function LocaleTranslationUiTest::testUICustomizedStrings
Same name in other branches
- 9 core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php \Drupal\Tests\locale\Functional\LocaleTranslationUiTest::testUICustomizedStrings()
- 8.9.x core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php \Drupal\Tests\locale\Functional\LocaleTranslationUiTest::testUICustomizedStrings()
- 10 core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php \Drupal\Tests\locale\Functional\LocaleTranslationUiTest::testUICustomizedStrings()
Tests that only changed strings are saved customized when edited.
File
-
core/
modules/ locale/ tests/ src/ Functional/ LocaleTranslationUiTest.php, line 557
Class
- LocaleTranslationUiTest
- Tests the validation of translation strings and search results.
Namespace
Drupal\Tests\locale\FunctionalCode
public function testUICustomizedStrings() : void {
$user = $this->drupalCreateUser([
'translate interface',
'administer languages',
'access administration pages',
]);
$this->drupalLogin($user);
ConfigurableLanguage::createFromLangcode('de')->save();
// Create test source string.
$string = $this->container
->get('locale.storage')
->createString([
'source' => $this->randomMachineName(100),
'context' => $this->randomMachineName(20),
])
->save();
// Create translation for new string and save it as non-customized.
$translation = $this->container
->get('locale.storage')
->createTranslation([
'lid' => $string->lid,
'language' => 'de',
'translation' => $this->randomMachineName(100),
'customized' => 0,
])
->save();
// Reset locale cache.
$this->container
->get('string_translation')
->reset();
// Ensure non-customized translation string does appear if searching
// non-customized translation.
$search = [
'string' => $string->getString(),
'langcode' => 'de',
'translation' => 'translated',
'customized' => '0',
];
$this->drupalGet('admin/config/regional/translate');
$this->submitForm($search, 'Filter');
$this->assertSession()
->pageTextContains($translation->getString());
// Submit the translations without changing the translation.
$textarea = $this->assertSession()
->elementExists('xpath', '//textarea');
$lid = $textarea->getAttribute('name');
$edit = [
$lid => $translation->getString(),
];
$this->drupalGet('admin/config/regional/translate');
$this->submitForm($edit, 'Save translations');
// Ensure unchanged translation string does appear if searching
// non-customized translation.
$search = [
'string' => $string->getString(),
'langcode' => 'de',
'translation' => 'translated',
'customized' => '0',
];
$this->drupalGet('admin/config/regional/translate');
$this->submitForm($search, 'Filter');
$this->assertSession()
->pageTextContains($string->getString());
// Submit the translations with a new translation.
$textarea = $this->assertSession()
->elementExists('xpath', '//textarea');
$lid = $textarea->getAttribute('name');
$edit = [
$lid => $this->randomMachineName(100),
];
$this->drupalGet('admin/config/regional/translate');
$this->submitForm($edit, 'Save translations');
// Ensure changed translation string does appear if searching customized
// translation.
$search = [
'string' => $string->getString(),
'langcode' => 'de',
'translation' => 'translated',
'customized' => '1',
];
$this->drupalGet('admin/config/regional/translate');
$this->submitForm($search, 'Filter');
$this->assertSession()
->pageTextContains($string->getString());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.