You are here

public function ThemeTest::testListThemes in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testListThemes()

Test the listInfo() function.

File

core/modules/system/tests/src/Kernel/Theme/ThemeTest.php, line 106

Class

ThemeTest
Tests low-level theme functions.

Namespace

Drupal\Tests\system\Kernel\Theme

Code

public function testListThemes() {
  $this->container
    ->get('theme_installer')
    ->install([
    'test_subtheme',
  ]);
  $theme_handler = $this->container
    ->get('theme_handler');
  $themes = $theme_handler
    ->listInfo();

  // Check if ThemeHandlerInterface::listInfo() retrieves enabled themes.
  $this
    ->assertIdentical(1, $themes['test_theme']->status, 'Installed theme detected');

  // Check if ThemeHandlerInterface::listInfo() returns disabled themes.
  // Check for base theme and subtheme lists.
  $base_theme_list = [
    'test_basetheme' => 'Theme test base theme',
  ];
  $sub_theme_list = [
    'test_subsubtheme' => 'Theme test subsubtheme',
    'test_subtheme' => 'Theme test subtheme',
  ];
  $this
    ->assertIdentical($themes['test_basetheme']->sub_themes, $sub_theme_list, 'Base theme\'s object includes list of subthemes.');
  $this
    ->assertIdentical($themes['test_subtheme']->base_themes, $base_theme_list, 'Subtheme\'s object includes list of base themes.');

  // Check for theme engine in subtheme.
  $this
    ->assertIdentical($themes['test_subtheme']->engine, 'twig', 'Subtheme\'s object includes the theme engine.');

  // Check for theme engine prefix.
  $this
    ->assertIdentical($themes['test_basetheme']->prefix, 'twig', 'Base theme\'s object includes the theme engine prefix.');
  $this
    ->assertIdentical($themes['test_subtheme']->prefix, 'twig', 'Subtheme\'s object includes the theme engine prefix.');
}