summaryrefslogtreecommitdiff
path: root/modules/simpletest
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-11-01 18:22:45 -0400
committerDavid Rothstein <drothstein@gmail.com>2014-11-01 18:22:45 -0400
commit4443a3070b80971e636c7ef5ba0fbb5ebfc8d024 (patch)
tree613b9cf93825fe3d101ab9dc77a8270bb2c0de3d /modules/simpletest
parentc312e5ee5589d060601f633deba3be26df494815 (diff)
downloadbrdo-4443a3070b80971e636c7ef5ba0fbb5ebfc8d024.tar.gz
brdo-4443a3070b80971e636c7ef5ba0fbb5ebfc8d024.tar.bz2
Issue #2307505 by Cottser, Fabianx: Port twig_debug output to Drupal 7.
Diffstat (limited to 'modules/simpletest')
-rw-r--r--modules/simpletest/tests/theme.test65
-rw-r--r--modules/simpletest/tests/themes/test_theme/templates/node--1.tpl.php2
2 files changed, 67 insertions, 0 deletions
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 -->', '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 -->', '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 @@
+<!-- Output for Theme Debug Markup test -->
+Node Content Dummy