1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
4
|
|
|
* @copyright (c) 2017-2018, Pierre-Henry Soria. All Rights Reserved. |
5
|
|
|
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
6
|
|
|
* @package PH7 / Test / Unit / App / System / Module / Error / Controller |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace PH7\Test\Unit\App\System\Module\Error\Controller; |
10
|
|
|
|
11
|
|
|
use GuzzleHttp\Client; |
12
|
|
|
use PH7\Framework\Mvc\Router\Uri; |
13
|
|
|
use PHPUnit_Framework_TestCase; |
14
|
|
|
|
15
|
|
|
class HttpControllerTest extends PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var Client */ |
18
|
|
|
protected $oClient; |
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->oClient = new Client(['exceptions' => false]); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testNotFoundPage() |
26
|
|
|
{ |
27
|
|
|
$oResponse = $this->oClient->get($this->getUrl()); |
28
|
|
|
|
29
|
|
|
$this->assertSame(404, $oResponse->getStatusCode()); |
30
|
|
|
$this->assertRegExp('/Page Not Found/', $oResponse->getBody()->__toString()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testBadRequestPage() |
34
|
|
|
{ |
35
|
|
|
$oResponse = $this->oClient->get($this->getUrl(400)); |
36
|
|
|
|
37
|
|
|
$this->assertSame(400, $oResponse->getStatusCode()); |
38
|
|
|
$this->assertRegExp('/Bad Request/', $oResponse->getBody()->__toString()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testUnauthorizedPage() |
42
|
|
|
{ |
43
|
|
|
$oResponse = $this->oClient->get($this->getUrl(401)); |
44
|
|
|
|
45
|
|
|
$this->assertSame(401, $oResponse->getStatusCode()); |
46
|
|
|
$this->assertRegExp('/Unauthorized/', $oResponse->getBody()->__toString()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testPaymentRequiredPage() |
50
|
|
|
{ |
51
|
|
|
$oResponse = $this->oClient->get($this->getUrl(402)); |
52
|
|
|
|
53
|
|
|
$this->assertSame(402, $oResponse->getStatusCode()); |
54
|
|
|
$this->assertRegExp('/Payment Required/', $oResponse->getBody()->__toString()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testForbiddenPage() |
58
|
|
|
{ |
59
|
|
|
$oResponse = $this->oClient->get($this->getUrl(403)); |
60
|
|
|
|
61
|
|
|
$this->assertSame(403, $oResponse->getStatusCode()); |
62
|
|
|
$this->assertRegExp('/Forbidden/', $oResponse->getBody()->__toString()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testMethodNotAllowedPage() |
66
|
|
|
{ |
67
|
|
|
$oResponse = $this->oClient->get($this->getUrl(405)); |
68
|
|
|
|
69
|
|
|
$this->assertSame(405, $oResponse->getStatusCode()); |
70
|
|
|
$this->assertRegExp('/Method Not Allowed/', $oResponse->getBody()->__toString()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testInternalServerErrorPage() |
74
|
|
|
{ |
75
|
|
|
$oResponse = $this->oClient->get($this->getUrl(500)); |
76
|
|
|
|
77
|
|
|
$this->assertSame(500, $oResponse->getStatusCode()); |
78
|
|
|
$this->assertRegExp('/Internal Server Error/', $oResponse->getBody()->__toString()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function testNotImplementedPage() |
82
|
|
|
{ |
83
|
|
|
$oResponse = $this->oClient->get($this->getUrl(501)); |
84
|
|
|
|
85
|
|
|
$this->assertSame(501, $oResponse->getStatusCode()); |
86
|
|
|
$this->assertRegExp('/Not Implemented/', $oResponse->getBody()->__toString()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testBadGatewayPage() |
90
|
|
|
{ |
91
|
|
|
$oResponse = $this->oClient->get($this->getUrl(502)); |
92
|
|
|
|
93
|
|
|
$this->assertSame(502, $oResponse->getStatusCode()); |
94
|
|
|
$this->assertRegExp('/Bad Gateway/', $oResponse->getBody()->__toString()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testGatewayTimeoutPage() |
98
|
|
|
{ |
99
|
|
|
$oResponse = $this->oClient->get($this->getUrl(504)); |
100
|
|
|
|
101
|
|
|
$this->assertSame(504, $oResponse->getStatusCode()); |
102
|
|
|
$this->assertRegExp('/Gateway Timeout/', $oResponse->getBody()->__toString()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testHttpVersionNotSupportedPage() |
106
|
|
|
{ |
107
|
|
|
$oResponse = $this->oClient->get($this->getUrl(505)); |
108
|
|
|
|
109
|
|
|
$this->assertSame(505, $oResponse->getStatusCode()); |
110
|
|
|
$this->assertRegExp('/HTTP Version Not Supported/', $oResponse->getBody()->__toString()); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
private function getUrl($sUri = '') |
114
|
|
|
{ |
115
|
|
|
return Uri::get('error', 'http', 'index', $sUri); |
116
|
|
|
} |
117
|
|
|
} |