class ExtensionListTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php \Drupal\Tests\Core\Extension\ExtensionListTest
- 8.9.x core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php \Drupal\Tests\Core\Extension\ExtensionListTest
- 11.x core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php \Drupal\Tests\Core\Extension\ExtensionListTest
@coversDefaultClass \Drupal\Core\Extension\ExtensionList @group Extension
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Extension\ExtensionListTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ExtensionListTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Extension/ ExtensionListTest.php, line 24
Namespace
Drupal\Tests\Core\ExtensionView source
class ExtensionListTest extends UnitTestCase {
/**
* @covers ::getName
*/
public function testGetNameWithNonExistingExtension() : void {
[
$cache,
$info_parser,
$module_handler,
$state,
] = $this->getMocks();
$test_extension_list = new TestExtension($this->randomMachineName(), 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing');
$extension_discovery = $this->prophesize(ExtensionDiscovery::class);
$extension_discovery->scan('test_extension')
->willReturn([]);
$test_extension_list->setExtensionDiscovery($extension_discovery->reveal());
$this->expectException(UnknownExtensionException::class);
$test_extension_list->getName('test_name');
}
/**
* @covers ::getName
*/
public function testGetName() : void {
$test_extension_list = $this->setupTestExtensionList();
$this->assertEquals('test name', $test_extension_list->getName('test_name'));
}
/**
* @covers ::get
*/
public function testGetWithNonExistingExtension() : void {
[
$cache,
$info_parser,
$module_handler,
$state,
] = $this->getMocks();
$test_extension_list = new TestExtension($this->randomMachineName(), 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing');
$extension_discovery = $this->prophesize(ExtensionDiscovery::class);
$extension_discovery->scan('test_extension')
->willReturn([]);
$test_extension_list->setExtensionDiscovery($extension_discovery->reveal());
$this->expectException(UnknownExtensionException::class);
$test_extension_list->get('test_name');
}
/**
* @covers ::get
*/
public function testGet() : void {
$test_extension_list = $this->setupTestExtensionList();
$extension = $test_extension_list->get('test_name');
$this->assertInstanceOf(Extension::class, $extension);
$this->assertEquals('test_name', $extension->getName());
}
/**
* @covers ::getList
*/
public function testGetList() : void {
$test_extension_list = $this->setupTestExtensionList();
$extensions = $test_extension_list->getList();
$this->assertCount(1, $extensions);
$this->assertEquals('test_name', $extensions['test_name']->getName());
}
/**
* @covers ::getExtensionInfo
* @covers ::getAllInstalledInfo
*/
public function testGetExtensionInfo() : void {
$test_extension_list = $this->setupTestExtensionList();
$test_extension_list->setInstalledExtensions([
'test_name',
]);
$info = $test_extension_list->getExtensionInfo('test_name');
$this->assertEquals([
'type' => 'test_extension',
'core' => '8.x',
'name' => 'test name',
'mtime' => 123456789,
], $info);
}
/**
* @covers ::getAllAvailableInfo
*/
public function testGetAllAvailableInfo() : void {
$test_extension_list = $this->setupTestExtensionList();
$infos = $test_extension_list->getAllAvailableInfo();
$this->assertEquals([
'test_name' => [
'type' => 'test_extension',
'core' => '8.x',
'name' => 'test name',
'mtime' => 123456789,
],
], $infos);
}
/**
* @covers ::getAllInstalledInfo
*/
public function testGetAllInstalledInfo() : void {
$test_extension_list = $this->setupTestExtensionList([
'test_name',
'test_name_2',
]);
$test_extension_list->setInstalledExtensions([
'test_name_2',
]);
$infos = $test_extension_list->getAllInstalledInfo();
$this->assertEquals([
'test_name_2' => [
'type' => 'test_extension',
'core' => '8.x',
'name' => 'test name',
'mtime' => 123456789,
],
], $infos);
}
/**
* @covers ::getPathNames
*/
public function testGetPathNames() : void {
$test_extension_list = $this->setupTestExtensionList();
$filenames = $test_extension_list->getPathNames();
$this->assertEquals([
'test_name' => 'example/test_name/test_name.info.yml',
], $filenames);
}
/**
* @covers ::getPathname
*/
public function testGetPathname() : void {
$test_extension_list = $this->setupTestExtensionList();
$pathname = $test_extension_list->getPathname('test_name');
$this->assertEquals('example/test_name/test_name.info.yml', $pathname);
}
/**
* @covers ::setPathname
* @covers ::getPathname
*/
public function testSetPathname() : void {
$test_extension_list = $this->setupTestExtensionList();
$test_extension_list->setPathname('test_name', 'vfs://drupal_root/example2/test_name/test_name.info.yml');
$this->assertEquals('vfs://drupal_root/example2/test_name/test_name.info.yml', $test_extension_list->getPathname('test_name'));
}
/**
* @covers ::getPath
*/
public function testGetPath() : void {
$test_extension_list = $this->setupTestExtensionList();
$path = $test_extension_list->getPath('test_name');
$this->assertEquals('example/test_name', $path);
}
/**
* @covers ::reset
*/
public function testReset() : void {
$test_extension_list = $this->setupTestExtensionList();
$path = $test_extension_list->getPath('test_name');
$this->assertEquals('example/test_name', $path);
$pathname = $test_extension_list->getPathname('test_name');
$this->assertEquals('example/test_name/test_name.info.yml', $pathname);
$filenames = $test_extension_list->getPathNames();
$this->assertEquals([
'test_name' => 'example/test_name/test_name.info.yml',
], $filenames);
$test_extension_list->reset();
// Ensure that everything is still usable after the resetting.
$path = $test_extension_list->getPath('test_name');
$this->assertEquals('example/test_name', $path);
$pathname = $test_extension_list->getPathname('test_name');
$this->assertEquals('example/test_name/test_name.info.yml', $pathname);
$filenames = $test_extension_list->getPathNames();
$this->assertEquals([
'test_name' => 'example/test_name/test_name.info.yml',
], $filenames);
}
/**
* @covers ::checkIncompatibility
*
* @dataProvider providerCheckIncompatibility
*/
public function testCheckIncompatibility($additional_settings, $expected) : void {
$test_extension_list = $this->setupTestExtensionList([
'test_name',
], $additional_settings);
$this->assertSame($expected, $test_extension_list->checkIncompatibility('test_name'));
}
/**
* DataProvider for testCheckIncompatibility().
*/
public static function providerCheckIncompatibility() {
return [
'core_incompatible true' => [
[
'core_incompatible' => TRUE,
],
TRUE,
],
'core_incompatible false' => [
[
'core_incompatible' => FALSE,
],
FALSE,
],
'PHP 1, core_incompatible FALSE' => [
[
'core_incompatible' => FALSE,
'php' => 1,
],
FALSE,
],
'PHP 1000000000000, core_incompatible FALSE' => [
[
'core_incompatible' => FALSE,
'php' => 1000000000000,
],
TRUE,
],
'PHP 1, core_incompatible TRUE' => [
[
'core_incompatible' => TRUE,
'php' => 1,
],
TRUE,
],
'PHP 1000000000000, core_incompatible TRUE' => [
[
'core_incompatible' => TRUE,
'php' => 1000000000000,
],
TRUE,
],
];
}
/**
* Sets up an a test extension list.
*
* @param string[] $extension_names
* The names of the extensions to create.
* @param mixed[] $additional_info_values
* The additional values to add to extensions info.yml files. These values
* will be encoded using '\Drupal\Component\Serialization\Yaml::encode()'.
* The array keys should be valid top level yaml file keys.
*
* @return \Drupal\Tests\Core\Extension\TestExtension
* The test extension list.
*/
protected function setupTestExtensionList(array $extension_names = [
'test_name',
], array $additional_info_values = []) {
vfsStream::setup('drupal_root');
$folders = [
'example' => [],
];
foreach ($extension_names as $extension_name) {
$folders['example'][$extension_name][$extension_name . '.info.yml'] = Yaml::encode([
'name' => 'test name',
'type' => 'test_extension',
'core' => '8.x',
] + $additional_info_values);
}
vfsStream::create($folders);
foreach ($extension_names as $extension_name) {
touch("vfs://drupal_root/example/{$extension_name}/{$extension_name}.info.yml", 123456789);
}
[
$cache,
$info_parser,
$module_handler,
$state,
] = $this->getMocks();
$info_parser->parse(Argument::any())
->will(function ($args) {
return Yaml::decode(file_get_contents('vfs://drupal_root/' . $args[0]));
});
$test_extension_list = new TestExtension('vfs://drupal_root', 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing');
$extension_discovery = $this->prophesize(ExtensionDiscovery::class);
$extension_scan_result = [];
foreach ($extension_names as $extension_name) {
$extension_scan_result[$extension_name] = new Extension('vfs://drupal_root', 'test_extension', "example/{$extension_name}/{$extension_name}.info.yml");
}
$extension_discovery->scan('test_extension')
->willReturn($extension_scan_result);
$test_extension_list->setExtensionDiscovery($extension_discovery->reveal());
return $test_extension_list;
}
protected function getMocks() {
$cache = $this->prophesize(CacheBackendInterface::class);
$info_parser = $this->prophesize(InfoParserInterface::class);
$module_handler = $this->prophesize(ModuleHandlerInterface::class);
$state = $this->prophesize(StateInterface::class);
return [
$cache,
$info_parser,
$module_handler,
$state,
];
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|---|
ExtensionListTest::getMocks | protected | function | |||
ExtensionListTest::providerCheckIncompatibility | public static | function | DataProvider for testCheckIncompatibility(). | ||
ExtensionListTest::setupTestExtensionList | protected | function | Sets up an a test extension list. | ||
ExtensionListTest::testCheckIncompatibility | public | function | @covers ::checkIncompatibility | ||
ExtensionListTest::testGet | public | function | @covers ::get | ||
ExtensionListTest::testGetAllAvailableInfo | public | function | @covers ::getAllAvailableInfo | ||
ExtensionListTest::testGetAllInstalledInfo | public | function | @covers ::getAllInstalledInfo | ||
ExtensionListTest::testGetExtensionInfo | public | function | @covers ::getExtensionInfo @covers ::getAllInstalledInfo |
||
ExtensionListTest::testGetList | public | function | @covers ::getList | ||
ExtensionListTest::testGetName | public | function | @covers ::getName | ||
ExtensionListTest::testGetNameWithNonExistingExtension | public | function | @covers ::getName | ||
ExtensionListTest::testGetPath | public | function | @covers ::getPath | ||
ExtensionListTest::testGetPathname | public | function | @covers ::getPathname | ||
ExtensionListTest::testGetPathNames | public | function | @covers ::getPathNames | ||
ExtensionListTest::testGetWithNonExistingExtension | public | function | @covers ::get | ||
ExtensionListTest::testReset | public | function | @covers ::reset | ||
ExtensionListTest::testSetPathname | public | function | @covers ::setPathname @covers ::getPathname |
||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | ||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | ||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | ||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | ||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | ||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | ||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | |
UnitTestCase::$root | protected | property | The app root. | 1 | |
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | ||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | ||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | ||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | ||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | ||
UnitTestCase::setUp | protected | function | 358 | ||
UnitTestCase::setUpBeforeClass | public static | function | |||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.