You are here

public function RouteNameResponseSubscriberTest::testOnResponseCacheableWithBaseRouteName in Page Manager 8

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

@covers ::onResponse

File

tests/src/Unit/RouteNameResponseSubscriberTest.php, line 67
Contains \Drupal\Tests\page_manager\Unit\RouteNameResponseSubscriberTest.

Class

RouteNameResponseSubscriberTest
@coversDefaultClass \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber @group PageManager

Namespace

Drupal\Tests\page_manager\Unit

Code

public function testOnResponseCacheableWithBaseRouteName() {
  $response = new CacheableResponse('');
  $event = $this
    ->buildEvent($response);
  $route_name = 'the_route_name';
  $master_route_match = $this
    ->prophesize(RouteMatchInterface::class);
  $master_route_match
    ->getParameter('base_route_name')
    ->willReturn($route_name);
  $master_route_match
    ->getRouteName()
    ->shouldNotBeCalled();
  $current_route_match = $this
    ->prophesize(StackedRouteMatchInterface::class);
  $current_route_match
    ->getMasterRouteMatch()
    ->willReturn($master_route_match
    ->reveal());
  $subscriber = new RouteNameResponseSubscriber($current_route_match
    ->reveal());
  $subscriber
    ->onResponse($event);
  $expected = [
    "page_manager_route_name:{$route_name}",
  ];
  $this
    ->assertSame($expected, $response
    ->getCacheableMetadata()
    ->getCacheTags());
}