diff --git a/core/tests/Drupal/KernelTests/Core/Block/BlockManagerTest.php b/core/tests/Drupal/KernelTests/Core/Block/BlockManagerTest.php deleted file mode 100644 index ff8cfb1..0000000 --- a/core/tests/Drupal/KernelTests/Core/Block/BlockManagerTest.php +++ /dev/null @@ -1,91 +0,0 @@ - [ - 'admin_label' => 'Broken/Missing', - 'category' => 'Block', - 'id' => 'broken', - 'class' => Broken::class, - 'provider' => 'core', - ], - 'page_title_block' => [ - 'admin_label' => 'Page title', - 'category' => 'core', - 'id' => 'page_title_block', - 'class' => PageTitleBlock::class, - 'provider' => 'core', - ], - 'local_actions_block' => [ - 'admin_label' => 'Primary admin actions', - 'category' => 'core', - 'id' => 'local_actions_block', - 'class' => LocalActionsBlock::class, - 'provider' => 'core', - ], - 'local_tasks_block' => [ - 'admin_label' => 'Tabs', - 'category' => 'core', - 'id' => 'local_tasks_block', - 'class' => LocalTasksBlock::class, - 'provider' => 'core', - ], - ]; - - /** - * @covers ::getDefinitions - */ - public function testDefinitions() { - $expected = $this->blockDefinitions; - $definitions = \Drupal::service('plugin.manager.block')->getDefinitions(); - $this->assertEquals($expected, $definitions); - } - - /** - * @covers ::getSortedDefinitions - */ - public function testSortedDefinitions() { - $expected = $this->blockDefinitions; - // Do not include the 'broken' plugin. - unset($expected['broken']); - - $definitions = \Drupal::service('plugin.manager.block')->getSortedDefinitions(); - $this->assertEquals($expected, $definitions); - // Ensure the order is as expected. - $this->assertSame(array_keys($expected), array_keys($definitions)); - } - - /** - * @covers ::getGroupedDefinitions - */ - public function testGroupedDefinitions() { - $expected = $this->blockDefinitions; - // Do not include the 'broken' plugin. - unset($expected['broken']); - // Group the plugins by their category. - $expected = ['core' => $expected]; - - $definitions = \Drupal::service('plugin.manager.block')->getGroupedDefinitions(); - $this->assertEquals($expected, $definitions); - } - -} diff --git a/core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php b/core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php new file mode 100644 index 0000000..796146d --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php @@ -0,0 +1,87 @@ +prophesize(CacheBackendInterface::class); + $module_handler = $this->prophesize(ModuleHandlerInterface::class); + $this->blockManager = new BlockManager(new \ArrayObject(), $cache_backend->reveal(), $module_handler->reveal()); + + $discovery = $this->prophesize(DiscoveryInterface::class); + // Specify the 'broken' block, as well as 3 other blocks with admin labels + // that are purposefully not in alphabetical order. + $discovery->getDefinitions()->willReturn([ + 'broken' => [ + 'admin_label' => 'Broken/Missing', + 'category' => 'Block', + ], + 'block1' => [ + 'admin_label' => 'Coconut', + 'category' => 'expected_category', + ], + 'block2' => [ + 'admin_label' => 'Apple', + 'category' => 'expected_category', + ], + 'block3' => [ + 'admin_label' => 'Banana', + 'category' => 'expected_category', + ], + ]); + // Force the discovery object onto the block manager. + $property = new \ReflectionProperty(BlockManager::class, 'discovery'); + $property->setAccessible(TRUE); + $property->setValue($this->blockManager, $discovery->reveal()); + } + + /** + * @covers ::getDefinitions + */ + public function testDefinitions() { + $definitions = $this->blockManager->getDefinitions(); + $this->assertSame(['broken', 'block1', 'block2', 'block3'], array_keys($definitions)); + } + + /** + * @covers ::getSortedDefinitions + */ + public function testSortedDefinitions() { + $definitions = $this->blockManager->getSortedDefinitions(); + $this->assertSame(['block2', 'block3', 'block1'], array_keys($definitions)); + } + + /** + * @covers ::getGroupedDefinitions + */ + public function testGroupedDefinitions() { + $definitions = $this->blockManager->getGroupedDefinitions(); + $this->assertArrayHasKey('expected_category', $definitions); + $this->assertSame(['block2', 'block3', 'block1'], array_keys($definitions['expected_category'])); + } + +}