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

Tests processing of theme .info.yml properties.

@group Theme

Hierarchy

  • class \Drupal\Tests\system\Functional\Theme\ThemeInfoTest extends \Drupal\Tests\BrowserTestBase

Expanded class hierarchy of ThemeInfoTest

File

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

Namespace

Drupal\Tests\system\Functional\Theme
View source
class ThemeInfoTest extends BrowserTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  protected static $modules = [
    'theme_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * The theme installer used in this test for enabling themes.
   *
   * @var \Drupal\Core\Extension\ThemeInstallerInterface
   */
  protected $themeInstaller;

  /**
   * The theme manager used in this test.
   *
   * @var \Drupal\Core\Theme\ThemeManagerInterface
   */
  protected $themeManager;

  /**
   * The state service used in this test.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->themeInstaller = $this->container
      ->get('theme_installer');
    $this->themeManager = $this->container
      ->get('theme.manager');
    $this->state = $this->container
      ->get('state');
  }

  /**
   * Tests libraries-override.
   */
  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
      ->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);
  }

  /**
   * Tests that changes to the info file are picked up.
   */
  public function testChanges() {
    $this->themeInstaller
      ->install([
      'test_theme',
    ]);
    $this
      ->config('system.theme')
      ->set('default', 'test_theme')
      ->save();
    $this->themeManager
      ->resetActiveTheme();
    $active_theme = $this->themeManager
      ->getActiveTheme();

    // Make sure we are not testing the wrong theme.
    $this
      ->assertEquals('test_theme', $active_theme
      ->getName());
    $this
      ->assertEquals([
      'starterkit_theme/base',
      'starterkit_theme/messages',
      'core/normalize',
      'test_theme/global-styling',
    ], $active_theme
      ->getLibraries());

    // @see theme_test_system_info_alter()
    $this->state
      ->set('theme_test.modify_info_files', TRUE);
    $this
      ->resetAll();
    $active_theme = $this->themeManager
      ->getActiveTheme();
    $this
      ->assertEquals([
      'starterkit_theme/base',
      'starterkit_theme/messages',
      'core/normalize',
      'test_theme/global-styling',
      'core/once',
    ], $active_theme
      ->getLibraries());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeInfoTest::$defaultTheme protected property
ThemeInfoTest::$modules protected static property Modules to enable.
ThemeInfoTest::$state protected property The state service used in this test.
ThemeInfoTest::$themeInstaller protected property The theme installer used in this test for enabling themes.
ThemeInfoTest::$themeManager protected property The theme manager used in this test.
ThemeInfoTest::setUp protected function
ThemeInfoTest::testChanges public function Tests that changes to the info file are picked up.
ThemeInfoTest::testStylesheets public function Tests libraries-override.