function MenuRouterTest::testHookCustomTheme

Test that hook_custom_theme() can control the theme of a page.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Menu/MenuRouterTest.php, line 252
Definition of Drupal\system\Tests\Menu\MenuRouterTest.

Class

MenuRouterTest
Tests menu router and hook_menu() functionality.

Namespace

Drupal\system\Tests\Menu

Code

function testHookCustomTheme() {

  // Trigger hook_custom_theme() to dynamically request the Stark theme for
  // the requested page.
  \Drupal::state()
    ->set('menu_test.hook_custom_theme_name', $this->alternate_theme);
  theme_enable(array(
    $this->alternate_theme,
    $this->admin_theme,
  ));

  // Visit a page that does not implement a theme callback. The above request
  // should be honored.
  $this
    ->drupalGet('menu-test/no-theme-callback');
  $this
    ->assertText('Custom theme: stark. Actual theme: stark.', 'The result of hook_custom_theme() is used as the theme for the current page.');
  $this
    ->assertRaw('stark/css/layout.css', "The Stark theme's CSS appears on the page.");
}