class ThemeHandlerTest in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Extension/ThemeHandlerTest.php \Drupal\Tests\Core\Extension\ThemeHandlerTest
@coversDefaultClass \Drupal\Core\Extension\ThemeHandler @group Extension
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Extension\ThemeHandlerTest
Expanded class hierarchy of ThemeHandlerTest
File
- core/
tests/ Drupal/ Tests/ Core/ Extension/ ThemeHandlerTest.php, line 20 - Contains \Drupal\Tests\Core\Extension\ThemeHandlerTest.
Namespace
Drupal\Tests\Core\ExtensionView source
class ThemeHandlerTest extends UnitTestCase {
/**
* The mocked config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $configFactory;
/**
* The theme listing service.
*
* @var \Drupal\Core\Extension\ThemeExtensionList|\PHPUnit\Framework\MockObject\MockObject
*/
protected $themeList;
/**
* The tested theme handler.
*
* @var \Drupal\Core\Extension\ThemeHandler|\Drupal\Tests\Core\Extension\StubThemeHandler
*/
protected $themeHandler;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->configFactory = $this
->getConfigFactoryStub([
'core.extension' => [
'module' => [],
'theme' => [],
'disabled' => [
'theme' => [],
],
],
]);
$this->themeList = $this
->getMockBuilder(ThemeExtensionList::class)
->disableOriginalConstructor()
->getMock();
$this->themeHandler = new StubThemeHandler($this->root, $this->configFactory, $this->themeList);
$container = $this
->createMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container
->expects($this
->any())
->method('get')
->with('class_loader')
->will($this
->returnValue($this
->createMock(ClassLoader::class)));
\Drupal::setContainer($container);
}
/**
* Tests rebuilding the theme data.
*
* @see \Drupal\Core\Extension\ThemeHandler::rebuildThemeData()
*/
public function testRebuildThemeData() {
$this->themeList
->expects($this
->once())
->method('reset')
->willReturnSelf();
$this->themeList
->expects($this
->once())
->method('getList')
->will($this
->returnValue([
'seven' => new Extension($this->root, 'theme', 'core/themes/seven/seven.info.yml', 'seven.theme'),
]));
$theme_data = $this->themeHandler
->rebuildThemeData();
$this
->assertCount(1, $theme_data);
$info = $theme_data['seven'];
// Ensure some basic properties.
$this
->assertInstanceOf('Drupal\\Core\\Extension\\Extension', $info);
$this
->assertEquals('seven', $info
->getName());
$this
->assertEquals('core/themes/seven/seven.info.yml', $info
->getPathname());
$this
->assertEquals('core/themes/seven/seven.theme', $info
->getExtensionPathname());
}
/**
* Tests empty libraries in theme.info.yml file.
*/
public function testThemeLibrariesEmpty() {
$theme = new Extension($this->root, 'theme', 'core/modules/system/tests/themes/test_theme_libraries_empty', 'test_theme_libraries_empty.info.yml');
try {
$this->themeHandler
->addTheme($theme);
$this
->assertTrue(TRUE, 'Empty libraries key in theme.info.yml does not cause PHP warning');
} catch (\Exception $e) {
$this
->fail('Empty libraries key in theme.info.yml causes PHP warning.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
ThemeHandlerTest:: |
protected | property | The mocked config factory. | |
ThemeHandlerTest:: |
protected | property | The tested theme handler. | |
ThemeHandlerTest:: |
protected | property | The theme listing service. | |
ThemeHandlerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
ThemeHandlerTest:: |
public | function | Tests rebuilding the theme data. | |
ThemeHandlerTest:: |
public | function | Tests empty libraries in theme.info.yml file. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |