public function RedirectRequestSubscriberTest::testRedirectLogicWithQueryRetaining in Redirect 8
@covers ::onKernelRequestCheckRedirect @dataProvider getRedirectData
File
- tests/
src/ Unit/ RedirectRequestSubscriberTest.php, line 32
Class
- RedirectRequestSubscriberTest
- Tests the redirect logic.
Namespace
Drupal\Tests\redirect\UnitCode
public function testRedirectLogicWithQueryRetaining($request_uri, $request_query, $redirect_uri, $redirect_query) {
// The expected final query. This query must contain values defined
// by the redirect entity and values from the accessed url.
$final_query = $redirect_query + $request_query;
$url = $this
->getMockBuilder('Drupal\\Core\\Url')
->disableOriginalConstructor()
->getMock();
$url
->expects($this
->once())
->method('setAbsolute')
->with(TRUE)
->willReturn($url);
$url
->expects($this
->once())
->method('getOption')
->with('query')
->willReturn($redirect_query);
$url
->expects($this
->once())
->method('setOption')
->with('query', $final_query);
$url
->expects($this
->once())
->method('toString')
->willReturn($redirect_uri);
$redirect = $this
->getRedirectStub($url);
$event = $this
->callOnKernelRequestCheckRedirect($redirect, $request_uri, $request_query, TRUE);
$this
->assertTrue($event
->getResponse() instanceof RedirectResponse);
$response = $event
->getResponse();
$this
->assertEquals('/test-path', $response
->getTargetUrl());
$this
->assertEquals(301, $response
->getStatusCode());
$this
->assertEquals(1, $response->headers
->get('X-Redirect-ID'));
}