public function ComponentsInfoTest::testFindComponentsInfo in Components! 8.2
Tests finding components info from extension .info.yml files.
Since this is a protected method, we are testing it via the constructor, getAllModuleInfo, and isProtectedNamespace.
@covers ::findComponentsInfo
File
- tests/
src/ Unit/ ComponentsInfoTest.php, line 109
Class
- ComponentsInfoTest
- @coversDefaultClass \Drupal\components\Template\ComponentsInfo @group components
Namespace
Drupal\Tests\components\UnitCode
public function testFindComponentsInfo() {
$this->moduleExtensionList
->expects($this
->exactly(1))
->method('getAllInstalledInfo')
->willReturn([
// Does not have a components entry.
'system' => [
'name' => 'System',
'type' => 'module',
'package' => 'Core',
'no-components' => 'system-value',
],
// Look for namespaces using 1.x API (backwards compatibility).
'harriet_tubman' => [
'name' => 'Harriet Tubman',
'type' => 'module',
'component-libraries' => [
'harriet_tubman' => [
'paths' => [
'deprecated',
],
],
],
],
'phillis_wheatley' => [
'name' => 'Phillis Wheatley',
'type' => 'module',
'components' => [
'namespaces' => [
// Namespace path is a string.
'phillis_wheatley' => 'templates',
// Namespace path is an array.
'wheatley' => [
'components',
],
],
],
// If components.namespaces is set, ignore 1.x API.
'component-libraries' => [
'wheatley' => [
'paths' => [
'deprecated',
],
],
],
],
// No default namespace defined.
'edna_lewis' => [
'name' => 'Edna Lewis',
'type' => 'module',
'unrelatedKey' => 'should be ignored',
'components' => [
'includedKey' => 'included',
'namespaces' => [
'lewis' => [
'templates',
'components',
],
],
],
],
// Namespace path is relative to Drupal root.
'tracy_chapman' => [
'name' => 'Tracy Chapman',
'type' => 'module',
'components' => [
'namespaces' => [
'chapman' => [
'templates',
'/libraries/chapman/components',
],
],
],
],
// Manual opt-in.
'components' => [
'name' => 'Components!',
'type' => 'module',
'components' => [
'allow_default_namespace_reuse' => TRUE,
],
],
]);
$this->moduleExtensionList
->expects($this
->exactly(6))
->method('getPath')
->willReturn($this->rootDir . '/core/modules/system', $this->modulesDir . '/tubman', $this->modulesDir . '/wheatley', $this->modulesDir . '/lewis', $this->modulesDir . '/chapman', $this->modulesDir . '/components');
$this->themeExtensionList
->method('getAllInstalledInfo')
->willReturn([]);
$this
->newSystemUnderTest();
$expected = [
'harriet_tubman' => [
'namespaces' => [
'harriet_tubman' => [
$this->modulesDir . '/tubman/deprecated',
],
],
'extensionPath' => $this->modulesDir . '/tubman',
],
'phillis_wheatley' => [
'namespaces' => [
'phillis_wheatley' => [
$this->modulesDir . '/wheatley/templates',
],
'wheatley' => [
$this->modulesDir . '/wheatley/components',
],
],
'extensionPath' => $this->modulesDir . '/wheatley',
],
'edna_lewis' => [
'includedKey' => 'included',
'namespaces' => [
'lewis' => [
$this->modulesDir . '/lewis/templates',
$this->modulesDir . '/lewis/components',
],
],
'extensionPath' => $this->modulesDir . '/lewis',
],
'tracy_chapman' => [
'namespaces' => [
'chapman' => [
$this->modulesDir . '/chapman/templates',
$this->rootDir . '/libraries/chapman/components',
],
],
'extensionPath' => $this->modulesDir . '/chapman',
],
'components' => [
'allow_default_namespace_reuse' => TRUE,
'extensionPath' => $this->modulesDir . '/components',
],
];
$result = $this->systemUnderTest
->getAllModuleInfo();
$this
->assertEquals($expected, $result);
foreach ([
'system',
'edna_lewis',
'tracy_chapman',
] as $namespace) {
$this
->assertTrue($this->systemUnderTest
->isProtectedNamespace($namespace), 'Failed finding "' . $namespace . '" in protected namespaces list.');
}
foreach ([
'harriet_tubman',
'phillis_wheatley',
'wheatley',
'lewis',
'chapman',
'components',
] as $namespace) {
$this
->assertNotTrue($this->systemUnderTest
->isProtectedNamespace($namespace), 'Failed looking up "' . $namespace . '" in protected namespaces list.');
}
}