function LocaleConfigManagerTest::testGetStringTranslation

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

Tests getStringTranslation().

File

core/modules/locale/tests/src/Kernel/LocaleConfigManagerTest.php, line 58

Class

LocaleConfigManagerTest
Tests that the locale config manager operates correctly.

Namespace

Drupal\Tests\locale\Kernel

Code

public function testGetStringTranslation() : void {
    $this->installSchema('locale', [
        'locales_location',
        'locales_source',
        'locales_target',
    ]);
    $this->installConfig([
        'locale_test',
    ]);
    $locale_config_manager = \Drupal::service('locale.config_manager');
    $language = ConfigurableLanguage::createFromLangcode('de');
    $language->save();
    $translation_before = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
    $this->assertTrue($translation_before->isNew());
    $translation_before->setString('translation')
        ->save();
    $translation_after = $locale_config_manager->getStringTranslation('locale_test.no_translation', $language->getId(), 'Test', '');
    $this->assertFalse($translation_after->isNew());
    $translation_after->setString('updated_translation')
        ->save();
}

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