public function VariantRouteFilterTest::testFilterRequestAttributesException in Page Manager 8
Same name and namespace in other branches
- 8.4 tests/src/Unit/VariantRouteFilterTest.php \Drupal\Tests\page_manager\Unit\VariantRouteFilterTest::testFilterRequestAttributesException()
@covers ::filter @covers ::getVariantRouteName @covers ::getRequestAttributes
File
- tests/
src/ Unit/ VariantRouteFilterTest.php, line 364 - Contains \Drupal\Tests\page_manager\Unit\VariantRouteFilterTest.
Class
- VariantRouteFilterTest
- @coversDefaultClass \Drupal\page_manager\Routing\VariantRouteFilter @group PageManager
Namespace
Drupal\Tests\page_manager\UnitCode
public function testFilterRequestAttributesException() {
$route_collection = new RouteCollection();
$original_attributes = [
'foo' => 'bar',
'slug' => 2,
];
$request = new Request([], [], $original_attributes);
$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());
$expected_enhance_attributes = [
'foo' => 'bar',
'slug' => '1',
'page_manager_page_variant' => 'a_variant',
'_route_object' => $route,
'_route' => 'a_route',
];
$route_enhancer
->enhance($expected_enhance_attributes, $request)
->willThrow(new \Exception('A route enhancer failed'));
$result = $this->routeFilter
->filter($route_collection, $request);
$this
->assertEmpty($result
->all());
$this
->assertSame($original_attributes, $request->attributes
->all());
}