function ThemeTest::testInstallAndSetAsDefault

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testInstallAndSetAsDefault()
  2. 8.9.x core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testInstallAndSetAsDefault()
  3. 10 core/modules/system/tests/src/Functional/System/ThemeTest.php \Drupal\Tests\system\Functional\System\ThemeTest::testInstallAndSetAsDefault()

Tests installing a theme and setting it as default.

File

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

Class

ThemeTest
Tests the theme administration user interface.

Namespace

Drupal\Tests\system\Functional\System

Code

public function testInstallAndSetAsDefault() : void {
    $this->markTestSkipped('Skipped due to major version-specific logic. See https://www.drupal.org/project/drupal/issues/3359322');
    $themes = [
        'olivero' => 'Olivero',
        'test_core_semver' => 'Theme test with semver core version',
    ];
    foreach ($themes as $theme_machine_name => $theme_name) {
        $this->drupalGet('admin/appearance');
        $this->getSession()
            ->getPage()
            ->findLink("Install {$theme_name} as default theme")
            ->click();
        // Test the confirmation message.
        $this->assertSession()
            ->pageTextContains("{$theme_name} is now the default theme.");
        // Make sure the theme is now set as the default theme in config.
        $this->assertEquals($theme_machine_name, $this->config('system.theme')
            ->get('default'));
        // This checks for a regression. See https://www.drupal.org/node/2498691.
        $this->assertSession()
            ->pageTextNotContains("The {$theme_machine_name} theme was not found.");
        $themes = \Drupal::service('extension.list.theme')->reset()
            ->getList();
        $version = $themes[$theme_machine_name]->info['version'];
        // Confirm the theme is indicated as the default theme and administration
        // theme because the admin theme is the default theme.
        $out = $this->getSession()
            ->getPage()
            ->getContent();
        $this->assertTrue((bool) preg_match("/{$theme_name} " . preg_quote($version) . '\\s{2,}\\(default theme, administration theme\\)/', $out));
    }
}

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