X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Flayout_builder%2Ftests%2Fsrc%2FUnit%2FSectionStorageManagerTest.php;fp=web%2Fcore%2Fmodules%2Flayout_builder%2Ftests%2Fsrc%2FUnit%2FSectionStorageManagerTest.php;h=392cd8939ebed61081d53950a127850c72b133bd;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hp=0000000000000000000000000000000000000000;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0;p=yaffs-website diff --git a/web/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php b/web/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php new file mode 100644 index 000000000..392cd8939 --- /dev/null +++ b/web/core/modules/layout_builder/tests/src/Unit/SectionStorageManagerTest.php @@ -0,0 +1,100 @@ +prophesize(CacheBackendInterface::class); + $module_handler = $this->prophesize(ModuleHandlerInterface::class); + $this->manager = new SectionStorageManager(new \ArrayObject(), $cache->reveal(), $module_handler->reveal()); + + $this->plugin = $this->prophesize(SectionStorageInterface::class); + + $factory = $this->prophesize(FactoryInterface::class); + $factory->createInstance('the_plugin_id', [])->willReturn($this->plugin->reveal()); + $reflection_property = new \ReflectionProperty($this->manager, 'factory'); + $reflection_property->setAccessible(TRUE); + $reflection_property->setValue($this->manager, $factory->reveal()); + } + + /** + * @covers ::loadEmpty + */ + public function testLoadEmpty() { + $result = $this->manager->loadEmpty('the_plugin_id'); + $this->assertInstanceOf(SectionStorageInterface::class, $result); + } + + /** + * @covers ::loadFromStorageId + */ + public function testLoadFromStorageId() { + $section_list = $this->prophesize(SectionListInterface::class); + $this->plugin->setSectionList($section_list->reveal())->will(function () { + return $this; + }); + $this->plugin->getSectionListFromId('the_storage_id')->willReturn($section_list->reveal()); + + $result = $this->manager->loadFromStorageId('the_plugin_id', 'the_storage_id'); + $this->assertInstanceOf(SectionStorageInterface::class, $result); + } + + /** + * @covers ::loadFromRoute + */ + public function testLoadFromRoute() { + $section_list = $this->prophesize(SectionListInterface::class); + $this->plugin->extractIdFromRoute('the_value', [], 'the_parameter_name', [])->willReturn('the_storage_id'); + $this->plugin->getSectionListFromId('the_storage_id')->willReturn($section_list->reveal()); + $this->plugin->setSectionList($section_list->reveal())->will(function () { + return $this; + }); + + $result = $this->manager->loadFromRoute('the_plugin_id', 'the_value', [], 'the_parameter_name', []); + $this->assertInstanceOf(SectionStorageInterface::class, $result); + } + + /** + * @covers ::loadFromRoute + */ + public function testLoadFromRouteNull() { + $this->plugin->extractIdFromRoute('the_value', [], 'the_parameter_name', ['_route' => 'the_route_name'])->willReturn(NULL); + + $result = $this->manager->loadFromRoute('the_plugin_id', 'the_value', [], 'the_parameter_name', ['_route' => 'the_route_name']); + $this->assertNull($result); + } + +}