You are here

public function ThemeTest::testSwitchDefaultTheme in Drupal 9

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

Tests switching the default theme.

File

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

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('Set as default');
  $this
    ->assertEquals('bartik', $this
    ->config('system.theme')
    ->get('default'));

  // Test the default theme on the secondary links (blocks admin page).
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertSession()
    ->pageTextContains('Bartik(active tab)');

  // 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('Set as default');
  $this
    ->drupalGet('admin/structure/block');
  $this
    ->assertSession()
    ->pageTextContains('Stark(active tab)');
}