From 4443a3070b80971e636c7ef5ba0fbb5ebfc8d024 Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Sat, 1 Nov 2014 18:22:45 -0400 Subject: Issue #2307505 by Cottser, Fabianx: Port twig_debug output to Drupal 7. --- modules/simpletest/tests/theme.test | 65 ++++++++++++++++++++++ .../themes/test_theme/templates/node--1.tpl.php | 2 + 2 files changed, 67 insertions(+) create mode 100644 modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php (limited to 'modules/simpletest') diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index 519a7a90a..328afec44 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -500,3 +500,68 @@ class ThemeRegistryTestCase extends DrupalWebTestCase { $this->assertTrue($registry['theme_test_template_test_2'], 'Offset was returned correctly from the theme registry'); } } + +/** + * Tests for theme debug markup. + */ +class ThemeDebugMarkupTestCase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Theme debug markup', + 'description' => 'Tests theme debug markup output.', + 'group' => 'Theme', + ); + } + + function setUp() { + parent::setUp('theme_test', 'node'); + theme_enable(array('test_theme')); + } + + /** + * Tests debug markup added to template output. + */ + function testDebugOutput() { + variable_set('theme_default', 'test_theme'); + // Enable the debug output. + variable_set('theme_debug', TRUE); + + $registry = theme_get_registry(); + $extension = '.tpl.php'; + // Populate array of templates. + $templates = drupal_find_theme_templates($registry, $extension, drupal_get_path('theme', 'test_theme')); + $templates += drupal_find_theme_templates($registry, $extension, drupal_get_path('module', 'node')); + + // Create a node and test different features of the debug markup. + $node = $this->drupalCreateNode(); + $this->drupalGet('node/' . $node->nid); + $this->assertRaw('', 'Theme debug markup found in theme output when debug is enabled.'); + $this->assertRaw("CALL: theme('node')", 'Theme call information found.'); + $this->assertRaw('x node--1' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node' . $extension, '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->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.'); + + // Create another node and make sure the template suggestions shown in the + // debug markup are correct. + $node2 = $this->drupalCreateNode(); + $this->drupalGet('node/' . $node2->nid); + $this->assertRaw('* node--2' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' x node' . $extension, 'Suggested template files found in order and base template shown as current template.'); + + // Create another node and make sure the template suggestions shown in the + // debug markup are correct. + $node3 = $this->drupalCreateNode(); + $build = array('#theme' => 'node__foo__bar'); + $build += node_view($node3); + $output = drupal_render($build); + $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--3' . $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 theme debug. + variable_set('theme_debug', FALSE); + + $this->drupalGet('node/' . $node->nid); + $this->assertNoRaw('', 'Theme debug markup not found in theme output when debug is disabled.'); + } + +} diff --git a/modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php b/modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php new file mode 100644 index 000000000..87aa79477 --- /dev/null +++ b/modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php @@ -0,0 +1,2 @@ + +Node Content Dummy -- cgit v1.2.3