1.20.x theme.test ThemeDebugMarkupTestCase::testDebugOutput()

Tests debug markup added to template output.

File

modules/simpletest/tests/theme.test, line 841
Tests for the theme API.

Class

ThemeDebugMarkupTestCase
Tests for theme debug markup.

Code

function testDebugOutput() {
  config_set('system.core', 'theme_default', 'test_theme');
  // Enable the debug output.
  config_set('system.core', 'theme_debug', TRUE);

  $registry = theme_get_registry();
  $extension = '.tpl.php';
  // Populate array of templates.
  $templates = backdrop_find_theme_templates($registry, $extension, backdrop_get_path('theme', 'test_theme'));
  $templates += backdrop_find_theme_templates($registry, $extension, backdrop_get_path('module', 'node'));

  // Create a node and test different features of the debug markup.
  $node = $this->backdropCreateNode();
  $this->backdropGet("node/$node->nid");
  $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
  $this->assertRaw("CALL: theme('node__page__full')", 'Theme call information found.');
  $debug_output = <<<EOL
   * node--page--full.tpl.php
   * node--page.tpl.php
   x node--{$node->nid}.tpl.php
   * node.tpl.php
EOL;
  $this->assertRaw($debug_output, 'Suggested template files found in order and node ID specific template shown as current template.');
  $template_filename = $templates['node__' . $node->nid]['path'] . '/' . $templates['node__' . $node->nid]['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->backdropCreateNode();
  $this->backdropGet("node/$node2->nid");
  $debug_output = <<<EOL
   * node--page--full.tpl.php
   * node--page.tpl.php
   * node--{$node2->nid}.tpl.php
   x node.tpl.php
EOL;
  $this->assertRaw($debug_output, '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->backdropCreateNode();
  $build = array('#theme' => 'node__foo__bar');
  $build += node_view($node3);
  $output = backdrop_render($build);
  $this->assertTrue(strpos($output, "CALL: theme('node__foo__bar')") !== FALSE, 'Theme call information found.');
  $debug_output = <<<EOL
   * node--foo--bar.tpl.php
   * node--foo.tpl.php
   * node--{$node3->nid}.tpl.php
   x node.tpl.php
EOL;
  $this->assertTrue(strpos($output, $debug_output) !== FALSE, 'Suggested template files found in order and base template shown as current template.');

  // Disable theme debug.
  config_set('system.core', 'theme_debug', FALSE);

  $this->backdropGet('node/' . $node->nid);
  $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
}