You are here

function ThemeSuggestionsAlterTest::testExecutionOrder in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php \Drupal\system\Tests\Theme\ThemeSuggestionsAlterTest::testExecutionOrder()

Tests execution order of theme suggestion alter hooks.

hook_theme_suggestions_alter() should fire before hook_theme_suggestions_HOOK_alter() within an extension (module or theme).

File

core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php, line 165
Contains \Drupal\system\Tests\Theme\ThemeSuggestionsAlterTest.

Class

ThemeSuggestionsAlterTest
Tests theme suggestion alter hooks.

Namespace

Drupal\system\Tests\Theme

Code

function testExecutionOrder() {

  // Install our test theme and module.
  $this
    ->config('system.theme')
    ->set('default', 'test_theme')
    ->save();
  \Drupal::service('module_installer')
    ->install(array(
    'theme_suggestions_test',
  ));
  $this
    ->resetAll();

  // Send two requests so that we get all the messages we've set via
  // drupal_set_message().
  $this
    ->drupalGet('theme-test/suggestion-alter');

  // Ensure that the order is first by extension, then for a given extension,
  // the hook-specific one after the generic one.
  $expected = array(
    'theme_suggestions_test_theme_suggestions_alter() executed.',
    'theme_suggestions_test_theme_suggestions_theme_test_suggestions_alter() executed.',
    'theme_test_theme_suggestions_alter() executed.',
    'theme_test_theme_suggestions_theme_test_suggestions_alter() executed.',
    'test_theme_theme_suggestions_alter() executed.',
    'test_theme_theme_suggestions_theme_test_suggestions_alter() executed.',
  );
  $content = preg_replace('/\\s+/', ' ', Xss::filter($this->content, array()));
  $this
    ->assert(strpos($content, implode(' ', $expected)) !== FALSE, 'Suggestion alter hooks executed in the expected order.');
}