diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php index f6ff9c3bf99069f86f2d8ff0faa76a93b85e26df..b5ddd4f3ef02e44f1f5ddebcb9486a3690db6f19 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php @@ -8,6 +8,7 @@ namespace Drupal\locale\Tests; use Drupal\simpletest\WebTestBase; +use Drupal\Core\Language\Language; /** * Functional test for string translation and validation. @@ -467,4 +468,65 @@ function testStringSearch() { $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); $this->assertText(t('No strings available.'), t("Search didn't find the invalid string.")); } + + /** + * Test that strings are only saved and marked as customized when they are + * actually changed. + */ + function testUICustomizedStrings(){ + $user = $this->drupalCreateUser(array('translate interface', 'administer languages', 'access administration pages')); + $this->drupalLogin($user); + $language = new Language(array('langcode' => 'de')); + language_save($language); + + // Create test source string + $string = locale_storage()->createString(array( + 'source' => $this->randomName(100), + 'context' => $this->randomName(20), + ))->save(); + + // Create translation for new string and save it as non-customized. + $translation = locale_storage()->createTranslation(array( + 'lid' => $string->lid, + 'language' => 'de', + 'translation' => $this->randomName(100), + 'customized' => 0, + ))->save(); + + // Reset locale cache. + locale_reset(); + + // Queries strings with showing only non-customized strings. + $search = array( + 'string' => $string->getString(), + 'langcode' => 'de', + 'translation' => 'translated', + 'customized' => '0', + ); + $this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter')); + + $source = $this->assertText($translation->getString(), 'Translation is found in search result.'); + + // Submitting the translations withouth changing the translation, so the + // translation should not be saved and still be returned as non-customized. + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => $translation->getString(), + ); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); + + $source = $this->assertText($translation->getString(), 'Translation still marked as non-customized.'); + + // Submitting the translations with a new the translation, so the + // translation will be saved as customized and no result will be returned. + $textarea = current($this->xpath('//textarea')); + $lid = (string) $textarea[0]['name']; + $edit = array( + $lid => $this->randomName(100), + ); + $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); + + $this->assertText(t('No strings available.'), "No result anymore, so the string has been saved as customized."); + } }