3 namespace Drupal\Tests\layout_builder\Unit;
5 use Drupal\Component\Plugin\Factory\FactoryInterface;
6 use Drupal\Core\Cache\CacheBackendInterface;
7 use Drupal\Core\Extension\ModuleHandlerInterface;
8 use Drupal\layout_builder\SectionListInterface;
9 use Drupal\layout_builder\SectionStorage\SectionStorageManager;
10 use Drupal\layout_builder\SectionStorageInterface;
11 use Drupal\Tests\UnitTestCase;
14 * @coversDefaultClass \Drupal\layout_builder\SectionStorage\SectionStorageManager
16 * @group layout_builder
18 class SectionStorageManagerTest extends UnitTestCase {
21 * The section storage manager.
23 * @var \Drupal\layout_builder\SectionStorage\SectionStorageManager
30 * @var \Drupal\layout_builder\SectionStorageInterface
37 protected function setUp() {
40 $cache = $this->prophesize(CacheBackendInterface::class);
41 $module_handler = $this->prophesize(ModuleHandlerInterface::class);
42 $this->manager = new SectionStorageManager(new \ArrayObject(), $cache->reveal(), $module_handler->reveal());
44 $this->plugin = $this->prophesize(SectionStorageInterface::class);
46 $factory = $this->prophesize(FactoryInterface::class);
47 $factory->createInstance('the_plugin_id', [])->willReturn($this->plugin->reveal());
48 $reflection_property = new \ReflectionProperty($this->manager, 'factory');
49 $reflection_property->setAccessible(TRUE);
50 $reflection_property->setValue($this->manager, $factory->reveal());
56 public function testLoadEmpty() {
57 $result = $this->manager->loadEmpty('the_plugin_id');
58 $this->assertInstanceOf(SectionStorageInterface::class, $result);
62 * @covers ::loadFromStorageId
64 public function testLoadFromStorageId() {
65 $section_list = $this->prophesize(SectionListInterface::class);
66 $this->plugin->setSectionList($section_list->reveal())->will(function () {
69 $this->plugin->getSectionListFromId('the_storage_id')->willReturn($section_list->reveal());
71 $result = $this->manager->loadFromStorageId('the_plugin_id', 'the_storage_id');
72 $this->assertInstanceOf(SectionStorageInterface::class, $result);
76 * @covers ::loadFromRoute
78 public function testLoadFromRoute() {
79 $section_list = $this->prophesize(SectionListInterface::class);
80 $this->plugin->extractIdFromRoute('the_value', [], 'the_parameter_name', [])->willReturn('the_storage_id');
81 $this->plugin->getSectionListFromId('the_storage_id')->willReturn($section_list->reveal());
82 $this->plugin->setSectionList($section_list->reveal())->will(function () {
86 $result = $this->manager->loadFromRoute('the_plugin_id', 'the_value', [], 'the_parameter_name', []);
87 $this->assertInstanceOf(SectionStorageInterface::class, $result);
91 * @covers ::loadFromRoute
93 public function testLoadFromRouteNull() {
94 $this->plugin->extractIdFromRoute('the_value', [], 'the_parameter_name', ['_route' => 'the_route_name'])->willReturn(NULL);
96 $result = $this->manager->loadFromRoute('the_plugin_id', 'the_value', [], 'the_parameter_name', ['_route' => 'the_route_name']);
97 $this->assertNull($result);