You are here

public function ThemeInfoTest::testStylesheets in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php \Drupal\Tests\system\Functional\Theme\ThemeInfoTest::testStylesheets()
  2. 10 core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php \Drupal\Tests\system\Functional\Theme\ThemeInfoTest::testStylesheets()

Tests stylesheets-remove.

File

core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php, line 61

Class

ThemeInfoTest
Tests processing of theme .info.yml properties.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testStylesheets() {
  $this->themeInstaller
    ->install([
    'test_basetheme',
    'test_subtheme',
  ]);
  $this
    ->config('system.theme')
    ->set('default', 'test_subtheme')
    ->save();
  $base = $this
    ->getThemePath('test_basetheme');
  $sub = $this
    ->getThemePath('test_subtheme') . '/css';

  // All removals are expected to be based on a file's path and name and
  // should work nevertheless.
  $this
    ->drupalGet('theme-test/info/stylesheets');
  $this
    ->assertCount(1, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "{$base}/base-add.css",
  ]), "{$base}/base-add.css found");
  $this
    ->assertCount(0, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "base-remove.css",
  ]), "base-remove.css not found");
  $this
    ->assertCount(1, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "{$sub}/sub-add.css",
  ]), "{$sub}/sub-add.css found");
  $this
    ->assertCount(0, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "sub-remove.css",
  ]), "sub-remove.css not found");
  $this
    ->assertCount(0, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "base-add.sub-remove.css",
  ]), "base-add.sub-remove.css not found");

  // Verify that CSS files with the same name are loaded from both the base theme and subtheme.
  $this
    ->assertCount(1, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "{$base}/samename.css",
  ]), "{$base}/samename.css found");
  $this
    ->assertCount(1, $this
    ->xpath('//link[contains(@href, :href)]', [
    ':href' => "{$sub}/samename.css",
  ]), "{$sub}/samename.css found");
}