1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Effortless maintenance management (http://juliangut.com/janitor) |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/juliangut/janitor for the canonical source repository |
6
|
|
|
* |
7
|
|
|
* @license https://github.com/juliangut/janitor/blob/master/LICENSE |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Janitor\Test\Handler; |
11
|
|
|
|
12
|
|
|
use Janitor\Handler\Redirect; |
13
|
|
|
use Zend\Diactoros\ServerRequestFactory; |
14
|
|
|
use Zend\Diactoros\Response; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @covers \Janitor\Handler\Redirect |
18
|
|
|
*/ |
19
|
|
|
class RedirectTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @covers \Janitor\Handler\Redirect::__construct |
23
|
|
|
* @covers \Janitor\Handler\Redirect::__invoke |
24
|
|
|
*/ |
25
|
|
|
public function testAbsouteRedirection() |
26
|
|
|
{ |
27
|
|
|
$watcher = $this->getMock('Janitor\\Watcher'); |
28
|
|
|
$handler = new Redirect('http://example.com'); |
29
|
|
|
|
30
|
|
|
$response = $handler(ServerRequestFactory::fromGlobals(), new Response('php://temp'), $watcher); |
31
|
|
|
|
32
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
33
|
|
|
$this->assertEquals('http://example.com', $response->getHeaderLine('Location')); |
34
|
|
|
$this->assertEquals('no-cache', $response->getHeaderLine('Pragma')); |
35
|
|
|
$this->assertTrue($response->hasHeader('Cache-Control')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers \Janitor\Handler\Redirect::__construct |
40
|
|
|
* @covers \Janitor\Handler\Redirect::__invoke |
41
|
|
|
*/ |
42
|
|
|
public function testRelativeRedirection() |
43
|
|
|
{ |
44
|
|
|
$request = ServerRequestFactory::fromGlobals(); |
45
|
|
|
$request = $request->withUri($request->getUri()->withHost('mydomain.com')); |
46
|
|
|
|
47
|
|
|
$watcher = $this->getMock('Janitor\\Watcher'); |
48
|
|
|
$handler = new Redirect('/maintenance'); |
49
|
|
|
|
50
|
|
|
$response = $handler($request, new Response('php://temp'), $watcher); |
51
|
|
|
|
52
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
53
|
|
|
$this->assertEquals('http://mydomain.com/maintenance', $response->getHeaderLine('Location')); |
54
|
|
|
$this->assertEquals('no-cache', $response->getHeaderLine('Pragma')); |
55
|
|
|
$this->assertTrue($response->hasHeader('Cache-Control')); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @covers \Janitor\Handler\Redirect::__construct |
60
|
|
|
* @covers \Janitor\Handler\Redirect::__invoke |
61
|
|
|
*/ |
62
|
|
|
public function testRedirectScheduled() |
63
|
|
|
{ |
64
|
|
|
$watcher = $this->getMock('Janitor\\ScheduledWatcher'); |
65
|
|
|
$watcher->expects($this->once())->method('getEnd')->will($this->returnValue(new \DateTime)); |
66
|
|
|
$handler = new Redirect('http://example.com'); |
67
|
|
|
|
68
|
|
|
$response = $handler(ServerRequestFactory::fromGlobals(), new Response('php://temp'), $watcher); |
69
|
|
|
|
70
|
|
|
$this->assertEquals(302, $response->getStatusCode()); |
71
|
|
|
$this->assertTrue($response->hasHeader('Expires')); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|