You are here

public function ThemeTest::testSwitchDefaultTheme in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testSwitchDefaultTheme()

Test switching the default theme.

File

core/modules/system/tests/src/Functional/System/ThemeTest.php, line 344

Class

ThemeTest
Tests the theme interface functionality by enabling and switching themes, and using an administration theme.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testSwitchDefaultTheme() {

  /** @var \Drupal\Core\Extension\ThemeInstallerInterface $theme_installer */
  $theme_installer = \Drupal::service('theme_installer');

  // First, install Stark and set it as the default theme programmatically.
  $theme_installer
    ->install([
    'stark',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'stark')
    ->save();
  $this
    ->drupalPlaceBlock('local_tasks_block');

  // Install Bartik and set it as the default theme.
  $theme_installer
    ->install([
    'bartik',
  ]);
  $this
    ->drupalGet('admin/appearance');
  $this
    ->clickLink(t('Set as default'));
  $this
    ->assertEqual($this
    ->config('system.theme')
    ->get('default'), 'bartik');

  // Test the default theme on the secondary links (blocks admin page).
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertText('Bartik(' . t('active tab') . ')', 'Default local task on blocks admin page is the default theme.');

  // Switch back to Stark and test again to test that the menu cache is cleared.
  $this
    ->drupalGet('admin/appearance');

  // Stark is the first 'Set as default' link.
  $this
    ->clickLink(t('Set as default'));
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertText('Stark(' . t('active tab') . ')', 'Default local task on blocks admin page has changed.');
}