X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flocale%2Fsrc%2FTests%2FLocaleJavascriptTranslationTest.php;fp=web%2Fcore%2Fmodules%2Flocale%2Fsrc%2FTests%2FLocaleJavascriptTranslationTest.php;h=0000000000000000000000000000000000000000;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hp=fe99ce2f37c424c3680c17dd542616cf4d72ce98;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a;p=yaffs-website diff --git a/web/core/modules/locale/src/Tests/LocaleJavascriptTranslationTest.php b/web/core/modules/locale/src/Tests/LocaleJavascriptTranslationTest.php deleted file mode 100644 index fe99ce2f3..000000000 --- a/web/core/modules/locale/src/Tests/LocaleJavascriptTranslationTest.php +++ /dev/null @@ -1,145 +0,0 @@ -container - ->get('locale.storage') - ->getStrings([ - 'type' => 'javascript', - 'name' => $filename, - ]); - - $source_strings = []; - foreach ($strings as $string) { - $source_strings[$string->source] = $string->context; - } - - $etx = LOCALE_PLURAL_DELIMITER; - // List of all strings that should be in the file. - $test_strings = [ - 'Standard Call t' => '', - 'Whitespace Call t' => '', - - 'Single Quote t' => '', - "Single Quote \\'Escaped\\' t" => '', - 'Single Quote Concat strings t' => '', - - 'Double Quote t' => '', - "Double Quote \\\"Escaped\\\" t" => '', - 'Double Quote Concat strings t' => '', - - 'Context !key Args t' => 'Context string', - - 'Context Unquoted t' => 'Context string unquoted', - 'Context Single Quoted t' => 'Context string single quoted', - 'Context Double Quoted t' => 'Context string double quoted', - - "Standard Call plural{$etx}Standard Call @count plural" => '', - "Whitespace Call plural{$etx}Whitespace Call @count plural" => '', - - "Single Quote plural{$etx}Single Quote @count plural" => '', - "Single Quote \\'Escaped\\' plural{$etx}Single Quote \\'Escaped\\' @count plural" => '', - - "Double Quote plural{$etx}Double Quote @count plural" => '', - "Double Quote \\\"Escaped\\\" plural{$etx}Double Quote \\\"Escaped\\\" @count plural" => '', - - "Context !key Args plural{$etx}Context !key Args @count plural" => 'Context string', - - "Context Unquoted plural{$etx}Context Unquoted @count plural" => 'Context string unquoted', - "Context Single Quoted plural{$etx}Context Single Quoted @count plural" => 'Context string single quoted', - "Context Double Quoted plural{$etx}Context Double Quoted @count plural" => 'Context string double quoted', - ]; - - // Assert that all strings were found properly. - foreach ($test_strings as $str => $context) { - $args = ['%source' => $str, '%context' => $context]; - - // Make sure that the string was found in the file. - $this->assertTrue(isset($source_strings[$str]), SafeMarkup::format('Found source string: %source', $args)); - - // Make sure that the proper context was matched. - $message = $context ? SafeMarkup::format('Context for %source is %context', $args) : SafeMarkup::format('Context for %source is blank', $args); - $this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, $message); - } - - $this->assertEqual(count($source_strings), count($test_strings), 'Found correct number of source strings.'); - } - - /** - * Assert translations JS is added before drupal.js, because it depends on it. - */ - public function testLocaleTranslationJsDependencies() { - // User to add and remove language. - $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages', 'translate interface']); - - // Add custom language. - $this->drupalLogin($admin_user); - // Code for the language. - $langcode = 'es'; - // The English name for the language. - $name = $this->randomMachineName(16); - // The domain prefix. - $prefix = $langcode; - $edit = [ - 'predefined_langcode' => 'custom', - 'langcode' => $langcode, - 'label' => $name, - 'direction' => LanguageInterface::DIRECTION_LTR, - ]; - $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); - - // Set path prefix. - $edit = ["prefix[$langcode]" => $prefix]; - $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration')); - - // This forces locale.admin.js string sources to be imported, which contains - // the next translation. - $this->drupalGet($prefix . '/admin/config/regional/translate'); - - // Translate a string in locale.admin.js to our new language. - $strings = \Drupal::service('locale.storage') - ->getStrings([ - 'source' => 'Show description', - 'type' => 'javascript', - 'name' => 'core/modules/locale/locale.admin.js', - ]); - $string = $strings[0]; - - $this->drupalPostForm(NULL, ['string' => 'Show description'], t('Filter')); - $edit = ['strings[' . $string->lid . '][translations][0]' => $this->randomString(16)]; - $this->drupalPostForm(NULL, $edit, t('Save translations')); - - // Calculate the filename of the JS including the translations. - $js_translation_files = \Drupal::state()->get('locale.translation.javascript'); - $js_filename = $prefix . '_' . $js_translation_files[$prefix] . '.js'; - - // Assert translations JS is included before drupal.js. - $this->assertTrue(strpos($this->content, $js_filename) < strpos($this->content, 'core/misc/drupal.js'), 'Translations are included before Drupal.t.'); - } - -}