class RouteNameResponseSubscriberTest in Page Manager 8
Same name and namespace in other branches
- 8.4 tests/src/Unit/RouteNameResponseSubscriberTest.php \Drupal\Tests\page_manager\Unit\RouteNameResponseSubscriberTest
@coversDefaultClass \Drupal\page_manager\EventSubscriber\RouteNameResponseSubscriber @group PageManager
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\page_manager\Unit\RouteNameResponseSubscriberTest
Expanded class hierarchy of RouteNameResponseSubscriberTest
File
- tests/
src/ Unit/ RouteNameResponseSubscriberTest.php, line 24 - Contains \Drupal\Tests\page_manager\Unit\RouteNameResponseSubscriberTest.
Namespace
Drupal\Tests\page_manager\UnitView source
class RouteNameResponseSubscriberTest extends UnitTestCase {
/**
* @covers ::onResponse
*/
public function testOnResponseCacheable() {
$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(NULL);
$master_route_match
->getRouteName()
->willReturn($route_name);
$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());
}
/**
* @covers ::onResponse
*/
public function testOnResponseUncacheable() {
$response = new Response('');
$event = $this
->buildEvent($response);
$master_route_match = $this
->prophesize(RouteMatchInterface::class);
$master_route_match
->getParameter()
->shouldNotBeCalled();
$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);
}
/**
* @covers ::onResponse
*/
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());
}
/**
* Builds an event to wrap a response.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* The response to be sent as the event payload.
*
* @return \Symfony\Component\HttpKernel\Event\FilterResponseEvent
* An event suitable for a KernelEvents::RESPONSE subscriber to process.
*/
protected function buildEvent(Response $response) {
$kernel = $this
->prophesize(HttpKernelInterface::class);
$request = Request::create('');
return new FilterResponseEvent($kernel
->reveal(), $request, HttpKernelInterface::SUB_REQUEST, $response);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RouteNameResponseSubscriberTest:: |
protected | function | Builds an event to wrap a response. | |
RouteNameResponseSubscriberTest:: |
public | function | @covers ::onResponse | |
RouteNameResponseSubscriberTest:: |
public | function | @covers ::onResponse | |
RouteNameResponseSubscriberTest:: |
public | function | @covers ::onResponse | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |