1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpCacheGUITest\Unit\Network; |
4
|
|
|
|
5
|
|
|
use OpCacheGUI\Network\Request; |
6
|
|
|
use OpCacheGUI\Network\RequestData; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class RequestTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
13
|
|
|
*/ |
14
|
|
|
public function testConstructCorrectInstance() |
15
|
|
|
{ |
16
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '']); |
17
|
|
|
|
18
|
|
|
$this->assertInstanceOf(RequestData::class, $request); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
23
|
|
|
* @covers OpCacheGUI\Network\Request::get |
24
|
|
|
*/ |
25
|
|
|
public function testGetNoQueryString() |
26
|
|
|
{ |
27
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '']); |
28
|
|
|
|
29
|
|
|
$this->assertSame('', $request->get()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
34
|
|
|
* @covers OpCacheGUI\Network\Request::get |
35
|
|
|
*/ |
36
|
|
|
public function testGetQueryString() |
37
|
|
|
{ |
38
|
|
|
$request = new Request(['foo' => '', 'bar' => ''], [], ['REQUEST_URI' => '']); |
39
|
|
|
|
40
|
|
|
$this->assertSame('foo', $request->get()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
45
|
|
|
* @covers OpCacheGUI\Network\Request::path |
46
|
|
|
*/ |
47
|
|
|
public function testPathEmptyRequestUri() |
48
|
|
|
{ |
49
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '']); |
50
|
|
|
|
51
|
|
|
$this->assertSame('', $request->path()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
56
|
|
|
* @covers OpCacheGUI\Network\Request::path |
57
|
|
|
*/ |
58
|
|
|
public function testPathOnlySlash() |
59
|
|
|
{ |
60
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '/']); |
61
|
|
|
|
62
|
|
|
$this->assertSame('', $request->path()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
67
|
|
|
* @covers OpCacheGUI\Network\Request::path |
68
|
|
|
*/ |
69
|
|
|
public function testPathSingle() |
70
|
|
|
{ |
71
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '/foo']); |
72
|
|
|
|
73
|
|
|
$this->assertSame('foo', $request->path()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
78
|
|
|
* @covers OpCacheGUI\Network\Request::path |
79
|
|
|
*/ |
80
|
|
|
public function testPathMultiple() |
81
|
|
|
{ |
82
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '/foo/bar']); |
83
|
|
|
|
84
|
|
|
$this->assertSame('bar', $request->path()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
89
|
|
|
* @covers OpCacheGUI\Network\Request::path |
90
|
|
|
*/ |
91
|
|
|
public function testPathTrailingSlash() |
92
|
|
|
{ |
93
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '/foo/bar/']); |
94
|
|
|
|
95
|
|
|
$this->assertSame('bar', $request->path()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
100
|
|
|
* @covers OpCacheGUI\Network\Request::getVerb |
101
|
|
|
*/ |
102
|
|
|
public function testGetVerb() |
103
|
|
|
{ |
104
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '', 'REQUEST_METHOD' => 'POST']); |
105
|
|
|
|
106
|
|
|
$this->assertSame('POST', $request->getVerb()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
111
|
|
|
* @covers OpCacheGUI\Network\Request::post |
112
|
|
|
*/ |
113
|
|
|
public function testPost() |
114
|
|
|
{ |
115
|
|
|
$request = new Request([], ['foo' => 'bar'], ['REQUEST_URI' => '']); |
116
|
|
|
|
117
|
|
|
$this->assertSame('bar', $request->post('foo')); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
122
|
|
|
* @covers OpCacheGUI\Network\Request::getUrl |
123
|
|
|
*/ |
124
|
|
|
public function testGetUrlSslEnabled() |
125
|
|
|
{ |
126
|
|
|
$request = new Request([], [], ['HTTPS' => 'on', 'HTTP_HOST' => 'foo.com', 'REQUEST_URI' => '/bar']); |
127
|
|
|
|
128
|
|
|
$this->assertSame('https://foo.com/bar', $request->getUrl()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
133
|
|
|
* @covers OpCacheGUI\Network\Request::getUrl |
134
|
|
|
*/ |
135
|
|
|
public function testGetUrlSslDisabled() |
136
|
|
|
{ |
137
|
|
|
$request = new Request([], [], ['HTTP_HOST' => 'foo.com', 'REQUEST_URI' => '/bar']); |
138
|
|
|
|
139
|
|
|
$this->assertSame('http://foo.com/bar', $request->getUrl()); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
144
|
|
|
* @covers OpCacheGUI\Network\Request::getUrl |
145
|
|
|
*/ |
146
|
|
|
public function testGetUrlSslDisabledIIS() |
147
|
|
|
{ |
148
|
|
|
$request = new Request([], [], ['HTTPS' => 'off', 'HTTP_HOST' => 'foo.com', 'REQUEST_URI' => '/bar']); |
149
|
|
|
|
150
|
|
|
$this->assertSame('http://foo.com/bar', $request->getUrl()); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @covers OpCacheGUI\Network\Request::__construct |
155
|
|
|
* @covers OpCacheGUI\Network\Request::getIp |
156
|
|
|
*/ |
157
|
|
|
public function testGetIp() |
158
|
|
|
{ |
159
|
|
|
$request = new Request([], [], ['REQUEST_URI' => '/bar', 'REMOTE_ADDR' => '10.0.0.2']); |
160
|
|
|
|
161
|
|
|
$this->assertSame('10.0.0.2', $request->getIp()); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|