Completed
Push — master ( cbd317...231b94 )
by Henry
09:43
created

tests/phpunit/Head/ScriptTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Redaxscript\Tests\Head;
3
4
use org\bovigo\vfs\vfsStream as Stream;
5
use Redaxscript\Head;
6
use Redaxscript\Tests\TestCaseAbstract;
7
8
/**
9
 * ScriptTest
10
 *
11
 * @since 3.0.0
12
 *
13
 * @package Redaxscript
14
 * @category Tests
15
 * @author Henry Ruhs
16
 * @author Balázs Szilágyi
17
 *
18
 * @covers Redaxscript\Head\HeadAbstract
19
 * @covers Redaxscript\Head\Script
20
 */
21
22
class ScriptTest extends TestCaseAbstract
23
{
24
	/**
25
	 * setUp
26
	 *
27
	 * @since 3.0.0
28
	 */
29
30
	public function setUp()
31
	{
32
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR. 'provider' . DIRECTORY_SEPARATOR. 'Head' . DIRECTORY_SEPARATOR. 'ScriptTest_setUp.json'));
0 ignored issues
show
It seems like $this->getJSON('tests' ....ScriptTest_setUp.json') targeting Redaxscript\Tests\TestCaseAbstract::getJSON() can also be of type null; however, org\bovigo\vfs\vfsStream::setup() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
33
	}
34
35
	/**
36
	 * testAppend
37
	 *
38
	 * @since 3.0.0
39
	 *
40
	 * @param array $coreArray
41
	 * @param array $moduleArray
42
	 * @param string $expect
43
	 *
44
	 * @dataProvider providerAutoloader
45
	 */
46
47
	public function testAppend(array $coreArray = [], array $moduleArray = [], string $expect = null)
48
	{
49
		/* setup */
50
51
		$script = Head\Script::getInstance();
52
		$script->init('append');
53
54
		/* process core */
55
56
		foreach ($coreArray as $key => $value)
57
		{
58
			$script->append($value);
59
		}
60
61
		/* process module */
62
63
		foreach ($moduleArray as $key => $value)
64
		{
65
			$script->appendFile($value);
66
		}
67
68
		/* actual */
69
70
		$actual = $script;
71
72
		/* compare */
73
74
		$this->assertEquals($expect, $this->normalizeNewline($actual));
75
	}
76
77
	/**
78
	 * testPrepend
79
	 *
80
	 * @since 3.0.0
81
	 *
82
	 * @param array $coreArray
83
	 * @param array $moduleArray
84
	 * @param string $expect
85
	 *
86
	 * @dataProvider providerAutoloader
87
	 */
88
89
	public function testPrepend(array $coreArray = [], array $moduleArray = [], string $expect = null)
90
	{
91
		/* setup */
92
93
		$script = Head\Script::getInstance();
94
		$script->init('prepend');
95
96
		/* process core */
97
98
		foreach ($coreArray as $value)
99
		{
100
			$script->prepend($value);
101
		}
102
103
		/* process module */
104
105
		foreach ($moduleArray as $key => $value)
106
		{
107
			$script->prependFile($value);
108
		}
109
110
		/* actual */
111
112
		$actual = $script;
113
114
		/* compare */
115
116
		$this->assertEquals($expect, $this->normalizeNewline($actual));
117
	}
118
119
	/**
120
	 * testInline
121
	 *
122
	 * @since 3.0.0
123
	 *
124
	 * @param array $coreArray
125
	 * @param array $moduleArray
126
	 * @param string $expect
127
	 *
128
	 * @dataProvider providerAutoloader
129
	 */
130
131
	public function testInline(array $coreArray = [], array $moduleArray = [], string $expect = null)
132
	{
133
		/* setup */
134
135
		$script = Head\Script::getInstance();
136
		$script->init('inline');
137
138
		/* process core */
139
140
		foreach ($coreArray as $value)
141
		{
142
			$script->appendInline($value);
143
		}
144
145
		/* process module */
146
147
		foreach ($moduleArray as $value)
148
		{
149
			$script->prependInline($value);
150
		}
151
152
		/* actual */
153
154
		$actual = $script;
155
156
		/* compare */
157
158
		$this->assertEquals($expect, $actual);
159
	}
160
161
	/**
162
	 * testRemove
163
	 *
164
	 * @since 3.0.0
165
	 *
166
	 * @param array $coreArray
167
	 * @param string $deleteFile
168
	 * @param string $expect
169
	 *
170
	 * @dataProvider providerAutoloader
171
	 */
172
173
	public function testRemove(array $coreArray = [], string $deleteFile = null, string $expect = null)
174
	{
175
		/* setup */
176
177
		$script = Head\Script::getInstance();
178
		$script->init('remove');
179
180
		/* process core */
181
182
		foreach ($coreArray as $key => $value)
183
		{
184
			$script->append($value);
185
		}
186
		$script->removeFile($deleteFile);
187
188
		/* actual */
189
190
		$actual = $script;
191
192
		/* compare */
193
194
		$this->assertEquals($expect, $this->normalizeNewline($actual));
195
	}
196
197
	/**
198
	 * testTransportVar
199
	 *
200
	 * @since 3.0.0
201
	 *
202
	 * @param array $transportArray
203
	 * @param string $expect
204
	 *
205
	 * @dataProvider providerAutoloader
206
	 */
207
208
	public function testTransportVar(array $transportArray = [], string $expect = null)
209
	{
210
		/* setup */
211
212
		$script = Head\Script::getInstance();
213
		$script
214
			->init('transport')
215
			->transportVar($transportArray['key'], $transportArray['value']);
216
217
		/* actual */
218
219
		$actual = $script;
220
221
		/* compare */
222
223
		$this->assertEquals($expect, $actual);
224
	}
225
226
	/**
227
	 * testConcat
228
	 *
229
	 * @since 3.0.0
230
	 *
231
	 * @param array $concatArray
232
	 * @param string $expect
233
	 *
234
	 * @dataProvider providerAutoloader
235
	 */
236
237
	public function testConcat(array $concatArray = [], string $expect = null)
238
	{
239
		/* setup */
240
241
		$optionArray =
242
		[
243
			'directory' => Stream::url('root' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'scripts')
244
		];
245
		$script = Head\Script::getInstance();
246
		$script->init('concat');
247
248
		/* process concat */
249
250
		foreach ($concatArray as $key => $value)
251
		{
252
			$script->append($value);
253
		}
254
		$script
255
			->concat($optionArray)
256
			->concat($optionArray);
257
258
		/* actual */
259
260
		$actual = $script;
261
262
		/* compare */
263
264
		$this->assertEquals($expect, $this->normalizeNewline($actual));
265
	}
266
267
	/**
268
	 * testInvalid
269
	 *
270
	 * @since 3.0.0
271
	 */
272
273
	public function testInvalid()
274
	{
275
		/* setup */
276
277
		$script = Head\Script::getInstance();
278
		$script->init('invalid');
279
280
		/* actual */
281
282
		$actual = $script;
283
284
		/* compare */
285
286
		$this->assertEquals('<!-- Redaxscript\Head\Script\Invalid -->', $actual);
287
	}
288
}
289