Completed
Push — master ( 432a29...e6b984 )
by Henry
06:52
created

CommonTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Redaxscript\Tests\Bootstrap;
3
4
use Redaxscript\Bootstrap;
5
use Redaxscript\Tests\TestCaseAbstract;
6
use function putenv;
7
8
/**
9
 * CommonTest
10
 *
11
 * @since 3.1.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 *
17
 * @covers Redaxscript\Bootstrap\Common
18
 * @covers Redaxscript\Bootstrap\BootstrapAbstract
19
 *
20
 * @runTestsInSeparateProcesses
21
 */
22
23
class CommonTest extends TestCaseAbstract
24
{
25
	/**
26
	 * setUp
27
	 *
28
	 * @since 5.0.0
29
	 */
30
31
	public function setUp() : void
32
	{
33
		parent::setUp();
34
		$this->_request->init();
35
	}
36
37
	/**
38
	 * testServer
39
	 *
40
	 * @since 3.2.3
41
	 *
42
	 * @param string $userAgent
43
	 * @param array $expectArray
44
	 *
45
	 * @dataProvider providerAutoloader
46
	 */
47
48
	public function testServer(string $userAgent = null, array $expectArray = []) : void
49
	{
50
		/* setup */
51
52
		$this->_request->set('server',
53
		[
54
			'HTTP_HOST' => 'localhost',
55
			'HTTP_USER_AGENT' => $userAgent,
56
			'REMOTE_ADDR' => 'localhost',
57
			'SCRIPT_NAME' => '/redaxscript/index.php'
58
		]);
59
		new Bootstrap\Common($this->_registry, $this->_request);
60
61
		/* actual */
62
63
		$actualArray =
64
		[
65
			'file' => $this->_registry->get('file'),
66
			'root' => $this->_registry->get('root'),
67
			'host' => $this->_registry->get('host'),
68
			'token' => $this->_registry->get('token')
69
		];
70
71
		/* compare */
72
73
		$this->assertEquals($expectArray, $actualArray);
74
	}
75
76
	/**
77
	 * testClient
78
	 *
79
	 * @since 3.2.3
80
	 *
81
	 * @param string $userAgent
82
	 * @param array $expectArray
83
	 *
84
	 * @dataProvider providerAutoloader
85
	 */
86
87
	public function testClient(string $userAgent = null, array $expectArray = []) : void
88
	{
89
		/* setup */
90
91
		$this->_request->setServer('HTTP_USER_AGENT', $userAgent);
92
		new Bootstrap\Common($this->_registry, $this->_request);
93
94
		/* actual */
95
96
		$actualArray =
97
		[
98
			'myBrowser' => $this->_registry->get('myBrowser'),
99
			'myBrowserVersion' => $this->_registry->get('myBrowserVersion'),
100
			'myEngine' => $this->_registry->get('myEngine'),
101
			'myMobile' => $this->_registry->get('myMobile'),
102
			'myTablet' => $this->_registry->get('myTablet'),
103
			'myDesktop' => $this->_registry->get('myDesktop')
104
		];
105
106
		/* compare */
107
108
		$this->assertEquals($expectArray, $actualArray);
109
	}
110
111
	/**
112
	 * testDriver
113
	 *
114
	 * @since 3.2.3
115
	 */
116
117
	public function testDriver() : void
118
	{
119
		/* setup */
120
121
		new Bootstrap\Common($this->_registry, $this->_request);
122
123
		/* actual */
124
125
		$actualArray = $this->_registry->get('driverArray');
126
127
		/* compare */
128
129
		$this->assertNotNull($actualArray);
130
	}
131
132
	/**
133
	 * testModule
134
	 *
135
	 * @since 3.2.3
136
	 */
137
138
	public function testModule() : void
139
	{
140
		/* setup */
141
142
		putenv('REDIRECT_MOD_BROTLI=on');
143
		putenv('REDIRECT_MOD_DEFLATE=on');
144
		putenv('REDIRECT_MOD_SECURITY=on');
145
		putenv('REDIRECT_MOD_REWRITE=on');
146
		putenv('REDIRECT_MOD_HEADERS=on');
147
		new Bootstrap\Common($this->_registry, $this->_request);
148
149
		/* expect and actual */
150
151
		$expectArray =
152
		[
153
			'mod_brotli' => true,
154
			'mod_deflate' => true,
155
			'mod_security' => true,
156
			'mod_rewrite' => true,
157
			'mod_headers' => true
158
		];
159
		$actualArray = $this->_registry->get('moduleArray');
160
161
		/* compare */
162
163
		$this->assertEquals($expectArray, $actualArray);
164
	}
165
166
	/**
167
	 * testPhp
168
	 *
169
	 * @since 3.2.3
170
	 */
171
172
	public function testPhp() : void
173
	{
174
		/* setup */
175
176
		new Bootstrap\Common($this->_registry, $this->_request);
177
178
		/* actual */
179
180
		$actualArray =
181
		[
182
			'phpOs' => $this->_registry->get('phpOs'),
183
			'phpVersion' => $this->_registry->get('phpVersion'),
184
			'phpStatus' => $this->_registry->get('phpStatus')
185
		];
186
187
		/* compare */
188
189
		$this->assertIsString($actualArray['phpOs']);
190
		$this->assertIsString($actualArray['phpVersion']);
191
		$this->assertIsNumeric($actualArray['phpStatus']);
192
	}
193
}
194