diff --git a/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php b/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php index 6957f27..15962c2 100644 --- a/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php +++ b/core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php @@ -157,7 +157,7 @@ public function testSuggestionsAlterInclude() { } /** - * Tests hook_theme_suggestions_HOOK(). + * Tests hook_theme_suggestions_HOOK() with direct array suggestions. */ public function testArraySuggestions() { $this->drupalGet('theme-test/array-suggestions'); diff --git a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php index cd2e2fd..d25e5d4 100644 --- a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php +++ b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php @@ -43,7 +43,7 @@ protected function setUp() { /** * Tests debug markup added to Twig template output. */ - function testTwigDebugMarkup() { + public function testTwigDebugMarkup() { $extension = twig_extension(); $cache = $this->container->get('theme.registry')->get(); // Create array of Twig templates. @@ -96,10 +96,20 @@ function testTwigDebugMarkup() { public function testArraySuggestionsTwigDebugMarkup() { \Drupal::service('module_installer')->install(array('theme_suggestions_test')); $extension = twig_extension(); - $this->drupalGet('theme-test/array-suggestions'); - $this->assertTrue(strpos($this->getRawContent(), "THEME HOOK: 'theme_test_array_suggestions'") !== FALSE, 'Theme call information found.'); - $this->assertTrue(strpos($this->getRawContent(), '') !== FALSE, 'Suggested template files found in order and correct suggestion shown as current template.'); + $output = $this->getRawContent(); + + $expected = "THEME HOOK: 'theme_test_array_suggestions'"; + $this->assertTrue(strpos($output, $expected) !== FALSE, 'Theme call information found.'); + + $expected = ''; + $message = 'Suggested template files found in order and correct suggestion shown as current template.'; + $this->assertTrue(strpos($output, $expected) !== FALSE, $message); } /** @@ -108,8 +118,18 @@ public function testArraySuggestionsTwigDebugMarkup() { public function testUnimplementedSpecificSuggestionsTwigDebugMarkup() { $extension = twig_extension(); $this->drupalGet('theme-test/specific-suggestion'); - $this->assertTrue(strpos($this->getRawContent(), "THEME HOOK: 'theme_test_specific_suggestions__not__found'") !== FALSE, 'Theme call information found.'); - $this->assertTrue(strpos($this->getRawContent(), '') !== FALSE, 'Suggested template files found in order and base template shown as current template.'); + $output = $this->getRawContent(); + + $expected = "THEME HOOK: 'theme_test_specific_suggestions__not__found'"; + $this->assertTrue(strpos($output, $expected) !== FALSE, 'Theme call information found.'); + + $message = 'Suggested template files found in order and base template shown as current template.'; + $expected = ''; + $this->assertTrue(strpos($output, $expected) !== FALSE, $message); } /** @@ -118,8 +138,17 @@ public function testUnimplementedSpecificSuggestionsTwigDebugMarkup() { public function testSpecificSuggestionsTwigDebugMarkup() { $extension = twig_extension(); $this->drupalGet('theme-test/specific-suggestion-alter'); - $this->assertTrue(strpos($this->getRawContent(), "THEME HOOK: 'theme_test_specific_suggestions__variant'") !== FALSE, 'Theme call information found.'); - $this->assertTrue(strpos($this->getRawContent(), '') !== FALSE, 'Suggested template files found in order and suggested template shown as current.'); + $output = $this->getRawContent(); + + $expected = "THEME HOOK: 'theme_test_specific_suggestions__variant'"; + $this->assertTrue(strpos($output, $expected) !== FALSE, 'Theme call information found.'); + + $expected = ''; + $message = 'Suggested template files found in order and suggested template shown as current.'; + $this->assertTrue(strpos($output, $expected) !== FALSE, $message); } } diff --git a/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php b/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php index 191102d..4b59b0e 100644 --- a/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php +++ b/core/modules/system/tests/modules/theme_test/src/ThemeTestController.php @@ -147,7 +147,8 @@ public function arraySuggestions() { '#theme' => array( 'theme_test_array_suggestions__not_implemented', 'theme_test_array_suggestions__not_implemented_2', - 'theme_test_array_suggestions'), + 'theme_test_array_suggestions', + ), ); } diff --git a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php b/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php index 6c67ee8..41bc7ea 100644 --- a/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php +++ b/core/modules/views/src/Tests/ViewsThemeIntegrationTest.php @@ -95,15 +95,15 @@ public function testThemeSuggestionsInDebug() { '#type' => 'view', '#name' => 'test_page_display', '#display_id' => 'default', - '#arguments' => array(), + '#arguments' => [], ]; $output = drupal_render($build, TRUE); - - $this->assertTrue(strpos($output, '* views-view--test-page-display--default.html.twig') !== FALSE); - $this->assertTrue(strpos($output, '* views-view--default.html.twig') !== FALSE); - $this->assertTrue(strpos($output, '* views-view--test-page-display.html.twig') !== FALSE); - $this->assertTrue(strpos($output, 'x views-view.html.twig') !== FALSE); + $expected = ' * views-view--test-page-display--default.html.twig' . PHP_EOL + . ' * views-view--default.html.twig' . PHP_EOL + . ' * views-view--test-page-display.html.twig' . PHP_EOL + . ' x views-view.html.twig' . PHP_EOL; + $this->assertTrue(strpos($output, $expected) !== FALSE); } } diff --git a/core/themes/engines/twig/twig.engine b/core/themes/engines/twig/twig.engine index 19c6a28..ff71af0 100644 --- a/core/themes/engines/twig/twig.engine +++ b/core/themes/engines/twig/twig.engine @@ -73,15 +73,13 @@ function twig_render_template($template_file, array $variables) { $current_template = basename($template_file); $pos = strpos($variables['theme_hook_original'], '__'); - if ( $pos !== FALSE) { + if ($pos !== FALSE) { $suggestions[] = substr($variables['theme_hook_original'], 0, $pos); } else { $suggestions[] = $variables['theme_hook_original']; } - // Only add the original theme hook if it wasn't a directly called - // suggestion. foreach ($suggestions as &$suggestion) { $template = strtr($suggestion, '_', '-') . $extension; $prefix = ($template == $current_template) ? 'x' : '*';