|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Yosymfony\Spress. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) YoSymfony <http://github.com/yosymfony> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Yosymfony\Spress\Core\Tests\DataSource\Filesystem; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
|
16
|
|
|
use Yosymfony\Spress\Core\DataSource\Filesystem\FilesystemDataSource; |
|
17
|
|
|
use Yosymfony\Spress\Core\DataSource\ItemInterface; |
|
18
|
|
|
|
|
19
|
|
|
class FilesystemDataSourceTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
protected $sourcePath; |
|
22
|
16 |
|
protected $extraPagesPath; |
|
23
|
|
|
protected $textExtensions; |
|
24
|
16 |
|
|
|
25
|
16 |
|
public function setUp() |
|
26
|
16 |
|
{ |
|
27
|
16 |
|
$this->sourcePath = sys_get_temp_dir().'/spress-tests'; |
|
28
|
|
|
|
|
29
|
1 |
|
$fs = new FileSystem(); |
|
30
|
|
|
$fs->mirror(__dir__.'/../../fixtures/project/src', $this->sourcePath); |
|
31
|
1 |
|
|
|
32
|
1 |
|
$this->extraPagesPath = __dir__.'/../../fixtures/extra_pages'; |
|
33
|
1 |
|
$this->textExtensions = ['htm', 'html', 'html.twig', 'twig,html', 'js', 'less', 'markdown', 'md', 'mkd', 'mkdn', 'coffee', 'css', 'erb', 'haml', 'handlebars', 'hb', 'ms', 'mustache', 'php', 'rb', 'sass', 'scss', 'slim', 'txt', 'xhtml', 'xml']; |
|
34
|
1 |
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
public function tearDown() |
|
37
|
|
|
{ |
|
38
|
1 |
|
$fs = new FileSystem(); |
|
39
|
1 |
|
$fs->remove($this->sourcePath); |
|
40
|
1 |
|
} |
|
41
|
|
|
|
|
42
|
1 |
|
public function testProcessItems() |
|
43
|
1 |
|
{ |
|
44
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
45
|
|
|
'source_root' => $this->sourcePath, |
|
46
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
47
|
1 |
|
]); |
|
48
|
1 |
|
|
|
49
|
|
|
$fsDataSource->load(); |
|
50
|
1 |
|
|
|
51
|
1 |
|
$items = $fsDataSource->getItems(); |
|
52
|
1 |
|
$layouts = $fsDataSource->getLayouts(); |
|
|
|
|
|
|
53
|
1 |
|
$includes = $fsDataSource->getIncludes(); |
|
|
|
|
|
|
54
|
1 |
|
|
|
55
|
1 |
|
$itemAttributes = $items['about/index.html']->getAttributes(); |
|
56
|
1 |
|
$this->assertCount(4, $itemAttributes); |
|
57
|
1 |
|
$this->assertEquals('default', $itemAttributes['layout']); |
|
58
|
1 |
|
|
|
59
|
1 |
|
$itemAttributes = $items['posts/2016-02-02-spress-2.1.1-released.md']->getAttributes(); |
|
60
|
1 |
|
$this->assertArrayHasKey('title_path', $itemAttributes); |
|
61
|
1 |
|
$this->assertEquals('spress-2.1.1-released', $itemAttributes['title_path']); |
|
62
|
1 |
|
|
|
63
|
|
|
$itemAttributes = $items['posts/2013-08-12-post-example-1.md']->getAttributes(); |
|
64
|
1 |
|
$this->assertCount(10, $itemAttributes); |
|
65
|
1 |
|
$this->assertArrayNotHasKey('meta_filename', $itemAttributes); |
|
66
|
1 |
|
$this->assertStringStartsWith('Post example 1', $items['posts/2013-08-12-post-example-1.md']->getContent()); |
|
67
|
|
|
|
|
68
|
1 |
|
$itemAttributes = $items['posts/books/2013-08-11-best-book.md']->getAttributes(); |
|
69
|
1 |
|
$this->assertArrayHasKey('categories', $itemAttributes); |
|
70
|
1 |
|
$this->assertCount(1, $itemAttributes['categories']); |
|
71
|
|
|
|
|
72
|
1 |
|
$itemAttributes = $items['posts/2013-08-12-post-example-2.mkd']->getAttributes(); |
|
73
|
1 |
|
$this->assertArrayHasKey('title', $itemAttributes); |
|
74
|
1 |
|
$this->assertArrayHasKey('title_path', $itemAttributes); |
|
75
|
1 |
|
$this->assertArrayHasKey('date', $itemAttributes); |
|
76
|
|
|
$this->assertEquals('post example 2', $itemAttributes['title']); |
|
77
|
1 |
|
$this->assertEquals('2013-08-12', $itemAttributes['date']); |
|
78
|
1 |
|
|
|
79
|
1 |
|
$itemAttributes = $items['sitemap.xml']->getAttributes(); |
|
80
|
|
|
$this->assertEquals('sitemap', $itemAttributes['name']); |
|
81
|
1 |
|
} |
|
82
|
1 |
|
|
|
83
|
1 |
|
public function testGetItemsMustReturnTheItemsOfASite() |
|
84
|
1 |
|
{ |
|
85
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
86
|
1 |
|
'source_root' => $this->sourcePath, |
|
87
|
|
|
'text_extensions' => $this->textExtensions, |
|
88
|
1 |
|
]); |
|
89
|
1 |
|
|
|
90
|
|
|
$fsDataSource->load(); |
|
91
|
1 |
|
$items = $fsDataSource->getItems(); |
|
92
|
|
|
|
|
93
|
1 |
|
$this->assertCount(15, $items); |
|
94
|
|
|
$this->assertArrayHasKey('index.html', $items); |
|
95
|
1 |
|
$this->assertArrayHasKey('LICENSE', $items); |
|
96
|
|
|
$this->assertArrayHasKey('about/index.html', $items); |
|
97
|
1 |
|
$this->assertArrayHasKey('about/me/index.html', $items); |
|
98
|
1 |
|
$this->assertArrayHasKey('pages/index.html', $items); |
|
99
|
|
|
$this->assertArrayHasKey('projects/index.md', $items); |
|
100
|
1 |
|
$this->assertArrayHasKey('robots.txt', $items); |
|
101
|
|
|
$this->assertArrayHasKey('sitemap.xml', $items); |
|
102
|
1 |
|
$this->assertArrayHasKey('posts/2013-08-12-post-example-1.md', $items); |
|
103
|
1 |
|
$this->assertArrayHasKey('posts/2013-08-12-post-example-2.mkd', $items); |
|
104
|
|
|
$this->assertArrayHasKey('posts/2016-02-02-spress-2.1.1-released.md', $items); |
|
105
|
1 |
|
$this->assertArrayHasKey('posts/books/2013-08-11-best-book.md', $items); |
|
106
|
1 |
|
$this->assertArrayHasKey('posts/books/2013-09-19-new-book.md', $items); |
|
107
|
1 |
|
$this->assertArrayHasKey('assets/style.css', $items); |
|
108
|
1 |
|
$this->assertArrayHasKey('.htaccess', $items); |
|
109
|
|
|
} |
|
110
|
1 |
|
|
|
111
|
|
View Code Duplication |
public function testGetLayoutsMustReturnTheLayoutsOfASite() |
|
|
|
|
|
|
112
|
1 |
|
{ |
|
113
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
114
|
1 |
|
'source_root' => $this->sourcePath, |
|
115
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
116
|
1 |
|
]); |
|
117
|
|
|
|
|
118
|
1 |
|
$fsDataSource->load(); |
|
119
|
1 |
|
$layouts = $fsDataSource->getLayouts(); |
|
120
|
|
|
|
|
121
|
1 |
|
$this->assertCount(1, $layouts); |
|
122
|
1 |
|
$this->assertArrayHasKey('default.html', $layouts); |
|
123
|
1 |
|
} |
|
124
|
|
|
|
|
125
|
1 |
View Code Duplication |
public function testGetIncludesMustReturnTheLayoutsOfASite() |
|
|
|
|
|
|
126
|
|
|
{ |
|
127
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
128
|
1 |
|
'source_root' => $this->sourcePath, |
|
129
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
130
|
1 |
|
]); |
|
131
|
1 |
|
|
|
132
|
|
|
$fsDataSource->load(); |
|
133
|
1 |
|
$includes = $fsDataSource->getIncludes(); |
|
134
|
1 |
|
|
|
135
|
|
|
$this->assertCount(1, $includes); |
|
136
|
1 |
|
$this->assertArrayHasKey('test.html', $includes); |
|
137
|
1 |
|
} |
|
138
|
1 |
|
|
|
139
|
|
View Code Duplication |
public function testGetLayoutsMustReturnsAnArrayOfItemInterface() |
|
|
|
|
|
|
140
|
1 |
|
{ |
|
141
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
142
|
1 |
|
'source_root' => $this->sourcePath, |
|
143
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
144
|
1 |
|
]); |
|
145
|
1 |
|
|
|
146
|
1 |
|
$fsDataSource->load(); |
|
147
|
|
|
$layouts = $fsDataSource->getLayouts(); |
|
148
|
1 |
|
|
|
149
|
1 |
|
$this->assertTrue(is_array($layouts), 'getLayouts must return an array'); |
|
150
|
|
|
$this->assertContainsOnlyInstancesOf( |
|
151
|
1 |
|
ItemInterface::class, |
|
152
|
1 |
|
$layouts, |
|
153
|
1 |
|
'getLayouts can only returns elements of ItemInterface type' |
|
154
|
|
|
); |
|
155
|
1 |
|
} |
|
156
|
|
|
|
|
157
|
1 |
View Code Duplication |
public function testGetIncludesMustReturnsAnArrayOfItemInterface() |
|
|
|
|
|
|
158
|
1 |
|
{ |
|
159
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
160
|
1 |
|
'source_root' => $this->sourcePath, |
|
161
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
162
|
|
|
]); |
|
163
|
1 |
|
|
|
164
|
1 |
|
$fsDataSource->load(); |
|
165
|
|
|
$includes = $fsDataSource->getIncludes(); |
|
166
|
1 |
|
|
|
167
|
1 |
|
$this->assertTrue(is_array($includes), 'getIncludes must return an array'); |
|
168
|
1 |
|
$this->assertContainsOnlyInstancesOf( |
|
169
|
|
|
ItemInterface::class, |
|
170
|
1 |
|
$includes, |
|
171
|
|
|
'getIncludes can only returns elements of ItemInterface type' |
|
172
|
1 |
|
); |
|
173
|
1 |
|
} |
|
174
|
1 |
|
|
|
175
|
1 |
View Code Duplication |
public function testGetItemsMustReturnsAnArrayOfItemInterface() |
|
|
|
|
|
|
176
|
1 |
|
{ |
|
177
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
178
|
1 |
|
'source_root' => $this->sourcePath, |
|
179
|
|
|
'text_extensions' => $this->textExtensions, |
|
180
|
1 |
|
]); |
|
181
|
1 |
|
|
|
182
|
1 |
|
$fsDataSource->load(); |
|
183
|
|
|
$items = $fsDataSource->getItems(); |
|
184
|
1 |
|
|
|
185
|
|
|
$this->assertTrue(is_array($items), 'getItems must return an array'); |
|
186
|
1 |
|
$this->assertContainsOnlyInstancesOf( |
|
187
|
1 |
|
ItemInterface::class, |
|
188
|
1 |
|
$items, |
|
189
|
1 |
|
'getItems can only returns elements of ItemInterface type' |
|
190
|
1 |
|
); |
|
191
|
1 |
|
} |
|
192
|
|
|
|
|
193
|
1 |
View Code Duplication |
public function testGetTypeOfAnIncludeItemMustBeInclude() |
|
|
|
|
|
|
194
|
1 |
|
{ |
|
195
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
196
|
1 |
|
'source_root' => $this->sourcePath, |
|
197
|
|
|
'text_extensions' => $this->textExtensions, |
|
198
|
1 |
|
]); |
|
199
|
1 |
|
|
|
200
|
1 |
|
$fsDataSource->load(); |
|
201
|
1 |
|
$includes = $fsDataSource->getIncludes(); |
|
202
|
1 |
|
|
|
203
|
1 |
|
$this->assertEquals( |
|
204
|
|
|
'include', |
|
205
|
1 |
|
$includes['test.html']->getType(), |
|
206
|
1 |
|
'The type of an include item must be "include"' |
|
207
|
|
|
); |
|
208
|
1 |
|
} |
|
209
|
|
|
|
|
210
|
1 |
View Code Duplication |
public function testGetContentOfAnIncludeItemMustBeRight() |
|
|
|
|
|
|
211
|
1 |
|
{ |
|
212
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
213
|
1 |
|
'source_root' => $this->sourcePath, |
|
214
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
215
|
1 |
|
]); |
|
216
|
|
|
|
|
217
|
1 |
|
$fsDataSource->load(); |
|
218
|
1 |
|
$includes = $fsDataSource->getIncludes(); |
|
219
|
|
|
|
|
220
|
1 |
|
$this->assertRegExp( |
|
221
|
|
|
'/Include test/', |
|
222
|
1 |
|
$includes['test.html']->getContent(), |
|
223
|
1 |
|
'The content of the include item must contains the text "Include test"' |
|
224
|
1 |
|
); |
|
225
|
1 |
|
} |
|
226
|
1 |
|
|
|
227
|
|
View Code Duplication |
public function testGetTypeOfAnLayoutItemMustBeLayout() |
|
|
|
|
|
|
228
|
1 |
|
{ |
|
229
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
230
|
1 |
|
'source_root' => $this->sourcePath, |
|
231
|
|
|
'text_extensions' => $this->textExtensions, |
|
232
|
1 |
|
]); |
|
233
|
|
|
|
|
234
|
1 |
|
$fsDataSource->load(); |
|
235
|
1 |
|
$layouts = $fsDataSource->getLayouts(); |
|
236
|
|
|
|
|
237
|
1 |
|
$this->assertEquals( |
|
238
|
1 |
|
'layout', |
|
239
|
1 |
|
$layouts['default.html']->getType(), |
|
240
|
|
|
'The type of a layout item must be "layout"' |
|
241
|
1 |
|
); |
|
242
|
|
|
} |
|
243
|
1 |
|
|
|
244
|
1 |
View Code Duplication |
public function testGetContentOfALayoutItemMustBeRight() |
|
|
|
|
|
|
245
|
1 |
|
{ |
|
246
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
247
|
1 |
|
'source_root' => $this->sourcePath, |
|
248
|
|
|
'text_extensions' => $this->textExtensions, |
|
249
|
1 |
|
]); |
|
250
|
|
|
|
|
251
|
1 |
|
$fsDataSource->load(); |
|
252
|
|
|
$layouts = $fsDataSource->getLayouts(); |
|
253
|
1 |
|
|
|
254
|
|
|
$this->assertRegExp( |
|
255
|
1 |
|
'/Welcome to my site/', |
|
256
|
1 |
|
$layouts['default.html']->getContent(), |
|
257
|
|
|
'The content of the layout item must contains the text "Welcome to my site"' |
|
258
|
1 |
|
); |
|
259
|
1 |
|
} |
|
260
|
1 |
|
|
|
261
|
|
View Code Duplication |
public function testGetBinaryOfAnItemMustReturnTrueIfThereIsNotFilenameExtension() |
|
|
|
|
|
|
262
|
|
|
{ |
|
263
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
264
|
|
|
'source_root' => $this->sourcePath, |
|
265
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
266
|
|
|
]); |
|
267
|
1 |
|
|
|
268
|
1 |
|
$fsDataSource->load(); |
|
269
|
|
|
$items = $fsDataSource->getItems(); |
|
270
|
|
|
|
|
271
|
|
|
$this->assertTrue( |
|
272
|
|
|
$items['LICENSE']->isBinary(), |
|
273
|
|
|
'An item without a filename extension must be treated as a binary item' |
|
274
|
1 |
|
); |
|
275
|
|
|
} |
|
276
|
1 |
|
|
|
277
|
1 |
View Code Duplication |
public function testGetBinaryOfAnItemMustReturnFalseIfTheFilenameExtensionBelongsToTextExtensions() |
|
|
|
|
|
|
278
|
1 |
|
{ |
|
279
|
1 |
|
$fsDataSource = new FilesystemDataSource([ |
|
280
|
|
|
'source_root' => $this->sourcePath, |
|
281
|
|
|
'text_extensions' => $this->textExtensions, |
|
282
|
|
|
]); |
|
283
|
|
|
|
|
284
|
|
|
$fsDataSource->load(); |
|
285
|
1 |
|
$items = $fsDataSource->getItems(); |
|
286
|
|
|
|
|
287
|
1 |
|
$this->assertFalse( |
|
288
|
1 |
|
$items['posts/2013-08-12-post-example-1.md']->isBinary(), |
|
289
|
1 |
|
'An item with a filename extension included in the text extension list must be treated as a text item' |
|
290
|
1 |
|
); |
|
291
|
1 |
|
} |
|
292
|
|
|
|
|
293
|
|
|
public function testGetBinaryOfAnItemMustReturnTrueIfTheFilenameExtensionDoesNotBelongsToTextExtensions() |
|
294
|
|
|
{ |
|
295
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
296
|
|
|
'source_root' => $this->sourcePath, |
|
297
|
1 |
|
'text_extensions' => ['html'], |
|
298
|
|
|
]); |
|
299
|
1 |
|
|
|
300
|
1 |
|
$fsDataSource->load(); |
|
301
|
1 |
|
$items = $fsDataSource->getItems(); |
|
302
|
1 |
|
|
|
303
|
1 |
|
$this->assertTrue( |
|
304
|
1 |
|
$items['posts/2013-08-12-post-example-1.md']->isBinary(), |
|
305
|
|
|
'An item with a filename extension not included in the text extension list must be treated as a binary item' |
|
306
|
|
|
); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
View Code Duplication |
public function testGetPathOfABinaryItemMustHasSourceAndRelativePaths() |
|
|
|
|
|
|
310
|
1 |
|
{ |
|
311
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
312
|
1 |
|
'source_root' => $this->sourcePath, |
|
313
|
1 |
|
'text_extensions' => $this->textExtensions, |
|
314
|
1 |
|
]); |
|
315
|
1 |
|
|
|
316
|
1 |
|
$fsDataSource->load(); |
|
317
|
1 |
|
$items = $fsDataSource->getItems(); |
|
318
|
|
|
$item = $items['LICENSE']; |
|
319
|
|
|
|
|
320
|
|
|
$this->assertTrue( |
|
321
|
|
|
strlen($item->getPath('source')) > 0, |
|
322
|
|
|
'A binary item must have a source path' |
|
323
|
|
|
); |
|
324
|
|
|
$this->assertTrue( |
|
325
|
|
|
strlen($item->getPath('relative')) > 0, |
|
326
|
|
|
'A binary item must have a relative path' |
|
327
|
|
|
); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
View Code Duplication |
public function testGetPathOfATextItemMustHasOnlyARelativePaths() |
|
|
|
|
|
|
331
|
|
|
{ |
|
332
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
333
|
|
|
'source_root' => $this->sourcePath, |
|
334
|
|
|
'text_extensions' => $this->textExtensions, |
|
335
|
|
|
]); |
|
336
|
|
|
|
|
337
|
|
|
$fsDataSource->load(); |
|
338
|
|
|
$items = $fsDataSource->getItems(); |
|
339
|
|
|
$item = $items['index.html']; |
|
340
|
|
|
|
|
341
|
|
|
$this->assertTrue( |
|
342
|
|
|
strlen($item->getPath('relative')) > 0, |
|
343
|
|
|
'A text item must have a relative path' |
|
344
|
|
|
); |
|
345
|
|
|
$this->assertFalse( |
|
346
|
|
|
strlen($item->getPath('source')) > 0, |
|
347
|
|
|
'A text item must not have a source path' |
|
348
|
|
|
); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
public function testGetAttributesMustReturnsTheBasicAttributes() |
|
352
|
|
|
{ |
|
353
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
354
|
|
|
'source_root' => $this->sourcePath, |
|
355
|
|
|
'text_extensions' => $this->textExtensions, |
|
356
|
|
|
]); |
|
357
|
|
|
|
|
358
|
|
|
$fsDataSource->load(); |
|
359
|
|
|
$items = $fsDataSource->getItems(); |
|
360
|
|
|
$item = $items['index.html']; |
|
361
|
|
|
$itemAttributes = $item->getAttributes(); |
|
362
|
|
|
|
|
363
|
|
|
$this->assertArrayHasKey('mtime', $itemAttributes); |
|
364
|
|
|
$this->assertArrayHasKey('filename', $itemAttributes); |
|
365
|
|
|
$this->assertArrayHasKey('extension', $itemAttributes); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
View Code Duplication |
public function testGetLayoutsMustGivesPreferenceSiteLayoutsOverThemeLayoutsWhenThereIsAEnabledTheme() |
|
|
|
|
|
|
369
|
|
|
{ |
|
370
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
371
|
|
|
'source_root' => $this->sourcePath, |
|
372
|
|
|
'text_extensions' => $this->textExtensions, |
|
373
|
|
|
'theme_name' => 'theme01', |
|
374
|
|
|
]); |
|
375
|
|
|
|
|
376
|
|
|
$fsDataSource->load(); |
|
377
|
|
|
$layouts = $fsDataSource->getLayouts(); |
|
378
|
|
|
|
|
379
|
|
|
$this->assertCount(2, $layouts); |
|
380
|
|
|
$this->assertRegExp('/Welcome to my site/', $layouts['default.html']->getContent()); |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
View Code Duplication |
public function testGetIncludesMustGivesPreferenceSiteIncludesOverThemeIncludesWhenThereIsAEnabledTheme() |
|
|
|
|
|
|
384
|
|
|
{ |
|
385
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
386
|
|
|
'source_root' => $this->sourcePath, |
|
387
|
|
|
'text_extensions' => $this->textExtensions, |
|
388
|
|
|
'theme_name' => 'theme01', |
|
389
|
|
|
]); |
|
390
|
|
|
|
|
391
|
|
|
$fsDataSource->load(); |
|
392
|
|
|
$includes = $fsDataSource->getIncludes(); |
|
393
|
|
|
|
|
394
|
|
|
$this->assertCount(2, $includes); |
|
395
|
|
|
$this->assertRegExp('/Include test/', $includes['test.html']->getContent()); |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
View Code Duplication |
public function testGetItemsMustGivesPreferenceSiteAssetsOverThemeAssetsWhenThereIsAEnabledTheme() |
|
|
|
|
|
|
399
|
|
|
{ |
|
400
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
401
|
|
|
'source_root' => $this->sourcePath, |
|
402
|
|
|
'text_extensions' => $this->textExtensions, |
|
403
|
|
|
'theme_name' => 'theme01', |
|
404
|
|
|
]); |
|
405
|
|
|
|
|
406
|
|
|
$fsDataSource->load(); |
|
407
|
|
|
$items = $fsDataSource->getItems(); |
|
408
|
|
|
$this->assertRegExp('/styles of the site/', $items['assets/style.css']->getContent()); |
|
409
|
|
|
} |
|
410
|
|
|
|
|
411
|
|
|
public function testGetItemsMustReturnThemeAssetsIfItDoesNotExistsInTheSiteAssetsWhenThereIsAEnabledTheme() |
|
412
|
|
|
{ |
|
413
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
414
|
|
|
'source_root' => $this->sourcePath, |
|
415
|
|
|
'text_extensions' => $this->textExtensions, |
|
416
|
|
|
'theme_name' => 'theme01', |
|
417
|
|
|
]); |
|
418
|
|
|
|
|
419
|
|
|
$fsDataSource->load(); |
|
420
|
|
|
$items = $fsDataSource->getItems(); |
|
421
|
|
|
|
|
422
|
|
|
$this->assertArrayHasKey('assets/extra.css', $items); |
|
423
|
|
|
$this->assertRegExp('/extra styles of the theme/', $items['assets/extra.css']->getContent()); |
|
424
|
|
|
} |
|
425
|
|
|
|
|
426
|
|
View Code Duplication |
public function testGetIncludesMustReturnThemeIncludesIfItDoesNotExistsInTheSiteIncludesWhenThereIsAEnabledTheme() |
|
|
|
|
|
|
427
|
|
|
{ |
|
428
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
429
|
|
|
'source_root' => $this->sourcePath, |
|
430
|
|
|
'text_extensions' => $this->textExtensions, |
|
431
|
|
|
'theme_name' => 'theme01', |
|
432
|
|
|
]); |
|
433
|
|
|
|
|
434
|
|
|
$fsDataSource->load(); |
|
435
|
|
|
$includes = $fsDataSource->getIncludes(); |
|
436
|
|
|
|
|
437
|
|
|
$this->assertCount(2, $includes); |
|
438
|
|
|
$this->assertRegExp('/Include theme 01 - test2/', $includes['test2.html']->getContent()); |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
View Code Duplication |
public function testGetLayoutsMustReturnThemeLayoutsIfItDoesNotExistsInTheSiteLayoutsWhenThereIsAEnabledTheme() |
|
|
|
|
|
|
442
|
|
|
{ |
|
443
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
444
|
|
|
'source_root' => $this->sourcePath, |
|
445
|
|
|
'text_extensions' => $this->textExtensions, |
|
446
|
|
|
'theme_name' => 'theme01', |
|
447
|
|
|
]); |
|
448
|
|
|
|
|
449
|
|
|
$fsDataSource->load(); |
|
450
|
|
|
$layouts = $fsDataSource->getLayouts(); |
|
451
|
|
|
|
|
452
|
|
|
$this->assertCount(2, $layouts); |
|
453
|
|
|
$this->assertRegExp('/Theme 01 layout/', $layouts['page.html']->getContent()); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
View Code Duplication |
public function testGetItemsMustReturnAnExtraItemWhenIncludeOptionIsSetWithAFile() |
|
|
|
|
|
|
457
|
|
|
{ |
|
458
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
459
|
|
|
'source_root' => $this->sourcePath, |
|
460
|
|
|
'include' => [$this->extraPagesPath.'/extra-page1.html'], |
|
461
|
|
|
'text_extensions' => $this->textExtensions, |
|
462
|
|
|
]); |
|
463
|
|
|
$fsDataSource->load(); |
|
464
|
|
|
$items = $fsDataSource->getItems(); |
|
465
|
|
|
|
|
466
|
|
|
$this->assertCount(16, $items); |
|
467
|
|
|
$this->assertArrayHasKey('extra-page1.html', $items); |
|
468
|
|
|
} |
|
469
|
|
|
|
|
470
|
|
View Code Duplication |
public function testGetItemsMustReturnDotItemsWhenThereAreDotFiles() |
|
|
|
|
|
|
471
|
|
|
{ |
|
472
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
473
|
|
|
'source_root' => $this->sourcePath, |
|
474
|
|
|
'text_extensions' => $this->textExtensions, |
|
475
|
|
|
]); |
|
476
|
|
|
$fsDataSource->load(); |
|
477
|
|
|
$items = $fsDataSource->getItems(); |
|
478
|
|
|
|
|
479
|
|
|
$this->assertArrayHasKey('.htaccess', $items); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
public function testGetItemsMustNotReturnItemsInVCSFolders() |
|
483
|
|
|
{ |
|
484
|
|
|
$gitDir = $this->sourcePath.'/.git'; |
|
485
|
|
|
$fs = new FileSystem(); |
|
486
|
|
|
$fs->dumpFile($gitDir.'/HEAD', ''); |
|
487
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
488
|
|
|
'source_root' => $this->sourcePath, |
|
489
|
|
|
'text_extensions' => $this->textExtensions, |
|
490
|
|
|
]); |
|
491
|
|
|
$fsDataSource->load(); |
|
492
|
|
|
$items = $fsDataSource->getItems(); |
|
493
|
|
|
|
|
494
|
|
|
$this->assertArrayNotHasKey('HEAD', $items); |
|
495
|
|
|
} |
|
496
|
|
|
|
|
497
|
|
View Code Duplication |
public function testGetItemsMustReturnItemsOfIncludedFolderWhenIncludeOptionIsUsedWithAFolder() |
|
|
|
|
|
|
498
|
|
|
{ |
|
499
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
500
|
|
|
'source_root' => $this->sourcePath, |
|
501
|
|
|
'include' => [$this->extraPagesPath], |
|
502
|
|
|
'text_extensions' => $this->textExtensions, |
|
503
|
|
|
]); |
|
504
|
|
|
$fsDataSource->load(); |
|
505
|
|
|
|
|
506
|
|
|
$this->assertCount(17, $fsDataSource->getItems()); |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
View Code Duplication |
public function testGetItemMustNotContainExcludedItemWhenExcludeOptionIsSetWithAFile() |
|
|
|
|
|
|
510
|
|
|
{ |
|
511
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
512
|
|
|
'source_root' => $this->sourcePath, |
|
513
|
|
|
'exclude' => ['robots.txt'], |
|
514
|
|
|
'text_extensions' => $this->textExtensions, |
|
515
|
|
|
]); |
|
516
|
|
|
$fsDataSource->load(); |
|
517
|
|
|
|
|
518
|
|
|
$this->assertCount(14, $fsDataSource->getItems()); |
|
519
|
|
|
} |
|
520
|
|
|
|
|
521
|
|
View Code Duplication |
public function testExcludeFolder() |
|
|
|
|
|
|
522
|
|
|
{ |
|
523
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
524
|
|
|
'source_root' => $this->sourcePath, |
|
525
|
|
|
'exclude' => ['about'], |
|
526
|
|
|
'text_extensions' => $this->textExtensions, |
|
527
|
|
|
]); |
|
528
|
|
|
$fsDataSource->load(); |
|
529
|
|
|
|
|
530
|
|
|
$this->assertCount(13, $fsDataSource->getItems()); |
|
531
|
|
|
} |
|
532
|
|
|
|
|
533
|
|
View Code Duplication |
public function testAvoidRenderizerPath() |
|
|
|
|
|
|
534
|
|
|
{ |
|
535
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
536
|
|
|
'source_root' => $this->sourcePath, |
|
537
|
|
|
'text_extensions' => $this->textExtensions, |
|
538
|
|
|
'avoid_renderizer_path' => ['projects'], |
|
539
|
|
|
]); |
|
540
|
|
|
|
|
541
|
|
|
$fsDataSource->load(); |
|
542
|
|
|
|
|
543
|
|
|
$items = $fsDataSource->getItems(); |
|
544
|
|
|
|
|
545
|
|
|
$this->assertCount(15, $items); |
|
546
|
|
|
|
|
547
|
|
|
$itemAttributes = $items['projects/index.md']->getAttributes(); |
|
548
|
|
|
$this->assertArrayHasKey('avoid_renderizer', $itemAttributes); |
|
549
|
|
|
|
|
550
|
|
|
$itemAttributes = $items['posts/books/2013-08-11-best-book.md']->getAttributes(); |
|
551
|
|
|
$this->assertArrayNotHasKey('avoid_renderizer', $itemAttributes); |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
View Code Duplication |
public function testAvoidRenderizerFilenameExtension() |
|
|
|
|
|
|
555
|
|
|
{ |
|
556
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
557
|
|
|
'source_root' => $this->sourcePath, |
|
558
|
|
|
'text_extensions' => $this->textExtensions, |
|
559
|
|
|
'avoid_renderizer_extension' => ['mkd'], |
|
560
|
|
|
]); |
|
561
|
|
|
|
|
562
|
|
|
$fsDataSource->load(); |
|
563
|
|
|
|
|
564
|
|
|
$items = $fsDataSource->getItems(); |
|
565
|
|
|
|
|
566
|
|
|
$this->assertCount(15, $items); |
|
567
|
|
|
|
|
568
|
|
|
$itemAttributes = $items['posts/2013-08-12-post-example-2.mkd']->getAttributes(); |
|
569
|
|
|
$this->assertArrayHasKey('avoid_renderizer', $itemAttributes); |
|
570
|
|
|
|
|
571
|
|
|
$itemAttributes = $items['posts/books/2013-08-11-best-book.md']->getAttributes(); |
|
572
|
|
|
$this->assertArrayNotHasKey('avoid_renderizer', $itemAttributes); |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
/** |
|
576
|
|
|
* @expectedException Yosymfony\Spress\Core\ContentManager\Exception\MissingAttributeException |
|
577
|
|
|
*/ |
|
578
|
|
|
public function testConfigNoParams() |
|
579
|
|
|
{ |
|
580
|
|
|
$fsDataSource = new FilesystemDataSource([]); |
|
581
|
|
|
$fsDataSource->load(); |
|
582
|
|
|
} |
|
583
|
|
|
|
|
584
|
|
|
/** |
|
585
|
|
|
* @expectedException \Yosymfony\Spress\Core\ContentManager\Exception\MissingAttributeException |
|
586
|
|
|
*/ |
|
587
|
|
|
public function testNoParamTextExtensions() |
|
588
|
|
|
{ |
|
589
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
590
|
|
|
'source_root' => $this->sourcePath, |
|
591
|
|
|
]); |
|
592
|
|
|
$fsDataSource->load(); |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
/** |
|
596
|
|
|
* @expectedException Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException |
|
597
|
|
|
*/ |
|
598
|
|
|
public function testBadParamSourceRoot() |
|
599
|
|
|
{ |
|
600
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
601
|
|
|
'source_root' => [], |
|
602
|
|
|
'text_extensions' => $this->textExtensions, |
|
603
|
|
|
]); |
|
604
|
|
|
$fsDataSource->load(); |
|
605
|
|
|
} |
|
606
|
|
|
|
|
607
|
|
|
/** |
|
608
|
|
|
* @expectedException Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException |
|
609
|
|
|
*/ |
|
610
|
|
View Code Duplication |
public function testBadParamInclude() |
|
|
|
|
|
|
611
|
|
|
{ |
|
612
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
613
|
|
|
'source_root' => $this->sourcePath, |
|
614
|
|
|
'include' => './', |
|
615
|
|
|
'text_extensions' => $this->textExtensions, |
|
616
|
|
|
]); |
|
617
|
|
|
$fsDataSource->load(); |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
/** |
|
621
|
|
|
* @expectedException Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException |
|
622
|
|
|
*/ |
|
623
|
|
View Code Duplication |
public function testBadParamExclude() |
|
|
|
|
|
|
624
|
|
|
{ |
|
625
|
|
|
$fsDataSource = new FilesystemDataSource([ |
|
626
|
|
|
'source_root' => $this->sourcePath, |
|
627
|
|
|
'exclude' => './', |
|
628
|
|
|
'text_extensions' => $this->textExtensions, |
|
629
|
|
|
]); |
|
630
|
|
|
$fsDataSource->load(); |
|
631
|
|
|
} |
|
632
|
|
|
} |
|
633
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.