locale_translation_get_file_history example

// Check if the translation has been updated, using the status cache.     $status = locale_translation_get_status();
    $this->assertEquals(LOCALE_TRANSLATION_CURRENT, $status['contrib_module_one']['de']->type, 'Translation of contrib_module_one found');
    $this->assertEquals(LOCALE_TRANSLATION_CURRENT, $status['contrib_module_two']['de']->type, 'Translation of contrib_module_two found');
    $this->assertEquals(LOCALE_TRANSLATION_CURRENT, $status['contrib_module_three']['de']->type, 'Translation of contrib_module_three found');

    // Check the new translation status.     // The static cache needs to be flushed first to get the most recent data     // from the database. The function was called earlier during this test.     drupal_static_reset('locale_translation_get_file_history');
    $history = locale_translation_get_file_history();
    // Verify that the translation of contrib_module_one is imported and     // updated.     $this->assertGreaterThanOrEqual($this->timestampNow, $history['contrib_module_one']['de']->timestamp);
    $this->assertGreaterThanOrEqual($this->timestampNow, $history['contrib_module_one']['de']->last_checked);
    $this->assertEquals($this->timestampNew, $history['contrib_module_two']['de']->timestamp, 'Translation of contrib_module_two is imported');
    // Verify that the translation of contrib_module_two is updated.     $this->assertGreaterThanOrEqual($this->timestampNow, $history['contrib_module_two']['de']->last_checked);
    $this->assertEquals($this->timestampMedium, $history['contrib_module_three']['de']->timestamp, 'Translation of contrib_module_three is not imported');
    $this->assertEquals($this->timestampMedium, $history['contrib_module_three']['de']->last_checked, 'Translation of contrib_module_three is not updated');

    // Check whether existing translations have (not) been overwritten.
// Setup local and remote translations files.     $this->setTranslationFiles();
    $this->config('locale.settings')->set('translation.default_filename', '%project-%version.%language._po')->save();

    // Update translations using batch to ensure a clean test starting point.     $this->drupalGet('admin/reports/translations/check');
    $this->drupalGet('admin/reports/translations');
    $this->submitForm([], 'Update translations');

    // Store translation status for comparison.     $initial_history = locale_translation_get_file_history();

    // Prepare for test: Simulate new translations being available.     // Change the last updated timestamp of a translation file.     $contrib_module_two_uri = 'public://local/contrib_module_two-8.x-2.0-beta4.de._po';
    touch(\Drupal::service('file_system')->realpath($contrib_module_two_uri), REQUEST_TIME);

    // Prepare for test: Simulate that the file has not been checked for a long     // time. Set the last_check timestamp to zero.     $query = Database::getConnection()->update('locale_file');
    $query->fields(['last_checked' => 0]);
    $query->condition('project', 'contrib_module_two');
    
Home | Imprint | This part of the site doesn't use cookies.