function LocaleTranslationChangeProjectVersionTest::testUpdateImportSourceRemote

Same name in other branches
  1. 10 core/modules/locale/tests/src/Functional/LocaleTranslationChangeProjectVersionTest.php \Drupal\Tests\locale\Functional\LocaleTranslationChangeProjectVersionTest::testUpdateImportSourceRemote()

Tests update translations when project version changes.

File

core/modules/locale/tests/src/Functional/LocaleTranslationChangeProjectVersionTest.php, line 62

Class

LocaleTranslationChangeProjectVersionTest
Tests how translations are handled when a project gets updated.

Namespace

Drupal\Tests\locale\Functional

Code

public function testUpdateImportSourceRemote() : void {
    // Verify that the project status has the old version.
    $status = locale_translation_get_status([
        'contrib_module_one',
    ]);
    $this->assertEquals('8.x-1.0', $status['contrib_module_one']['de']->version);
    // Verify that the old translation file exists and the new does not exist.
    $this->assertFileExists('translations://contrib_module_one-8.x-1.0.de.po');
    $this->assertFileDoesNotExist('translations://contrib_module_one-8.x-1.1.de._po');
    // Run batch tasks.
    $context = [];
    locale_translation_batch_version_check('contrib_module_one', 'de', $context);
    locale_translation_batch_status_check('contrib_module_one', 'de', [], $context);
    locale_translation_batch_fetch_download('contrib_module_one', 'de', $context);
    // Verify that the project status has the new version.
    $status = locale_translation_get_status([
        'contrib_module_one',
    ]);
    $this->assertEquals('8.x-1.1', $status['contrib_module_one']['de']->version);
    // Verify that the old translation file was removed and the new was
    // downloaded.
    $this->assertFileDoesNotExist('translations://contrib_module_one-8.x-1.0.de.po');
    $this->assertFileExists('translations://contrib_module_one-8.x-1.1.de._po');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.