Commit 30366eba authored by catch's avatar catch

Issue #2889600 by droplet, drpal, Gábor Hojtsy, effulgentsia, Wim Leers:...

Issue #2889600 by droplet, drpal, Gábor Hojtsy, effulgentsia, Wim Leers: [regression] Restore \LocaleJavascriptTranslationTest test coverage and keep testing processed JS file
parent 85eefe2b
assets/vendor/**/*
modules/locale/tests/locale_test.js
node_modules/**/*
**/js_test_files/**/*
*.js
!*.es6.js
modules/locale/tests/locale_test.es6.js
......@@ -21,73 +21,86 @@ class LocaleJavascriptTranslationTest extends BrowserTestBase {
public static $modules = ['locale', 'locale_test'];
public function testFileParsing() {
$filename = __DIR__ . '/../../locale_test.js';
// Parse the file to look for source strings.
_locale_parse_js_file($filename);
// Get all of the source strings that were found.
$strings = $this->container
->get('locale.storage')
->getStrings([
'type' => 'javascript',
'name' => $filename,
]);
$source_strings = [];
foreach ($strings as $string) {
$source_strings[$string->source] = $string->context;
// This test is for ensuring that the regular expression in
// _locale_parse_js_file() finds translatable source strings in all valid
// JavaScript syntax regardless of the coding style used, especially with
// respect to optional whitespace, line breaks, etc.
// - We test locale_test.es6.js, because that is the one that contains a
// variety of whitespace styles.
// - We also test the transpiled locale_test.js as an extra double-check
// that JavaScript transpilation doesn't change what
// _locale_parse_js_file() finds.
$files[] = __DIR__ . '/../../locale_test.es6.js';
$files[] = __DIR__ . '/../../locale_test.js';
foreach ($files as $filename) {
// Parse the file to look for source strings.
_locale_parse_js_file($filename);
// Get all of the source strings that were found.
$strings = $this->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.');
}
$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.');
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment