1 theme.test ThemeDebugMarkupTestCase::testDebugTaxonomyOutput()

Tests debug taxonomy markup added to template output.

File

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

Class

ThemeDebugMarkupTestCase
Tests for theme debug markup.

Code

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

  $vocabulary = new TaxonomyVocabulary(array(
    'name' => $this->randomName(),
    'description' => $this->randomName(),
    'machine_name' => backdrop_strtolower($this->randomName()),
    'weight' => mt_rand(0, 10),
  ));
  taxonomy_vocabulary_save($vocabulary);

  $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', 'taxonomy'));

  // Create a term and test different features of the debug markup.
  $term = entity_create('taxonomy_term', array(
    'name' => $this->randomName(),
    'description' => $this->randomName(),
    'format' => filter_default_format(),
    'vocabulary' => $vocabulary->machine_name,
    'langcode' => LANGUAGE_NONE,
  ));
  taxonomy_term_save($term);

  $this->backdropGet("taxonomy/term/$term->tid");
  $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
  $this->assertRaw("CALL: theme('taxonomy_term')", 'Theme call information found.');
  $debug_output = <<<EOL
   * taxonomy-term--{$term->tid}--full.tpl.php
   x taxonomy-term--{$term->tid}.tpl.php
   * taxonomy-term--{$vocabulary->machine_name}--full.tpl.php
   * taxonomy-term--{$vocabulary->machine_name}.tpl.php
   * taxonomy-term.tpl.php
EOL;

  $this->assertRaw($debug_output, 'Suggested template files found in order and term ID specific template shown as current template.');
  $template_filename = $templates['taxonomy_term__' . $term->tid]['path'] . '/' . $templates['taxonomy_term__' . $term->tid]['template'] . $extension;
  $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');

  // Create another term and make sure the template suggestions shown in the
  // debug markup are correct.
  $term2 = entity_create('taxonomy_term', array(
    'name' => $this->randomName(),
    'description' => $this->randomName(),
    'format' => filter_default_format(),
    'vocabulary' => $vocabulary->machine_name,
    'langcode' => LANGUAGE_NONE,
  ));
  taxonomy_term_save($term2);

  $this->backdropGet("taxonomy/term/$term2->tid");
  $debug_output = <<<EOL
   * taxonomy-term--{$term2->tid}--full.tpl.php
   * taxonomy-term--{$term2->tid}.tpl.php
   * taxonomy-term--{$vocabulary->machine_name}--full.tpl.php
   * taxonomy-term--{$vocabulary->machine_name}.tpl.php
   x taxonomy-term.tpl.php
EOL;
  $this->assertRaw($debug_output, 'Suggested template files found in order and base template shown as current template.');

  // Create another term and make sure the template suggestions shown in the
  // debug markup are correct.
  $term3 = entity_create('taxonomy_term', array(
    'name' => $this->randomName(),
    'description' => $this->randomName(),
    'format' => filter_default_format(),
    'vocabulary' => $vocabulary->machine_name,
    'langcode' => LANGUAGE_NONE,
  ));
  taxonomy_term_save($term3);

  $build = array('#theme' => 'taxonomy_term__foo__bar');
  $build += taxonomy_term_view($term3);
  $output = backdrop_render($build);
  $this->assertTrue(strpos($output, "CALL: theme('taxonomy_term__foo__bar')") !== FALSE, 'Theme call information found.');
  $debug_output = <<<EOL
   * taxonomy-term--foo--bar.tpl.php
   * taxonomy-term--foo.tpl.php
   * taxonomy-term--{$term3->tid}--full.tpl.php
   * taxonomy-term--{$term3->tid}.tpl.php
   * taxonomy-term--{$vocabulary->machine_name}--full.tpl.php
   * taxonomy-term--{$vocabulary->machine_name}.tpl.php
   x taxonomy-term.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("taxonomy/term/$term3->tid");
  $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
}