public function PanelsEverywhereRouteSubscriberTest::testSubscriberWillSetPanelsEverywherePageIdForOtherVariantsOnThePageIfOverrideDisabledAndRemoveOverriddenRoute in Panels Everywhere 8.4
File
- tests/
src/ Unit/ Routing/ PanelsEverywhereRouteSubscriberTest.php, line 293
Class
- PanelsEverywhereRouteSubscriberTest
- @coversDefaultClass \Drupal\panels_everywhere\Routing\PanelsEverywhereRouteSubscriber @group panels_everywhere
Namespace
Drupal\Tests\panels_everywhere\Unit\RoutingCode
public function testSubscriberWillSetPanelsEverywherePageIdForOtherVariantsOnThePageIfOverrideDisabledAndRemoveOverriddenRoute() {
$page_id = 'some_page_id';
$variant_id = 'some_variant_id';
$other_variant_id = 'some_other_variant_id';
$route_name_variant = "page_manager.page_view_{$page_id}_{$variant_id}";
$route_name_other_variant = "page_manager.page_view_{$page_id}_{$other_variant_id}";
$variantPlugin = $this
->prophesize(PanelsEverywhereDisplayVariant::class);
$variantPlugin
->isRouteOverrideEnabled()
->willReturn(FALSE);
$pageVariant = $this
->prophesize(PageVariantInterface::class);
$pageVariant
->id()
->willReturn($variant_id);
$pageVariant
->getVariantPluginId()
->willReturn('panels_everywhere_variant');
$pageVariant
->getVariantPlugin()
->willReturn($variantPlugin
->reveal());
$otherPageVariant = $this
->prophesize(PageVariantInterface::class);
$otherPageVariant
->id()
->willReturn($other_variant_id);
$otherPageVariant
->getVariantPluginId()
->willReturn('other_variant');
$pageEntity = $this
->prophesize(PageInterface::class);
$pageEntity
->id()
->willReturn($page_id);
$pageEntity
->status()
->willReturn(TRUE);
$pageEntity
->getVariants()
->willReturn([
$variant_id => $pageVariant
->reveal(),
$other_variant_id => $otherPageVariant
->reveal(),
]);
$pageStorage = $this
->prophesize(EntityStorageInterface::class);
$pageStorage
->loadMultiple()
->willReturn([
$pageEntity
->reveal(),
]);
$entityTypeManager = $this
->prophesize(EntityTypeManagerInterface::class);
$entityTypeManager
->getStorage('page')
->willReturn($pageStorage
->reveal());
$cacheTagsInvalidator = $this
->prophesize(CacheTagsInvalidatorInterface::class);
$routeVariant = new Route('/some-path');
$routeOtherVariant = new Route('/some-path');
$routeCollection = new RouteCollection();
$routeCollection
->add($route_name_variant, $routeVariant);
$routeCollection
->add($route_name_other_variant, $routeOtherVariant);
$event = new RouteBuildEvent($routeCollection);
// When.
$subscriber = new PanelsEverywhereRouteSubscriber($entityTypeManager
->reveal(), $cacheTagsInvalidator
->reveal());
$subscriber
->onAlterRoutes($event);
// Then.
self::assertNull($routeCollection
->get($route_name_variant));
self::assertEquals($page_id, $routeOtherVariant
->getDefault('page_id'));
}