You are here

public function VariantRouteFilterTest::testFilterRequestAttributes in Page Manager 8.4

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

@covers ::filter @covers ::getVariantRouteName @covers ::getRequestAttributes

File

tests/src/Unit/VariantRouteFilterTest.php, line 316

Class

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

Namespace

Drupal\Tests\page_manager\Unit

Code

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(EnhancerInterface::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());
}