ExtensionPathResolverTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Bootstrap/ExtensionPathResolverTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Bootstrap;
use Drupal\Core\Extension\Exception\UnknownExtensionException;
use Drupal\Core\Extension\Exception\UnknownExtensionTypeException;
use Drupal\Core\Extension\ExtensionPathResolver;
use Drupal\Core\Extension\ModuleExtensionList;
use Drupal\Core\Extension\ProfileExtensionList;
use Drupal\Core\Extension\ThemeEngineExtensionList;
use Drupal\Core\Extension\ThemeExtensionList;
use Drupal\KernelTests\KernelTestBase;
class ExtensionPathResolverTest extends KernelTestBase {
public function testExtensionPathResolving() : void {
$this
->assertSame('core/modules/system/system.info.yml', \Drupal::service('extension.list.module')
->getPathname('system'));
\Drupal::service('theme_installer')
->install([
'stark',
]);
$this
->assertSame('core/themes/stark/stark.info.yml', \Drupal::service('extension.list.theme')
->getPathname('stark'));
$this
->assertSame('core/themes/engines/twig/twig.info.yml', \Drupal::service('extension.list.theme_engine')
->getPathname('twig'));
$this
->assertSame('core/profiles/testing/testing.info.yml', \Drupal::service('extension.list.profile')
->getPathname('testing'));
}
public function testExtensionPathResolvingPath() : void {
$this
->assertSame('core/modules/system/tests/modules/driver_test', \Drupal::service('extension.list.module')
->getPath('driver_test'));
}
public function testExtensionPathResolvingWithNonExistingModule() : void {
$this
->expectException(UnknownExtensionException::class);
$this
->expectExceptionMessage('The module there_is_a_module_for_that does not exist.');
$this
->assertNull(\Drupal::service('extension.list.module')
->getPathname('there_is_a_module_for_that'), 'Searching for an item that does not exist returns NULL.');
}
public function testExtensionPathResolvingWithNonExistingTheme() : void {
$this
->expectException(UnknownExtensionException::class);
$this
->expectExceptionMessage('The theme there_is_a_theme_for_you does not exist.');
$this
->assertNull(\Drupal::service('extension.list.theme')
->getPathname('there_is_a_theme_for_you'), 'Searching for an item that does not exist returns NULL.');
}
public function testExtensionPathResolvingWithNonExistingProfile() : void {
$this
->expectException(UnknownExtensionException::class);
$this
->expectExceptionMessage('The profile there_is_an_install_profile_for_you does not exist.');
$this
->assertNull(\Drupal::service('extension.list.profile')
->getPathname('there_is_an_install_profile_for_you'), 'Searching for an item that does not exist returns NULL.');
}
public function testExtensionPathResolvingWithNonExistingThemeEngine() : void {
$this
->expectException(UnknownExtensionException::class);
$this
->expectExceptionMessage('The theme_engine there_is_an_theme_engine_for_you does not exist');
$this
->assertNull(\Drupal::service('extension.list.theme_engine')
->getPathname('there_is_an_theme_engine_for_you'), 'Searching for an item that does not exist returns NULL.');
}
public function testUnknownExtension() {
$module_extension_list = $this
->prophesize(ModuleExtensionList::class);
$profile_extension_list = $this
->prophesize(ProfileExtensionList::class);
$theme_extension_list = $this
->prophesize(ThemeExtensionList::class);
$theme_engine_extension_list = $this
->prophesize(ThemeEngineExtensionList::class);
$resolver = new ExtensionPathResolver($module_extension_list
->reveal(), $profile_extension_list
->reveal(), $theme_extension_list
->reveal(), $theme_engine_extension_list
->reveal());
$this
->expectException(UnknownExtensionTypeException::class);
$this
->expectExceptionMessage('Extension type foo is unknown.');
$resolver
->getPath('foo', 'bar');
}
}