LinkTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 234
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 1
dl 0
loc 234
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testAppend() 0 29 3
A testPrepend() 0 29 3
A testRemove() 0 23 2
A testConcat() 0 29 2
A testRewrite() 0 31 1
A testInvalid() 0 15 1
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
 * LinkTest
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\Link
20
 */
21
22
class LinkTest extends TestCaseAbstract
23
{
24
	/**
25
	 * setUp
26
	 *
27
	 * @since 3.0.0
28
	 */
29
30
	public function setUp() : void
31
	{
32
		Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR. 'unit-provider' . DIRECTORY_SEPARATOR. 'Head' . DIRECTORY_SEPARATOR. 'LinkTest_setUp.json'));
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) : void
48
	{
49
		/* setup */
50
51
		$link = Head\Link::getInstance();
52
		$link->init('append');
53
54
		/* process core */
55
56
		foreach ($coreArray as $key => $value)
57
		{
58
			$link->append($value);
59
		}
60
61
		/* process module */
62
63
		foreach ($moduleArray as $key => $value)
64
		{
65
			$link->appendFile($value);
66
		}
67
68
		/* actual */
69
70
		$actual = $link;
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) : void
90
	{
91
		/* setup */
92
93
		$link = Head\Link::getInstance();
94
		$link->init('prepend');
95
96
		/* process core */
97
98
		foreach ($coreArray as $value)
99
		{
100
			$link->prepend($value);
101
		}
102
103
		/* process module */
104
105
		foreach ($moduleArray as $key => $value)
106
		{
107
			$link->prependFile($value);
108
		}
109
110
		/* actual */
111
112
		$actual = $link;
113
114
		/* compare */
115
116
		$this->assertEquals($expect, $this->normalizeNewline($actual));
117
	}
118
119
	/**
120
	 * testRemove
121
	 *
122
	 * @since 3.0.0
123
	 *
124
	 * @param array $coreArray
125
	 * @param string $deleteFile
126
	 * @param string $expect
127
	 *
128
	 * @dataProvider providerAutoloader
129
	 */
130
131
	public function testRemove(array $coreArray = [], string $deleteFile = null, string $expect = null) : void
132
	{
133
		/* setup */
134
135
		$link = Head\Link::getInstance();
136
		$link->init('remove');
137
138
		/* process core */
139
140
		foreach ($coreArray as $key => $value)
141
		{
142
			$link->append($value);
143
		}
144
		$link->removeFile($deleteFile);
145
146
		/* actual */
147
148
		$actual = $link;
149
150
		/* compare */
151
152
		$this->assertEquals($expect, $this->normalizeNewline($actual));
153
	}
154
155
	/**
156
	 * testConcat
157
	 *
158
	 * @since 3.0.0
159
	 *
160
	 * @param array $concatArray
161
	 * @param string $expect
162
	 *
163
	 * @dataProvider providerAutoloader
164
	 */
165
166
	public function testConcat(array $concatArray = [], string $expect = null) : void
167
	{
168
		/* setup */
169
170
		$optionArray =
171
		[
172
			'directory' => Stream::url('root' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'styles')
173
		];
174
		$link = Head\Link::getInstance();
175
		$link->init('concat');
176
177
		/* process concat */
178
179
		foreach ($concatArray as $key => $value)
180
		{
181
			$link->append($value);
182
		}
183
		$link
184
			->concat($optionArray)
185
			->concat($optionArray);
186
187
		/* actual */
188
189
		$actual = $link;
190
191
		/* compare */
192
193
		$this->assertEquals($expect, $this->normalizeNewline($actual));
194
	}
195
196
	/**
197
	 * testRewrite
198
	 *
199
	 * @since 3.0.0
200
	 */
201
202
	public function testRewrite() : void
203
	{
204
		/* setup */
205
206
		$link = Head\Link::getInstance();
207
		$link
208
			->init('rewrite')
209
			->rewrite(
210
			[
211
				'rewrite-one' => 'rewrite-one',
212
				'rewrite-two' => 'rewrite-two'
213
			])
214
			->rewrite(
215
			[
216
				'rewrite-three' => 'rewrite-three'
217
			]);
218
219
		/* expect and actual */
220
221
		$expectArray =
222
		[
223
			'rewrite-one' => 'rewrite-one',
224
			'rewrite-two' => 'rewrite-two',
225
			'rewrite-three' => 'rewrite-three'
226
		];
227
		$actualArray = $this->getProperty($link, '_rewriteArray')['Redaxscript\Head\Link\Rewrite'];
228
229
		/* compare */
230
231
		$this->assertEquals($expectArray, $actualArray);
232
	}
233
234
	/**
235
	 * testInvalid
236
	 *
237
	 * @since 3.0.0
238
	 */
239
240
	public function testInvalid() : void
241
	{
242
		/* setup */
243
244
		$link = Head\Link::getInstance();
245
		$link->init('invalid');
246
247
		/* actual */
248
249
		$actual = $link;
250
251
		/* compare */
252
253
		$this->assertEquals('<!-- Redaxscript\Head\Link\Invalid -->', $actual);
254
	}
255
}
256