1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Zenstruck\RedirectBundle\Tests\Functional; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @author Kevin Bond <[email protected]> |
7
|
|
|
*/ |
8
|
|
|
class RedirectTest extends FunctionalTest |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @test |
12
|
|
|
*/ |
13
|
|
|
public function test301_redirect() |
14
|
|
|
{ |
15
|
|
|
$this->assertSame(0, $this->getRedirect('/301-redirect')->getCount()); |
16
|
|
|
|
17
|
|
|
$this->client->followRedirects(false); |
18
|
|
|
$this->client->request('GET', '/301-redirect'); |
19
|
|
|
$response = $this->client->getResponse(); |
20
|
|
|
|
21
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); |
22
|
|
|
$this->assertSame('http://symfony.com', $response->getTargetUrl()); |
23
|
|
|
$this->assertSame(301, $response->getStatusCode()); |
24
|
|
|
$this->assertSame(1, $this->getRedirect('/301-redirect')->getCount()); |
25
|
|
|
|
26
|
|
|
$this->client->request('GET', '/301-redirect?foo=bar'); |
27
|
|
|
$response = $this->client->getResponse(); |
28
|
|
|
|
29
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); |
30
|
|
|
$this->assertSame('http://symfony.com', $response->getTargetUrl()); |
31
|
|
|
$this->assertSame(2, $this->getRedirect('/301-redirect')->getCount()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function test302_redirect() |
38
|
|
|
{ |
39
|
|
|
$this->assertSame(0, $this->getRedirect('/302-redirect')->getCount()); |
40
|
|
|
|
41
|
|
|
$this->client->followRedirects(false); |
42
|
|
|
$this->client->request('GET', '/302-redirect'); |
43
|
|
|
$response = $this->client->getResponse(); |
44
|
|
|
|
45
|
|
|
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response); |
46
|
|
|
$this->assertSame('http://example.com', $response->getTargetUrl()); |
47
|
|
|
$this->assertSame(302, $response->getStatusCode()); |
48
|
|
|
$this->assertSame(1, $this->getRedirect('/302-redirect')->getCount()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|