X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Flayout_builder%2Ftests%2Fsrc%2FUnit%2FLayoutTempstoreParamConverterTest.php;fp=web%2Fcore%2Fmodules%2Flayout_builder%2Ftests%2Fsrc%2FUnit%2FLayoutTempstoreParamConverterTest.php;h=5f8dc051e3765e978ea7a8ed39fa7d95f41c4935;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreParamConverterTest.php b/web/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreParamConverterTest.php new file mode 100644 index 000000000..5f8dc051e --- /dev/null +++ b/web/core/modules/layout_builder/tests/src/Unit/LayoutTempstoreParamConverterTest.php @@ -0,0 +1,85 @@ +prophesize(LayoutTempstoreRepositoryInterface::class); + $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class); + $converter = new LayoutTempstoreParamConverter($layout_tempstore_repository->reveal(), $section_storage_manager->reveal()); + + $section_storage = $this->prophesize(SectionStorageInterface::class); + + $value = 'some_value'; + $definition = ['layout_builder_tempstore' => TRUE]; + $name = 'the_parameter_name'; + $defaults = ['section_storage_type' => 'my_type']; + $expected = 'the_return_value'; + + $section_storage_manager->hasDefinition('my_type')->willReturn(TRUE); + $section_storage_manager->loadFromRoute('my_type', $value, $definition, $name, $defaults)->willReturn($section_storage); + + $layout_tempstore_repository->get($section_storage->reveal())->willReturn($expected); + + $result = $converter->convert($value, $definition, $name, $defaults); + $this->assertEquals($expected, $result); + } + + /** + * @covers ::convert + */ + public function testConvertNoType() { + $layout_tempstore_repository = $this->prophesize(LayoutTempstoreRepositoryInterface::class); + $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class); + $converter = new LayoutTempstoreParamConverter($layout_tempstore_repository->reveal(), $section_storage_manager->reveal()); + + $value = 'some_value'; + $definition = ['layout_builder_tempstore' => TRUE]; + $name = 'the_parameter_name'; + $defaults = ['section_storage_type' => NULL]; + + $section_storage_manager->hasDefinition()->shouldNotBeCalled(); + $section_storage_manager->loadFromRoute()->shouldNotBeCalled(); + $layout_tempstore_repository->get()->shouldNotBeCalled(); + + $result = $converter->convert($value, $definition, $name, $defaults); + $this->assertNull($result); + } + + /** + * @covers ::convert + */ + public function testConvertInvalidConverter() { + $layout_tempstore_repository = $this->prophesize(LayoutTempstoreRepositoryInterface::class); + $section_storage_manager = $this->prophesize(SectionStorageManagerInterface::class); + $converter = new LayoutTempstoreParamConverter($layout_tempstore_repository->reveal(), $section_storage_manager->reveal()); + + $value = 'some_value'; + $definition = ['layout_builder_tempstore' => TRUE]; + $name = 'the_parameter_name'; + $defaults = ['section_storage_type' => 'invalid']; + + $section_storage_manager->hasDefinition('invalid')->willReturn(FALSE); + $section_storage_manager->loadFromRoute()->shouldNotBeCalled(); + $layout_tempstore_repository->get()->shouldNotBeCalled(); + + $result = $converter->convert($value, $definition, $name, $defaults); + $this->assertNull($result); + } + +}