function ThemeInfoTest::testStylesheets

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php \Drupal\Tests\system\Functional\Theme\ThemeInfoTest::testStylesheets()
  2. 8.9.x core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php \Drupal\Tests\system\Functional\Theme\ThemeInfoTest::testStylesheets()
  3. 11.x core/modules/system/tests/src/Functional/Theme/ThemeInfoTest.php \Drupal\Tests\system\Functional\Theme\ThemeInfoTest::testStylesheets()

Tests libraries-override.

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() : void {
  $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->assertSession()
    ->elementsCount('xpath', '//link[contains(@href, "' . $base . '/base-add.css")]', 1);
  $this->assertSession()
    ->elementNotExists('xpath', '//link[contains(@href, "base-remove.css")]');
  $this->assertSession()
    ->elementsCount('xpath', '//link[contains(@href, "' . $sub . '/sub-add.css")]', 1);
  $this->assertSession()
    ->elementNotExists('xpath', '//link[contains(@href, "sub-remove.css")]');
  $this->assertSession()
    ->elementNotExists('xpath', '//link[contains(@href, "base-add.sub-remove.css")]');
  // Verify that CSS files with the same name are loaded from both the base theme and subtheme.
  $this->assertSession()
    ->elementsCount('xpath', '//link[contains(@href, "' . $base . '/samename.css")]', 1);
  $this->assertSession()
    ->elementsCount('xpath', '//link[contains(@href, "' . $sub . '/samename.css")]', 1);
}

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