function LocaleTranslationChangeProjectVersionTest::setUp

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

Overrides LocaleUpdateBase::setUp

File

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

Class

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

Namespace

Drupal\Tests\locale\Functional

Code

protected function setUp() : void {
    parent::setUp();
    \Drupal::moduleHandler()->loadInclude('locale', 'inc', 'locale.batch');
    ConfigurableLanguage::createFromLangcode('de')->save();
    \Drupal::state()->set('locale.test_projects_alter', TRUE);
    \Drupal::state()->set('locale.remove_core_project', TRUE);
    // Setup the environment.
    $config = $this->config('locale.settings');
    $public_path = PublicStream::basePath();
    $this->setTranslationsDirectory($public_path . '/local');
    $config->set('translation.default_filename', '%project-%version.%language._po')
        ->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
        ->save();
    // This test uses .po files for the old translation file instead of the ._po
    // files because locale_translate_get_interface_translation_files() (used to
    // delete old translation files) only works with .po files.
    // The new translation file uses _po.
    // Old version: 8.x-1.0; New version: 8.x-1.1.
    $this->makePoFile('remote/all/contrib_module_one', 'contrib_module_one-8.x-1.0.de.po', $this->timestampOld, []);
    $this->makePoFile('remote/all/contrib_module_one', 'contrib_module_one-8.x-1.1.de._po', $this->timestampNew, []);
    $this->makePoFile('local', 'contrib_module_one-8.x-1.0.de.po', $this->timestampOld, []);
    // Initialize the projects status and change the project version to the old
    // version. This makes the code update the module translation to the new
    // version when the (batch) update script is triggered.
    $status = locale_translation_get_status();
    $status['contrib_module_one']['de']->version = '8.x-1.0';
    \Drupal::keyValue('locale.translation_status')->setMultiple($status);
}

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