/** * @covers ::access */ public function testAccess() { $this->storage->load('id_exists')->willReturn($this->pageVariant->reveal()); $this->storage->load('doesnt_exist')->willReturn(NULL); $account = $this->prophesize(AccountInterface::class); $this->pageVariant->access('read', $account->reveal(), TRUE)->willReturn(AccessResult::allowed()); $panels_storage = new PageManagerPanelsStorage([], '', [], $this->entityTypeManager->reveal()); // Test the access condition. $this->assertEquals(AccessResult::allowed(), $panels_storage->access('id_exists', 'read', $account->reveal())); // Should be forbidden if it doesn't exist. $this->assertEquals(AccessResult::forbidden(), $panels_storage->access('doesnt_exist', 'read', $account->reveal())); }
/** * @covers ::filter */ public function testFilterRequestAttributes() { $route_collection = new RouteCollection(); $request = new Request([], [], ['foo' => 'bar', 'slug' => 2]); $route = new Route('/path/with/{slug}', ['page_manager_page_variant' => 'a_variant']); $route_collection->add('a_route', $route); $page_variant = $this->prophesize(PageVariantInterface::class); $page_variant->access('view')->willReturn(TRUE); $this->currentPath->getPath($request)->willReturn('/path/with/1'); $this->pageVariantStorage->load('a_variant')->willReturn($page_variant->reveal()); $route_enhancer = $this->prophesize(RouteEnhancerInterface::class); $this->routeFilter->addRouteEnhancer($route_enhancer->reveal()); $result_enhance_attributes = $expected_enhance_attributes = ['foo' => 'bar', 'slug' => '1', 'page_manager_page_variant' => 'a_variant', '_route_object' => $route, '_route' => 'a_route']; $result_enhance_attributes['slug'] = 'slug 1'; $route_enhancer->enhance($expected_enhance_attributes, $request)->willReturn($result_enhance_attributes); $result = $this->routeFilter->filter($route_collection, $request); $expected = ['a_route' => $route]; $this->assertSame($expected, $result->all()); $expected_attributes = ['foo' => 'bar', 'slug' => 'slug 1', 'page_manager_page_variant' => 'a_variant', '_route_object' => $route, '_route' => 'a_route']; $this->assertSame($expected_attributes, $request->attributes->all()); }