function LocaleConfigTranslationTest::setUp

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

Overrides BrowserTestBase::setUp

File

core/modules/locale/tests/src/Functional/LocaleConfigTranslationTest.php, line 43

Class

LocaleConfigTranslationTest
Tests translation of configuration strings.

Namespace

Drupal\Tests\locale\Functional

Code

protected function setUp() : void {
    parent::setUp();
    // Add a default locale storage for all these tests.
    $this->storage = $this->container
        ->get('locale.storage');
    // Enable import of translations. By default this is disabled for automated
    // tests.
    $this->config('locale.settings')
        ->set('translation.import_enabled', TRUE)
        ->set('translation.use_source', LOCALE_TRANSLATION_USE_SOURCE_LOCAL)
        ->save();
    // Add custom language.
    $this->langcode = 'xx';
    $admin_user = $this->drupalCreateUser([
        'administer languages',
        'access administration pages',
        'translate interface',
        'administer modules',
        'access site-wide contact form',
        'administer contact forms',
        'administer site configuration',
    ]);
    $this->drupalLogin($admin_user);
    $name = $this->randomMachineName(16);
    $edit = [
        'predefined_langcode' => 'custom',
        'langcode' => $this->langcode,
        'label' => $name,
        'direction' => LanguageInterface::DIRECTION_LTR,
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    // Set path prefix.
    $edit = [
        "prefix[{$this->langcode}]" => $this->langcode,
    ];
    $this->drupalGet('admin/config/regional/language/detection/url');
    $this->submitForm($edit, 'Save configuration');
}

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