public function LocaleTranslationUiTest::testUICustomizedStrings in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/locale/src/Tests/LocaleTranslationUiTest.php \Drupal\locale\Tests\LocaleTranslationUiTest::testUICustomizedStrings()
Tests that only changed strings are saved customized when edited.
File
- core/
modules/ locale/ src/ Tests/ LocaleTranslationUiTest.php, line 475 - Contains \Drupal\locale\Tests\LocaleTranslationUiTest.
Class
- LocaleTranslationUiTest
- Adds a new locale and translates its name. Checks the validation of translation strings and search results.
Namespace
Drupal\locale\TestsCode
public function testUICustomizedStrings() {
$user = $this
->drupalCreateUser(array(
'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(array(
'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(array(
'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 = array(
'string' => $string
->getString(),
'langcode' => 'de',
'translation' => 'translated',
'customized' => '0',
);
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText($translation
->getString(), 'Translation is found in search result.');
// Submit the translations without changing the translation.
$textarea = current($this
->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$edit = array(
$lid => $translation
->getString(),
);
$this
->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
// Ensure unchanged translation string does appear if searching
// non-customized translation.
$search = array(
'string' => $string
->getString(),
'langcode' => 'de',
'translation' => 'translated',
'customized' => '0',
);
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText($string
->getString(), 'Translation is not marked as customized.');
// Submit the translations with a new translation.
$textarea = current($this
->xpath('//textarea'));
$lid = (string) $textarea[0]['name'];
$edit = array(
$lid => $this
->randomMachineName(100),
);
$this
->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
// Ensure changed translation string does appear if searching customized
// translation.
$search = array(
'string' => $string
->getString(),
'langcode' => 'de',
'translation' => 'translated',
'customized' => '1',
);
$this
->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
$this
->assertText($string
->getString(), "Translation is marked as customized.");
}