You are here

public function VariantRouteFilterTest::testFilterAllowedAccessTwoRoutes in Page Manager 8

Same name and namespace in other branches
  1. 8.4 tests/src/Unit/VariantRouteFilterTest.php \Drupal\Tests\page_manager\Unit\VariantRouteFilterTest::testFilterAllowedAccessTwoRoutes()

@covers ::filter @covers ::getVariantRouteName

File

tests/src/Unit/VariantRouteFilterTest.php, line 203
Contains \Drupal\Tests\page_manager\Unit\VariantRouteFilterTest.

Class

VariantRouteFilterTest
@coversDefaultClass \Drupal\page_manager\Routing\VariantRouteFilter @group PageManager

Namespace

Drupal\Tests\page_manager\Unit

Code

public function testFilterAllowedAccessTwoRoutes() {
  $route_collection = new RouteCollection();
  $request = new Request();
  $route1 = new Route('/path/with/{slug}', [
    'page_manager_page_variant' => 'variant_1',
    'page_manager_page_variant_weight' => 0,
  ]);
  $route2 = new Route('/path/with/{slug}', [
    'page_manager_page_variant' => 'variant_2',
    'page_manager_page_variant_weight' => 2,
  ]);

  // Add route2 first to ensure that the routes get sorted by weight.
  $route_collection
    ->add('route_2', $route2);
  $route_collection
    ->add('route_1', $route1);
  $page_variant = $this
    ->prophesize(PageVariantInterface::class);
  $page_variant
    ->access('view')
    ->willReturn(TRUE);
  $this->currentPath
    ->getPath($request)
    ->willReturn('');
  $this->pageVariantStorage
    ->load('variant_1')
    ->willReturn($page_variant
    ->reveal());
  $this->pageVariantStorage
    ->load('variant_2')
    ->shouldNotBeCalled();
  $result = $this->routeFilter
    ->filter($route_collection, $request);
  $expected = [
    'route_1' => $route1,
  ];
  $this
    ->assertSame($expected, $result
    ->all());
  $expected_attributes = [
    'page_manager_page_variant' => 'variant_1',
    'page_manager_page_variant_weight' => 0,
    '_route_object' => $route1,
    '_route' => 'route_1',
  ];
  $this
    ->assertSame($expected_attributes, $request->attributes
    ->all());
}