function ThemeTest::testSwitchDefaultTheme

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testSwitchDefaultTheme()
  2. 10 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 373

Class

ThemeTest
Tests the theme administration user interface.

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 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(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)');
}

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