diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php index 34675f7..2dddb5a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigDebugMarkupTest.php @@ -19,7 +19,7 @@ class TwigDebugMarkupTest extends WebTestBase { * * @var array */ - public static $modules = array('theme_test'); + public static $modules = array('theme_test', 'comment'); public static function getInfo() { return array( @@ -49,14 +49,14 @@ function testTwigDebugMarkup() { // Create array of Twig templates. $templates = drupal_find_theme_templates($cache, $extension, drupal_get_path('theme', 'test_theme')); $templates += drupal_find_theme_templates($cache, $extension, drupal_get_path('module', 'node')); + $templates += drupal_find_theme_templates($cache, $extension, drupal_get_path('module', 'comment')); // Create a node and test different features of the debug markup. $node = $this->drupalCreateNode(); $output = theme('node', node_view($node)); $this->assertTrue(strpos($output, '') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.'); $this->assertTrue(strpos($output, "CALL: theme('node')") !== FALSE, 'Theme call information found.'); - $this->assertTrue(strpos($output, 'x node--1' . $extension) !== FALSE, 'Node ID specific template shown as current template.'); - $this->assertTrue(strpos($output, '* node' . $extension) !== FALSE, 'Base template file found.'); + $this->assertTrue(strpos($output, 'x node--1' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node' . $extension) !== FALSE, 'Suggested template files found in order and node ID specific template shown as current template.'); $template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension; $this->assertTrue(strpos($output, "BEGIN OUTPUT from '$template_filename'") !== FALSE, 'Full path to current template file found.'); @@ -64,8 +64,37 @@ function testTwigDebugMarkup() { // debug markup are correct. $node2 = $this->drupalCreateNode(); $output = theme('node', node_view($node2)); - $this->assertTrue(strpos($output, '* node--2' . $extension) !== FALSE, 'Node ID specific template suggestion found.'); - $this->assertTrue(strpos($output, 'x node' . $extension) !== FALSE, 'Base template file shown as current template.'); + $this->assertTrue(strpos($output, '* node--2' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.'); + + // Create another node, call a theme suggestion directly, and make sure the + // template suggestions shown in the debug markup are correct. + $node3 = $this->drupalCreateNode(); + // Create a comment on the node. + $comment = entity_create('comment', array( + 'cid' => NULL, + 'nid' => $node3->id(), + 'node_type' => $node3->type, + 'pid' => 0, + 'uid' => 0, + 'status' => COMMENT_PUBLISHED, + 'subject' => $this->randomName(), + 'hostname' => '127.0.0.1', + 'langcode' => 'und', + 'comment_body' => array('und' => array($this->randomName())), + )); + $comment->save(); + $output = theme('comment__node__article', comment_view($comment)); + $this->assertTrue(strpos($output, "CALL: theme('comment__node__article')") !== FALSE, 'Theme call information found.'); + $this->assertTrue(strpos($output, '* comment--node--article' . $extension . PHP_EOL . ' * comment--node' . $extension . PHP_EOL . ' x comment' . $extension) !== FALSE, 'Suggested template files found in order and comment template set as current template.'); + $template_filename = $templates['comment']['path'] . '/' . $templates['comment']['template'] . $extension; + $this->assertTrue(strpos($output, "BEGIN OUTPUT from '$template_filename'") !== FALSE, 'Full path to current template file found.'); + + // Create another node and make sure the template suggestions shown in the + // debug markup are correct. + $node4 = $this->drupalCreateNode(); + $output = theme('node__foo__bar', node_view($node4)); + $this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.'); + $this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--4' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.'); // Disable debug, rebuild the service container, and clear all caches. $this->settingsSet('twig_debug', FALSE);