1 theme.test ThemeDebugMarkupTestCase::testDebugUserOutput()

Tests debug user markup added to template output.

File

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

Class

ThemeDebugMarkupTestCase
Tests for theme debug markup.

Code

function testDebugUserOutput() {
  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', 'user'));

  // Create a user and test different features of the debug markup.
  $admin_user = $this->admin_user;
  $this->backdropGet("user/$admin_user->uid");
  $this->assertRaw('<!-- THEME DEBUG -->', 'Theme debug markup found in theme output when debug is enabled.');
  $this->assertRaw("CALL: theme('user_profile')", 'Theme call information found.');
  $debug_output = <<<EOL
   * user-profile--{$admin_user->uid}--full.tpl.php
   x user-profile--{$admin_user->uid}.tpl.php
   * user-profile--full.tpl.php
   * user-profile.tpl.php
EOL;
  $this->assertRaw($debug_output, 'Suggested template files found in order and user ID specific template shown as current template.');
  $template_filename = $templates['user_profile__' . $admin_user->uid]['path'] . '/' . $templates['user_profile__' . $admin_user->uid]['template'] . $extension;
  $this->assertRaw("BEGIN OUTPUT from '$template_filename'", 'Full path to current template file found.');

  // Create another user and make sure the template suggestions shown in the
  // debug markup are correct.
  $user2 = $this->backdropCreateUser();
  $this->backdropGet("user/$user2->uid");
  $debug_output = <<<EOL
   * user-profile--{$user2->uid}--full.tpl.php
   * user-profile--{$user2->uid}.tpl.php
   * user-profile--full.tpl.php
   x user-profile.tpl.php
EOL;
  $this->assertRaw($debug_output, 'Suggested template files found in order and base template shown as current template.');

  // Create another user and make sure the template suggestions shown in the
  // debug markup are correct.
  $user3 = $this->backdropCreateUser();
  $build = array('#theme' => 'user_profile__foo__bar');
  $build += user_view($user3);
  $output = backdrop_render($build);
  $this->assertTrue(strpos($output, "CALL: theme('user_profile__foo__bar')") !== FALSE, 'Theme call information found.');
  $debug_output = <<<EOL
   * user-profile--foo--bar.tpl.php
   * user-profile--foo.tpl.php
   * user-profile--{$user3->uid}--full.tpl.php
   * user-profile--{$user3->uid}.tpl.php
   * user-profile--full.tpl.php
   x user-profile.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('user/' . $admin_user->uid);
  $this->assertNoRaw('<!-- THEME DEBUG -->', 'Theme debug markup not found in theme output when debug is disabled.');
}