Completed
Push — master ( f37c71...d84366 )
by Henry
09:41
created

HeaderTest::testIsSent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Redaxscript\Tests;
3
4
use Redaxscript\Header;
5
6
/**
7
 * HeaderTest
8
 *
9
 * @since 3.3.0
10
 *
11
 * @package Redaxscript
12
 * @category Tests
13
 * @author Henry Ruhs
14
 *
15
 * @covers Redaxscript\Header
16
 */
17
18
class HeaderTest extends TestCaseAbstract
19
{
20
	/**
21
	 * testInit
22
	 *
23
	 * @since 3.3.0
24
	 *
25
	 * @runInSeparateProcess
26
	 */
27
28
	public function testInit() : void
29
	{
30
		/* setup */
31
32
		Header::init();
33
34
		/* expect and actual */
35
36
		$expectArray =
37
		[
38
			'X-Content-Type-Options: nosniff',
39
			'X-Frame-Options: sameorigin',
40
			'X-XSS-Protection: 1; mode=block'
41
		];
42
		$actualArray = $this->getHeaderArray();
43
44
		/* compare */
45
46
		$this->assertEquals($expectArray, $actualArray);
47
	}
48
49
	/**
50
	 * testGetArray
51
	 *
52
	 * @since 4.0.0
53
	 *
54
	 * @runInSeparateProcess
55
	 */
56
57
	public function testGetArray() : void
58
	{
59
		/* setup */
60
61
		Header::init();
62
63
		/* actual */
64
65
		$actualArray = Header::getArray();
66
67
		/* compare */
68
69
		$this->assertIsArray($actualArray);
70
	}
71
72
	/**
73
	 * testAdd
74
	 *
75
	 * @since 3.3.0
76
	 *
77
	 * @runInSeparateProcess
78
	 */
79
80
	public function testAdd() : void
81
	{
82
		/* setup */
83
84
		Header::add('X-One: One');
85
		Header::add(
86
		[
87
			'X-Two: Two',
88
			'X-Three: Three'
89
		]);
90
91
		/* expect and actual */
92
93
		$expectArray =
94
		[
95
			'X-One: One',
96
			'X-Two: Two',
97
			'X-Three: Three'
98
		];
99
		$actualArray = $this->getHeaderArray();
100
101
		/* compare */
102
103
		$this->assertEquals($expectArray, $actualArray);
104
	}
105
106
	/**
107
	 * testAddInvalid
108
	 *
109
	 * @since 3.3.0
110
	 */
111
112
	public function testAddInvalid() : void
113
	{
114
		/* actual */
115
116
		$actual = Header::add();
117
118
		/* compare */
119
120
		$this->assertFalse($actual);
121
	}
122
123
	/**
124
	 * testRemoveInvalid
125
	 *
126
	 * @since 3.3.0
127
	 *
128
	 */
129
130
	public function testRemoveInvalid() : void
131
	{
132
		/* actual */
133
134
		$actual = Header::remove();
135
136
		/* compare */
137
138
		$this->assertFalse($actual);
139
	}
140
141
	/**
142
	 * testIsSent
143
	 *
144
	 * @since 4.0.0
145
	 *
146
	 * @runInSeparateProcess
147
	 */
148
149
	public function testIsSent() : void
150
	{
151
		/* actual */
152
153
		$actual = Header::isSent();
154
155
		/* compare */
156
157
		$this->assertIsBool($actual);
158
	}
159
160
	/**
161
	 * testResponseCode
162
	 *
163
	 * @since 4.0.0
164
	 *
165
	 * @runInSeparateProcess
166
	 */
167
168
	public function testResponseCode() : void
169
	{
170
		/* actual */
171
172
		$actual = Header::responseCode(404);
173
174
		/* compare */
175
176
		$this->assertIsInt($actual);
177
	}
178
179
	/**
180
	 * testDoRedirect
181
	 *
182
	 * @since 3.3.0
183
	 *
184
	 * @runInSeparateProcess
185
	 */
186
187
	public function testDoRedirect() : void
188
	{
189
		/* setup */
190
191
		Header::doRedirect('install.php');
192
193
		/* expect and actual */
194
195
		$expectArray =
196
		[
197
			'Location: install.php'
198
		];
199
		$actualArray = $this->getHeaderArray();
200
201
		/* compare */
202
203
		$this->assertEquals($expectArray, $actualArray);
204
	}
205
206
	/**
207
	 * testContentType
208
	 *
209
	 * @since 3.3.0
210
	 *
211
	 * @runInSeparateProcess
212
	 */
213
214
	public function testContentType() : void
215
	{
216
		/* setup */
217
218
		Header::contentType('application/json');
219
220
		/* expect and actual */
221
222
		$expectArray =
223
		[
224
			'Content-Type: application/json'
225
		];
226
		$actualArray = $this->getHeaderArray();
227
228
		/* compare */
229
230
		$this->assertEquals($expectArray, $actualArray);
231
	}
232
}
233