diff --git a/core/lib/Drupal/Core/Template/TwigNodeTrans.php b/core/lib/Drupal/Core/Template/TwigNodeTrans.php
index 64e0b2e..13677cc 100644
--- a/core/lib/Drupal/Core/Template/TwigNodeTrans.php
+++ b/core/lib/Drupal/Core/Template/TwigNodeTrans.php
@@ -11,8 +11,7 @@
namespace Drupal\Core\Template;
/**
- * The 'trans' tag allows the content string to be passed to the translation
- * system for internationalization.
+ * A class that defines the Twig 'trans' tag for Drupal.
*/
class TwigNodeTrans extends \Twig_Node {
diff --git a/core/lib/Drupal/Core/Template/TwigTransTokenParser.php b/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
index e1f4807..44f6d21 100644
--- a/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
+++ b/core/lib/Drupal/Core/Template/TwigTransTokenParser.php
@@ -20,6 +20,7 @@
* @see \Twig_TokenParser
*/
class TwigTransTokenParser extends \Twig_TokenParser {
+
/**
* {@inheritdoc}
*/
@@ -79,6 +80,8 @@ public function getTag() {
* The expression to check.
* @param integer $lineno
* The source line.
+ *
+ * @throws \Twig_Error_Syntax
*/
protected function checkTransString(\Twig_NodeInterface $body, $lineno) {
foreach ($body as $node) {
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigTransTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigTransTest.php
index 8717147..8c984f0 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigTransTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigTransTest.php
@@ -71,14 +71,6 @@ protected function setUp() {
theme_enable(array('test_theme'));
\Drupal::config('system.theme')->set('default', 'test_theme')->save();
- // Enable twig debug and write to the test settings.php file.
- $this->settingsSet('twig_debug', TRUE);
- $settings['settings']['twig_debug'] = (object) array(
- 'value' => TRUE,
- 'required' => TRUE,
- );
- $this->writeSettings($settings);
-
// Create and log in as admin.
$this->admin_user = $this->drupalCreateUser(array(
'administer languages',
@@ -108,7 +100,7 @@ protected function setUp() {
// Assign lolspeak to be the default language.
$edit = array('site_default_language' => $this->langcode);
- $this->drupalpost('admin/config/regional/settings', $edit, t('Save configuration'));
+ $this->drupalPost('admin/config/regional/settings', $edit, t('Save configuration'));
// Reset the static cache of the language list.
drupal_static_reset('language_list');
@@ -144,49 +136,64 @@ public function testTwigTransTags() {
);
$this->assertRaw(
- '',
- 'The "twig_debug" translation comment markup printed successfully for the above test.'
- );
-
- $this->assertRaw(
'ESCAPEE: &"<>',
'{{ token }} was successfully translated and prefixed with "@".'
);
$this->assertRaw(
- '',
- 'The "twig_debug" translation comment markup printed successfully for the above test.'
- );
-
- $this->assertRaw(
'PAS-THRU: &"<>',
'{{ token|passthrough }} was successfully translated and prefixed with "!".'
);
$this->assertRaw(
- '',
- 'The "twig_debug" translation comment markup printed successfully for the above test.'
- );
-
- $this->assertRaw(
'PLAYSHOLDR: &"<>',
'{{ token|placeholder }} was successfully translated and prefixed with "%".'
);
$this->assertRaw(
- '',
- 'The "twig_debug" translation comment markup printed successfully for the above test.'
- );
-
- $this->assertRaw(
'DIS complex token HAZ LENGTH OV: 3. IT CONTAYNZ: 12345 AN &"<>. LETS PAS TEH BAD TEXT THRU: &"<>.',
'{{ complex.tokens }} were successfully translated with appropriate prefixes.'
);
- $this->assertRaw(
- '',
- 'The "twig_debug" translation comment markup printed successfully for the above test.'
+ // Ensure debug output does not print.
+ $this->checkDebugVisible(FALSE);
+ }
+
+ /**
+ * Test Twig "trans" debug markup.
+ */
+ public function testTwigTransDebug() {
+ // Enable twig debug and write to the test settings.php file.
+ $this->settingsSet('twig_debug', TRUE);
+ $settings['settings']['twig_debug'] = (object) array(
+ 'value' => TRUE,
+ 'required' => TRUE,
+ );
+ $this->writeSettings($settings);
+
+ // Get page for assertion testing.
+ $this->drupalGet('twig-theme-test/trans', array('language' => language_load('xx')));
+
+ // Ensure debug output is printed.
+ $this->checkDebugVisible(TRUE);
+ }
+
+ protected function checkDebugVisible($visible) {
+ $tests = array(
+ '{% trans %} with {% plural %}' => '',
+ '{{ token }}' => '',
+ '{{ token|passthrough }}' => '',
+ '{{ token|placeholder }}' => '',
+ '{{ complex.tokens }}' => '',
);
+ foreach ($tests as $test => $markup) {
+ if ($visible) {
+ $this->assertRaw($markup, "Twig debug translation markup exists in source for: $test");
+ }
+ else {
+ $this->assertNoRaw($markup, "Twig debug translation markup does not exist in source for: $test");
+ }
+ }
}
/**
@@ -194,9 +201,9 @@ public function testTwigTransTags() {
*
* Borrowed from \Drupal\locale\Tests\LocaleImportFunctionalTest.
*
- * @param $contents
+ * @param string $contents
* Contents of the .po file to import.
- * @param $options
+ * @param array $options
* Additional options to pass to the translation import form.
*/
protected function importPoFile($contents, array $options = array()) {