protected function RedirectRequestSubscriberTest::callOnKernelRequestCheckRedirect in Redirect 8
Instantiates the subscriber and runs onKernelRequestCheckRedirect()
Parameters
$redirect: The redirect entity.
$request_uri: The URI of the request.
array $request_query: The query that is supposed to come via request.
bool $retain_query: Flag if to retain the query through the redirect.
Return value
\Symfony\Component\HttpKernel\Event\GetResponseEvent THe response event.
2 calls to RedirectRequestSubscriberTest::callOnKernelRequestCheckRedirect()
- RedirectRequestSubscriberTest::testRedirectLogicWithoutQueryRetaining in tests/
src/ Unit/ RedirectRequestSubscriberTest.php - @covers ::onKernelRequestCheckRedirect @dataProvider getRedirectData
- RedirectRequestSubscriberTest::testRedirectLogicWithQueryRetaining in tests/
src/ Unit/ RedirectRequestSubscriberTest.php - @covers ::onKernelRequestCheckRedirect @dataProvider getRedirectData
File
- tests/
src/ Unit/ RedirectRequestSubscriberTest.php, line 131
Class
- RedirectRequestSubscriberTest
- Tests the redirect logic.
Namespace
Drupal\Tests\redirect\UnitCode
protected function callOnKernelRequestCheckRedirect($redirect, $request_uri, $request_query, $retain_query) {
$event = $this
->getGetResponseEventStub($request_uri, http_build_query($request_query));
$request = $event
->getRequest();
$checker = $this
->getMockBuilder('Drupal\\redirect\\RedirectChecker')
->disableOriginalConstructor()
->getMock();
$checker
->expects($this
->any())
->method('canRedirect')
->will($this
->returnValue(TRUE));
$context = $this
->createMock('Symfony\\Component\\Routing\\RequestContext');
$inbound_path_processor = $this
->getMockBuilder('Drupal\\Core\\PathProcessor\\InboundPathProcessorInterface')
->disableOriginalConstructor()
->getMock();
$inbound_path_processor
->expects($this
->any())
->method('processInbound')
->with($request
->getPathInfo(), $request)
->willReturnCallback(function ($path, Request $request) {
if (strpos($path, '/system/files/') === 0 && !$request->query
->has('file')) {
// Private files paths are split by the inbound path processor and the
// relative file path is moved to the 'file' query string parameter.
// This is because the route system does not allow an arbitrary amount
// of parameters.
// @see \Drupal\system\PathProcessor\PathProcessorFiles::processInbound()
$path = '/system/files';
}
return $path;
});
$alias_manager = $this
->createMock(AliasManagerInterface::class);
$module_handler = $this
->createMock(ModuleHandlerInterface::class);
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$subscriber = new RedirectRequestSubscriber($this
->getRedirectRepositoryStub('findMatchingRedirect', $redirect), $this
->getLanguageManagerStub(), $this
->getConfigFactoryStub([
'redirect.settings' => [
'passthrough_querystring' => $retain_query,
],
]), $alias_manager, $module_handler, $entity_type_manager, $checker, $context, $inbound_path_processor);
// Run the main redirect method.
$subscriber
->onKernelRequestCheckRedirect($event);
return $event;
}