diff -u b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php --- b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/ThemeTestTwig.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\system\Tests\Theme\ThemeTest. + * Contains Drupal\system\Tests\Theme\ThemeTestTwig. */ namespace Drupal\system\Tests\Theme; @@ -10,7 +10,7 @@ use Drupal\simpletest\WebTestBase; /** - * Tests low-level theme functions. + * Tests theme functions with the Twig engine. */ class ThemeTestTwig extends WebTestBase { @@ -82,4 +82,7 @@ $this->drupalGet('theme-test/template-test'); - $this->assertRaw('

null:

', t('NULL values render as empty strings in Twig templates.')); + foreach (_test_theme_twig_php_values() as $type => $value) { + $this->assertRaw('
  • ' . $type . ': ' . $value['expected'] . '
  • '); + } } + } diff -u b/core/modules/system/tests/themes/test_theme_twig/test_theme_twig.theme b/core/modules/system/tests/themes/test_theme_twig/test_theme_twig.theme --- b/core/modules/system/tests/themes/test_theme_twig/test_theme_twig.theme +++ b/core/modules/system/tests/themes/test_theme_twig/test_theme_twig.theme @@ -1,4 +1,5 @@ value pairs for testTwigVariableDataTypes(). - $types = array( - 'null' => NULL, - ); - - foreach ($types as $type => $value) { - // Prefix each variable with "twig_" so that twig doesn't get confused - // between a variable and a primitive. - $variables['twig_' . $type] = $value; - } + $variables['php_values'] = _test_theme_twig_php_values(); } diff -u b/core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.html.twig b/core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.html.twig --- b/core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.html.twig +++ b/core/modules/system/tests/themes/test_theme_twig/theme_test.template_test.html.twig @@ -4 +4,5 @@ -

    null: {{ twig_null }}

    + \ No newline at end of file only in patch2: unchanged: --- a/core/modules/system/tests/modules/theme_test/theme_test.module +++ b/core/modules/system/tests/modules/theme_test/theme_test.module @@ -172,3 +172,41 @@ function theme_theme_test_foo($variables) { return $variables['foo']; } +/* + * Helper function to test PHP variables in the Twig engine. + */ +function _test_theme_twig_php_values() { + // Prefix each variable with "twig_" so that twig doesn't get confused + // between a variable and a primitive. Arrays are not tested since they should + // be a Drupal render array. + return array( + 'twig_null' => array( + 'value' => NULL, + 'expected' => '', + ), + 'twig_bool_false' => array( + 'value' => FALSE, + 'expected' => '', + ), + 'twig_bool_true' => array( + 'value' => TRUE, + 'expected' => '1', + ), + 'twig_int' => array( + 'value' => 1, + 'expected' => '1', + ), + 'twig_int_0' => array( + 'value' => 0, + 'expected' => '0', + ), + 'twig_float' => array( + 'value' => 122.34343, + 'expected' => '122.34343', + ), + 'twig_string' => array( + 'value' => 'Hello world!', + 'expected' => 'Hello world!', + ), + ); +}