X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FBlock%2FBlockManagerTest.php;fp=web%2Fcore%2Ftests%2FDrupal%2FTests%2FCore%2FBlock%2FBlockManagerTest.php;h=1e9bb436db5ddfbababc084fdfbe4759d965c3e9;hb=bfbba508964731508b9bd6d5835c2edc858db95b;hp=0000000000000000000000000000000000000000;hpb=cb9a80db11fc6b014e5b1e693a5a391c95eb5d9a;p=yaffs-website diff --git a/web/core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php b/web/core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php new file mode 100644 index 000000000..1e9bb436d --- /dev/null +++ b/web/core/tests/Drupal/Tests/Core/Block/BlockManagerTest.php @@ -0,0 +1,89 @@ +prophesize(CacheBackendInterface::class); + $module_handler = $this->prophesize(ModuleHandlerInterface::class); + $this->blockManager = new BlockManager(new \ArrayObject(), $cache_backend->reveal(), $module_handler->reveal()); + $this->blockManager->setStringTranslation($this->getStringTranslationStub()); + + $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' => 'Group 2', + ], + 'block2' => [ + 'admin_label' => 'Apple', + 'category' => 'Group 1', + ], + 'block3' => [ + 'admin_label' => 'Banana', + 'category' => 'Group 2', + ], + ]); + // 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->assertSame(['Group 1', 'Group 2'], array_keys($definitions)); + $this->assertSame(['block2'], array_keys($definitions['Group 1'])); + $this->assertSame(['block3', 'block1'], array_keys($definitions['Group 2'])); + } + +}