function ThemeTest::testListThemes

Same name in other branches
  1. 9 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testListThemes()
  2. 8.9.x core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testListThemes()
  3. 10 core/modules/system/tests/src/Kernel/Theme/ThemeTest.php \Drupal\Tests\system\Kernel\Theme\ThemeTest::testListThemes()

Tests the listInfo() function.

File

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

Class

ThemeTest
Tests low-level theme functions.

Namespace

Drupal\Tests\system\Kernel\Theme

Code

public function testListThemes() : void {
    $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->assertSame(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_base_theme' => 'Theme test base theme',
    ];
    $sub_theme_list = [
        'test_subsubtheme' => 'Theme test subsubtheme',
        'test_subtheme' => 'Theme test subtheme',
    ];
    $this->assertSame($sub_theme_list, $themes['test_base_theme']->sub_themes, 'Base theme\'s object includes list of subthemes.');
    $this->assertSame($base_theme_list, $themes['test_subtheme']->base_themes, 'Subtheme\'s object includes list of base themes.');
    // Check for theme engine in subtheme.
    $this->assertSame('twig', $themes['test_subtheme']->engine, 'Subtheme\'s object includes the theme engine.');
    // Check for theme engine prefix.
    $this->assertSame('twig', $themes['test_base_theme']->prefix, 'Base theme\'s object includes the theme engine prefix.');
    $this->assertSame('twig', $themes['test_subtheme']->prefix, 'Subtheme\'s object includes the theme engine prefix.');
}

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