function ThemeTest::testSwitchDefaultTheme

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()
  2. 8.9.x core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testSwitchDefaultTheme()
  3. 11.x 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 429

Class

ThemeTest
Tests the theme administration user interface.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testSwitchDefaultTheme() : void {
  /** @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 Olivero and set it as the default theme.
  $theme_installer->install([
    'olivero',
  ]);
  $this->drupalGet('admin/appearance');
  $this->clickLink('Set as default');
  $this->assertEquals('olivero', $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('Olivero');
  // 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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.