Issue #3076797 by Wim Leers, lauriii, alexpott: \Drupal\Core\Extension\Extension's absence of validation has allowed multiple incorrect tests to be added

merge-requests/55/head
Alex Pott 2019-09-04 15:20:52 +01:00
parent 42962f7904
commit afcdeee465
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
11 changed files with 67 additions and 47 deletions

View File

@ -63,6 +63,8 @@ class Extension {
* (optional) The filename of the main extension file; e.g., 'node.module'. * (optional) The filename of the main extension file; e.g., 'node.module'.
*/ */
public function __construct($root, $type, $pathname, $filename = NULL) { public function __construct($root, $type, $pathname, $filename = NULL) {
// @see \Drupal\Core\Theme\ThemeInitialization::getActiveThemeByName()
assert($pathname === 'core/core.info.yml' || ($pathname[0] !== '/' && file_exists($root . '/' . $pathname)), sprintf('The file specified by the given app root, relative path and file name (%s) do not exist.', $root . '/' . $pathname));
$this->root = $root; $this->root = $root;
$this->type = $type; $this->type = $type;
$this->pathname = $pathname; $this->pathname = $pathname;
@ -155,7 +157,7 @@ class Extension {
*/ */
public function __call($method, array $args) { public function __call($method, array $args) {
if (!isset($this->splFileInfo)) { if (!isset($this->splFileInfo)) {
$this->splFileInfo = new \SplFileInfo($this->pathname); $this->splFileInfo = new \SplFileInfo($this->root . '/' . $this->pathname);
} }
return call_user_func_array([$this->splFileInfo, $method], $args); return call_user_func_array([$this->splFileInfo, $method], $args);
} }

View File

@ -47,6 +47,7 @@ EOF;
vfsStream::create([ vfsStream::create([
'modules' => [ 'modules' => [
'test_module' => [ 'test_module' => [
'test_module.info.yml' => $test_module_info,
'tests' => [ 'tests' => [
'src' => [ 'src' => [
'Functional' => [ 'Functional' => [
@ -212,7 +213,7 @@ EOF;
$test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); $test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal());
$result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); $result = $test_discovery->getTestClasses('test_profile_module', ['PHPUnit-Kernel']);
$expected = [ $expected = [
'example3' => [ 'example3' => [
'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [

View File

@ -31,7 +31,7 @@ class SystemLocalTasksTest extends LocalTaskIntegrationTestBase {
$this->themeHandler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface'); $this->themeHandler = $this->createMock('Drupal\Core\Extension\ThemeHandlerInterface');
$theme = new Extension($this->root, 'theme', '/core/themes/bartik', 'bartik.info.yml'); $theme = new Extension($this->root, 'theme', 'core/themes/bartik', 'bartik.info.yml');
$theme->status = 1; $theme->status = 1;
$theme->info = ['name' => 'bartik']; $theme->info = ['name' => 'bartik'];
$this->themeHandler->expects($this->any()) $this->themeHandler->expects($this->any())

View File

@ -76,7 +76,7 @@ class PermissionHandlerTest extends UnitTestCase {
* The extension object. * The extension object.
*/ */
protected function mockModuleExtension($module, $name) { protected function mockModuleExtension($module, $name) {
$extension = new Extension($this->root, $module, "modules/$module"); $extension = new Extension('vfs:/', $module, "modules/$module");
$extension->info['name'] = $name; $extension->info['name'] = $name;
return $extension; return $extension;
} }

View File

@ -26,7 +26,7 @@ class ExtensionListTest extends UnitTestCase {
*/ */
public function testGetNameWithNonExistingExtension() { public function testGetNameWithNonExistingExtension() {
list($cache, $info_parser, $module_handler, $state) = $this->getMocks(); list($cache, $info_parser, $module_handler, $state) = $this->getMocks();
$test_extension_list = new TestExtension($this->root, 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing'); $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 = $this->prophesize(ExtensionDiscovery::class);
$extension_discovery->scan('test_extension')->willReturn([]); $extension_discovery->scan('test_extension')->willReturn([]);
@ -50,7 +50,7 @@ class ExtensionListTest extends UnitTestCase {
*/ */
public function testGetWithNonExistingExtension() { public function testGetWithNonExistingExtension() {
list($cache, $info_parser, $module_handler, $state) = $this->getMocks(); list($cache, $info_parser, $module_handler, $state) = $this->getMocks();
$test_extension_list = new TestExtension($this->root, 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing'); $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 = $this->prophesize(ExtensionDiscovery::class);
$extension_discovery->scan('test_extension')->willReturn([]); $extension_discovery->scan('test_extension')->willReturn([]);
@ -142,7 +142,7 @@ class ExtensionListTest extends UnitTestCase {
$filenames = $test_extension_list->getPathnames(); $filenames = $test_extension_list->getPathnames();
$this->assertEquals([ $this->assertEquals([
'test_name' => 'vfs://drupal_root/example/test_name/test_name.info.yml', 'test_name' => 'example/test_name/test_name.info.yml',
], $filenames); ], $filenames);
} }
@ -153,7 +153,7 @@ class ExtensionListTest extends UnitTestCase {
$test_extension_list = $this->setupTestExtensionList(); $test_extension_list = $this->setupTestExtensionList();
$pathname = $test_extension_list->getPathname('test_name'); $pathname = $test_extension_list->getPathname('test_name');
$this->assertEquals('vfs://drupal_root/example/test_name/test_name.info.yml', $pathname); $this->assertEquals('example/test_name/test_name.info.yml', $pathname);
} }
/** /**
@ -174,7 +174,7 @@ class ExtensionListTest extends UnitTestCase {
$test_extension_list = $this->setupTestExtensionList(); $test_extension_list = $this->setupTestExtensionList();
$path = $test_extension_list->getPath('test_name'); $path = $test_extension_list->getPath('test_name');
$this->assertEquals('vfs://drupal_root/example/test_name', $path); $this->assertEquals('example/test_name', $path);
} }
/** /**
@ -184,24 +184,24 @@ class ExtensionListTest extends UnitTestCase {
$test_extension_list = $this->setupTestExtensionList(); $test_extension_list = $this->setupTestExtensionList();
$path = $test_extension_list->getPath('test_name'); $path = $test_extension_list->getPath('test_name');
$this->assertEquals('vfs://drupal_root/example/test_name', $path); $this->assertEquals('example/test_name', $path);
$pathname = $test_extension_list->getPathname('test_name'); $pathname = $test_extension_list->getPathname('test_name');
$this->assertEquals('vfs://drupal_root/example/test_name/test_name.info.yml', $pathname); $this->assertEquals('example/test_name/test_name.info.yml', $pathname);
$filenames = $test_extension_list->getPathnames(); $filenames = $test_extension_list->getPathnames();
$this->assertEquals([ $this->assertEquals([
'test_name' => 'vfs://drupal_root/example/test_name/test_name.info.yml', 'test_name' => 'example/test_name/test_name.info.yml',
], $filenames); ], $filenames);
$test_extension_list->reset(); $test_extension_list->reset();
// Ensure that everything is still usable after the resetting. // Ensure that everything is still usable after the resetting.
$path = $test_extension_list->getPath('test_name'); $path = $test_extension_list->getPath('test_name');
$this->assertEquals('vfs://drupal_root/example/test_name', $path); $this->assertEquals('example/test_name', $path);
$pathname = $test_extension_list->getPathname('test_name'); $pathname = $test_extension_list->getPathname('test_name');
$this->assertEquals('vfs://drupal_root/example/test_name/test_name.info.yml', $pathname); $this->assertEquals('example/test_name/test_name.info.yml', $pathname);
$filenames = $test_extension_list->getPathnames(); $filenames = $test_extension_list->getPathnames();
$this->assertEquals([ $this->assertEquals([
'test_name' => 'vfs://drupal_root/example/test_name/test_name.info.yml', 'test_name' => 'example/test_name/test_name.info.yml',
], $filenames); ], $filenames);
} }
@ -226,7 +226,7 @@ class ExtensionListTest extends UnitTestCase {
list($cache, $info_parser, $module_handler, $state) = $this->getMocks(); list($cache, $info_parser, $module_handler, $state) = $this->getMocks();
$info_parser->parse(Argument::any())->will(function ($args) { $info_parser->parse(Argument::any())->will(function ($args) {
return Yaml::decode(file_get_contents($args[0])); 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'); $test_extension_list = new TestExtension('vfs://drupal_root', 'test_extension', $cache->reveal(), $info_parser->reveal(), $module_handler->reveal(), $state->reveal(), 'testing');
@ -234,7 +234,7 @@ class ExtensionListTest extends UnitTestCase {
$extension_discovery = $this->prophesize(ExtensionDiscovery::class); $extension_discovery = $this->prophesize(ExtensionDiscovery::class);
$extension_scan_result = []; $extension_scan_result = [];
foreach ($extension_names as $extension_name) { foreach ($extension_names as $extension_name) {
$extension_scan_result[$extension_name] = new Extension($this->root, 'test_extension', "vfs://drupal_root/example/$extension_name/$extension_name.info.yml"); $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); $extension_discovery->scan('test_extension')->willReturn($extension_scan_result);
$test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal());

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\Core\Extension;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\Extension;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use org\bovigo\vfs\vfsStream;
/** /**
* Tests Extension serialization. * Tests Extension serialization.
@ -14,6 +15,23 @@ use Drupal\Core\DependencyInjection\ContainerBuilder;
*/ */
class ExtensionSerializationTest extends UnitTestCase { class ExtensionSerializationTest extends UnitTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
vfsStream::setup('dummy_app_root');
vfsStream::create([
'core' => [
'modules' => [
'system' => [
'system.info.yml' => file_get_contents($this->root . '/core/modules/system/system.info.yml'),
],
],
],
]);
}
/** /**
* Tests that the Extension class unserialize method uses the preferred root. * Tests that the Extension class unserialize method uses the preferred root.
* *
@ -30,12 +48,12 @@ class ExtensionSerializationTest extends UnitTestCase {
$this->assertFalse(defined('DRUPAL_ROOT'), 'Constant DRUPAL_ROOT is defined.'); $this->assertFalse(defined('DRUPAL_ROOT'), 'Constant DRUPAL_ROOT is defined.');
$container = new ContainerBuilder(); $container = new ContainerBuilder();
// Set a dummy container app.root to test against. // Set a dummy container app.root to test against.
$container->set('app.root', '/dummy/app/root'); $container->set('app.root', 'vfs://dummy_app_root');
\Drupal::setContainer($container); \Drupal::setContainer($container);
// Instantiate an Extension object for testing unserialization. // Instantiate an Extension object for testing unserialization.
$extension = new Extension($container->get('app.root'), 'module', 'core/modules/system/system.info.yml', 'system.module'); $extension = new Extension($container->get('app.root'), 'module', 'core/modules/system/system.info.yml', 'system.module');
$extension = unserialize(serialize($extension)); $extension = unserialize(serialize($extension));
$this->assertEquals('/dummy/app/root', $this->readAttribute($extension, 'root')); $this->assertEquals('vfs://dummy_app_root', $this->readAttribute($extension, 'root'));
} }
/** /**
@ -47,7 +65,7 @@ class ExtensionSerializationTest extends UnitTestCase {
public function testPublicProperties() { public function testPublicProperties() {
$container = new ContainerBuilder(); $container = new ContainerBuilder();
// Set a dummy container app.root to test against. // Set a dummy container app.root to test against.
$container->set('app.root', '/dummy/app/root'); $container->set('app.root', 'vfs://dummy_app_root');
\Drupal::setContainer($container); \Drupal::setContainer($container);
$extension = new Extension($container->get('app.root'), 'module', 'core/modules/system/system.info.yml', 'system.module'); $extension = new Extension($container->get('app.root'), 'module', 'core/modules/system/system.info.yml', 'system.module');
// Assign a public property dynamically. // Assign a public property dynamically.

View File

@ -318,7 +318,7 @@ class ModuleHandlerTest extends UnitTestCase {
$module_handler->addModule('module_handler_test_added', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added'); $module_handler->addModule('module_handler_test_added', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added');
$this->assertTrue($module_handler->implementsHook('module_handler_test_added', 'hook'), 'Runtime added module with implementation in include found.'); $this->assertTrue($module_handler->implementsHook('module_handler_test_added', 'hook'), 'Runtime added module with implementation in include found.');
$module_handler->addModule('module_handler_test_no_hook', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_added'); $module_handler->addModule('module_handler_test_no_hook', 'core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_no_hook');
$this->assertFalse($module_handler->implementsHook('module_handler_test_no_hook', 'hook', [TRUE]), 'Missing implementation not found.'); $this->assertFalse($module_handler->implementsHook('module_handler_test_no_hook', 'hook', [TRUE]), 'Missing implementation not found.');
} }
@ -502,8 +502,8 @@ class ModuleHandlerTest extends UnitTestCase {
public function testGetModuleDirectories() { public function testGetModuleDirectories() {
$module_handler = $this->getModuleHandler(); $module_handler = $this->getModuleHandler();
$module_handler->setModuleList([]); $module_handler->setModuleList([]);
$module_handler->addModule('module', 'place'); $module_handler->addModule('node', 'core/modules/node');
$this->assertEquals(['module' => $this->root . '/place'], $module_handler->getModuleDirectories()); $this->assertEquals(['node' => $this->root . '/core/modules/node'], $module_handler->getModuleDirectories());
} }
} }

View File

@ -31,29 +31,30 @@ class ThemeExtensionListTest extends UnitTestCase {
$extension_discovery $extension_discovery
->scan('theme') ->scan('theme')
->willReturn([ ->willReturn([
'test_subtheme' => new Extension($this->root, 'theme', $this->root . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml', 'test_subtheme.info.yml'), 'test_subtheme' => new Extension($this->root, 'theme', 'core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml', 'test_subtheme.info.yml'),
'test_basetheme' => new Extension($this->root, 'theme', $this->root . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml', 'test_basetheme.info.yml'), 'test_basetheme' => new Extension($this->root, 'theme', 'core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml', 'test_basetheme.info.yml'),
]); ]);
$extension_discovery $extension_discovery
->scan('theme_engine') ->scan('theme_engine')
->willReturn([ ->willReturn([
'twig' => new Extension($this->root, 'theme_engine', $this->root . '/core/themes/engines/twig/twig.info.yml', 'twig.engine'), 'twig' => new Extension($this->root, 'theme_engine', 'core/themes/engines/twig/twig.info.yml', 'twig.engine'),
]); ]);
// Verify that info parser is called with the specified paths. // Verify that info parser is called with the specified paths.
$argument_condition = function ($path) { $argument_condition = function ($path) {
return in_array($path, [ return in_array($path, [
$this->root . '/core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml', 'core/modules/system/tests/themes/test_subtheme/test_subtheme.info.yml',
$this->root . '/core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml', 'core/modules/system/tests/themes/test_basetheme/test_basetheme.info.yml',
$this->root . '/core/themes/engines/twig/twig.info.yml', 'core/themes/engines/twig/twig.info.yml',
], TRUE); ], TRUE);
}; };
$info_parser = $this->prophesize(InfoParserInterface::class); $info_parser = $this->prophesize(InfoParserInterface::class);
$root = $this->root;
$info_parser->parse(Argument::that($argument_condition)) $info_parser->parse(Argument::that($argument_condition))
->shouldBeCalled() ->shouldBeCalled()
->will(function ($file) { ->will(function ($file) use ($root) {
$info_parser = new InfoParser(); $info_parser = new InfoParser();
return $info_parser->parse($file[0]); return $info_parser->parse($root . '/' . $file[0]);
}); });
$module_handler = $this->prophesize(ModuleHandlerInterface::class); $module_handler = $this->prophesize(ModuleHandlerInterface::class);
@ -99,9 +100,9 @@ class ThemeExtensionListTest extends UnitTestCase {
$info_subtheme->info['base theme'] = 'test_basetheme'; $info_subtheme->info['base theme'] = 'test_basetheme';
$info_basetheme->sub_themes = ['test_subtheme']; $info_basetheme->sub_themes = ['test_subtheme'];
$this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info_basetheme->owner); $this->assertEquals('core/themes/engines/twig/twig.engine', $info_basetheme->owner);
$this->assertEquals('twig', $info_basetheme->prefix); $this->assertEquals('twig', $info_basetheme->prefix);
$this->assertEquals($this->root . '/core/themes/engines/twig/twig.engine', $info_subtheme->owner); $this->assertEquals('core/themes/engines/twig/twig.engine', $info_subtheme->owner);
$this->assertEquals('twig', $info_subtheme->prefix); $this->assertEquals('twig', $info_subtheme->prefix);
} }

View File

@ -80,7 +80,7 @@ class ThemeHandlerTest extends UnitTestCase {
$this->themeList->expects($this->at(1)) $this->themeList->expects($this->at(1))
->method('getList') ->method('getList')
->will($this->returnValue([ ->will($this->returnValue([
'seven' => new Extension($this->root, 'theme', $this->root . '/core/themes/seven/seven.info.yml', 'seven.theme'), 'seven' => new Extension($this->root, 'theme', 'core/themes/seven/seven.info.yml', 'seven.theme'),
])); ]));
$theme_data = $this->themeHandler->rebuildThemeData(); $theme_data = $this->themeHandler->rebuildThemeData();
@ -90,8 +90,8 @@ class ThemeHandlerTest extends UnitTestCase {
// Ensure some basic properties. // Ensure some basic properties.
$this->assertInstanceOf('Drupal\Core\Extension\Extension', $info); $this->assertInstanceOf('Drupal\Core\Extension\Extension', $info);
$this->assertEquals('seven', $info->getName()); $this->assertEquals('seven', $info->getName());
$this->assertEquals($this->root . '/core/themes/seven/seven.info.yml', $info->getPathname()); $this->assertEquals('core/themes/seven/seven.info.yml', $info->getPathname());
$this->assertEquals($this->root . '/core/themes/seven/seven.theme', $info->getExtensionPathname()); $this->assertEquals('core/themes/seven/seven.theme', $info->getExtensionPathname());
} }
@ -99,7 +99,7 @@ class ThemeHandlerTest extends UnitTestCase {
* Tests empty libraries in theme.info.yml file. * Tests empty libraries in theme.info.yml file.
*/ */
public function testThemeLibrariesEmpty() { public function testThemeLibrariesEmpty() {
$theme = new Extension($this->root, 'theme', '/core/modules/system/tests/themes/test_theme_libraries_empty', 'test_theme_libraries_empty.info.yml'); $theme = new Extension($this->root, 'theme', 'core/modules/system/tests/themes/test_theme_libraries_empty', 'test_theme_libraries_empty.info.yml');
try { try {
$this->themeHandler->addTheme($theme); $this->themeHandler->addTheme($theme);
$this->assertTrue(TRUE, 'Empty libraries key in theme.info.yml does not cause PHP warning'); $this->assertTrue(TRUE, 'Empty libraries key in theme.info.yml does not cause PHP warning');

View File

@ -70,7 +70,7 @@ class LayoutPluginManagerTest extends UnitTestCase {
$this->moduleHandler->moduleExists('core')->willReturn(FALSE); $this->moduleHandler->moduleExists('core')->willReturn(FALSE);
$this->moduleHandler->moduleExists('invalid_provider')->willReturn(FALSE); $this->moduleHandler->moduleExists('invalid_provider')->willReturn(FALSE);
$module_a = new Extension('/', 'module', vfsStream::url('root/modules/module_a/module_a.layouts.yml')); $module_a = new Extension('vfs://root', 'module', 'modules/module_a/module_a.layouts.yml');
$this->moduleHandler->getModule('module_a')->willReturn($module_a); $this->moduleHandler->getModule('module_a')->willReturn($module_a);
$this->moduleHandler->getModuleDirectories()->willReturn(['module_a' => vfsStream::url('root/modules/module_a')]); $this->moduleHandler->getModuleDirectories()->willReturn(['module_a' => vfsStream::url('root/modules/module_a')]);
$this->moduleHandler->alter('layout', Argument::type('array'))->shouldBeCalled(); $this->moduleHandler->alter('layout', Argument::type('array'))->shouldBeCalled();
@ -81,7 +81,7 @@ class LayoutPluginManagerTest extends UnitTestCase {
$this->themeHandler->themeExists('core')->willReturn(FALSE); $this->themeHandler->themeExists('core')->willReturn(FALSE);
$this->themeHandler->themeExists('invalid_provider')->willReturn(FALSE); $this->themeHandler->themeExists('invalid_provider')->willReturn(FALSE);
$theme_a = new Extension('/', 'theme', vfsStream::url('root/themes/theme_a/theme_a.layouts.yml')); $theme_a = new Extension('vfs://root', 'theme', 'themes/theme_a/theme_a.layouts.yml');
$this->themeHandler->getTheme('theme_a')->willReturn($theme_a); $this->themeHandler->getTheme('theme_a')->willReturn($theme_a);
$this->themeHandler->getThemeDirectories()->willReturn(['theme_a' => vfsStream::url('root/themes/theme_a')]); $this->themeHandler->getThemeDirectories()->willReturn(['theme_a' => vfsStream::url('root/themes/theme_a')]);
@ -112,7 +112,6 @@ class LayoutPluginManagerTest extends UnitTestCase {
* @covers ::processDefinition * @covers ::processDefinition
*/ */
public function testGetDefinition() { public function testGetDefinition() {
$theme_a_path = vfsStream::url('root/themes/theme_a');
$layout_definition = $this->layoutPluginManager->getDefinition('theme_a_provided_layout'); $layout_definition = $this->layoutPluginManager->getDefinition('theme_a_provided_layout');
$this->assertSame('theme_a_provided_layout', $layout_definition->id()); $this->assertSame('theme_a_provided_layout', $layout_definition->id());
$this->assertSame('2 column layout', (string) $layout_definition->getLabel()); $this->assertSame('2 column layout', (string) $layout_definition->getLabel());
@ -122,10 +121,10 @@ class LayoutPluginManagerTest extends UnitTestCase {
$this->assertTrue($layout_definition->getCategory() instanceof TranslatableMarkup); $this->assertTrue($layout_definition->getCategory() instanceof TranslatableMarkup);
$this->assertTrue($layout_definition->getDescription() instanceof TranslatableMarkup); $this->assertTrue($layout_definition->getDescription() instanceof TranslatableMarkup);
$this->assertSame('twocol', $layout_definition->getTemplate()); $this->assertSame('twocol', $layout_definition->getTemplate());
$this->assertSame("$theme_a_path/templates", $layout_definition->getPath()); $this->assertSame('themes/theme_a/templates', $layout_definition->getPath());
$this->assertSame('theme_a/twocol', $layout_definition->getLibrary()); $this->assertSame('theme_a/twocol', $layout_definition->getLibrary());
$this->assertSame('twocol', $layout_definition->getThemeHook()); $this->assertSame('twocol', $layout_definition->getThemeHook());
$this->assertSame("$theme_a_path/templates", $layout_definition->getTemplatePath()); $this->assertSame('themes/theme_a/templates', $layout_definition->getTemplatePath());
$this->assertSame('theme_a', $layout_definition->getProvider()); $this->assertSame('theme_a', $layout_definition->getProvider());
$this->assertSame('right', $layout_definition->getDefaultRegion()); $this->assertSame('right', $layout_definition->getDefaultRegion());
$this->assertSame(LayoutDefault::class, $layout_definition->getClass()); $this->assertSame(LayoutDefault::class, $layout_definition->getClass());
@ -142,7 +141,6 @@ class LayoutPluginManagerTest extends UnitTestCase {
$this->assertTrue($regions['left']['label'] instanceof TranslatableMarkup); $this->assertTrue($regions['left']['label'] instanceof TranslatableMarkup);
$this->assertTrue($regions['right']['label'] instanceof TranslatableMarkup); $this->assertTrue($regions['right']['label'] instanceof TranslatableMarkup);
$module_a_path = vfsStream::url('root/modules/module_a');
$layout_definition = $this->layoutPluginManager->getDefinition('module_a_provided_layout'); $layout_definition = $this->layoutPluginManager->getDefinition('module_a_provided_layout');
$this->assertSame('module_a_provided_layout', $layout_definition->id()); $this->assertSame('module_a_provided_layout', $layout_definition->id());
$this->assertSame('1 column layout', (string) $layout_definition->getLabel()); $this->assertSame('1 column layout', (string) $layout_definition->getLabel());
@ -152,7 +150,7 @@ class LayoutPluginManagerTest extends UnitTestCase {
$this->assertTrue($layout_definition->getCategory() instanceof TranslatableMarkup); $this->assertTrue($layout_definition->getCategory() instanceof TranslatableMarkup);
$this->assertTrue($layout_definition->getDescription() instanceof TranslatableMarkup); $this->assertTrue($layout_definition->getDescription() instanceof TranslatableMarkup);
$this->assertSame(NULL, $layout_definition->getTemplate()); $this->assertSame(NULL, $layout_definition->getTemplate());
$this->assertSame("$module_a_path/layouts", $layout_definition->getPath()); $this->assertSame('modules/module_a/layouts', $layout_definition->getPath());
$this->assertSame('module_a/onecol', $layout_definition->getLibrary()); $this->assertSame('module_a/onecol', $layout_definition->getLibrary());
$this->assertSame('onecol', $layout_definition->getThemeHook()); $this->assertSame('onecol', $layout_definition->getThemeHook());
$this->assertSame(NULL, $layout_definition->getTemplatePath()); $this->assertSame(NULL, $layout_definition->getTemplatePath());
@ -226,7 +224,6 @@ EOS;
*/ */
public function testGetThemeImplementations() { public function testGetThemeImplementations() {
$core_path = '/core/lib/Drupal/Core'; $core_path = '/core/lib/Drupal/Core';
$theme_a_path = vfsStream::url('root/themes/theme_a');
$expected = [ $expected = [
'layout' => [ 'layout' => [
'render element' => 'content', 'render element' => 'content',
@ -235,7 +232,7 @@ EOS;
'render element' => 'content', 'render element' => 'content',
'base hook' => 'layout', 'base hook' => 'layout',
'template' => 'twocol', 'template' => 'twocol',
'path' => "$theme_a_path/templates", 'path' => 'themes/theme_a/templates',
], ],
'plugin_provided_layout' => [ 'plugin_provided_layout' => [
'render element' => 'content', 'render element' => 'content',

View File

@ -326,6 +326,7 @@ EOF;
vfsStream::create([ vfsStream::create([
'modules' => [ 'modules' => [
'test_module' => [ 'test_module' => [
'test_module.info.yml' => $test_module_info,
'tests' => [ 'tests' => [
'src' => [ 'src' => [
'Functional' => [ 'Functional' => [
@ -491,7 +492,7 @@ EOF;
$test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal()); $test_discovery = new TestDiscovery('vfs://drupal', $class_loader->reveal(), $module_handler->reveal());
$result = $test_discovery->getTestClasses(NULL, ['PHPUnit-Kernel']); $result = $test_discovery->getTestClasses('test_profile_module', ['PHPUnit-Kernel']);
$expected = [ $expected = [
'example3' => [ 'example3' => [
'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [ 'Drupal\Tests\test_profile_module\Kernel\KernelExampleTest4' => [