Test Failed
Push — master ( f09e2c...6721e1 )
by Yo!
05:56
created

testLoadMethodMustThrowAnAttributeValueExceptionWhenTheClassHasAnInvalidSourceRootParam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
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();
0 ignored issues
show
Unused Code introduced by
$layouts is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
53 1
        $includes = $fsDataSource->getIncludes();
0 ignored issues
show
Unused Code introduced by
$includes is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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(), 'Failed to exclude the file.');
519
    }
520
521 View Code Duplication
    public function testGetItemMustNotContainTheItemsOfAExcludedFolderWhenExcludeOptionIsSetWithAFolder()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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(), 'Failed to exclude the elements of about folder.');
531
    }
532
533
    public function testGetItemMustReturnItemsWithAvoidRenderizerAttributeWhenTheybelongToAFolderDeclaredAtAvoidRenderizerPathOption()
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
        $items = $fsDataSource->getItems();
543
544
        $itemAttributes = $items['projects/index.md']->getAttributes();
545
        $this->assertArrayHasKey('avoid_renderizer', $itemAttributes);
546
    }
547
548
    public function testGetItemMustReturnItemsWithoutAvoidRenderizerAttributeWhenTheyDoesNotbelongToAFolderDeclaredAtAvoidRenderizerPathOption()
549
    {
550
        $fsDataSource = new FilesystemDataSource([
551
            'source_root' => $this->sourcePath,
552
            'text_extensions' => $this->textExtensions,
553
            'avoid_renderizer_path' => ['projects'],
554
        ]);
555
556
        $fsDataSource->load();
557
        $items = $fsDataSource->getItems();
558
559
        $itemAttributes = $items['posts/books/2013-08-11-best-book.md']->getAttributes();
560
        $this->assertArrayNotHasKey('avoid_renderizer', $itemAttributes);
561
    }
562
563
    public function testGetItemMustReturnItemsWithAvoidRenderizerAttributeWhenTheyHaveAnFilenameExtensionDeclaredAtAvoidRenderizerExtensionOption()
564
    {
565
        $fsDataSource = new FilesystemDataSource([
566
            'source_root' => $this->sourcePath,
567
            'text_extensions' => $this->textExtensions,
568
            'avoid_renderizer_extension' => ['mkd'],
569
        ]);
570
        $fsDataSource->load();
571
        $items = $fsDataSource->getItems();
572
573
        $itemAttributes = $items['posts/2013-08-12-post-example-2.mkd']->getAttributes();
574
        $this->assertArrayHasKey('avoid_renderizer', $itemAttributes);
575
    }
576
577
    public function testGetItemMustReturnItemsWithoutAvoidRenderizerAttributeWhenTheyHaveAnFilenameExtensionNotDeclaredAtAvoidRenderizerExtensionOption()
578
    {
579
        $fsDataSource = new FilesystemDataSource([
580
            'source_root' => $this->sourcePath,
581
            'text_extensions' => $this->textExtensions,
582
            'avoid_renderizer_extension' => ['mkd'],
583
        ]);
584
        $fsDataSource->load();
585
        $items = $fsDataSource->getItems();
586
587
        $itemAttributes = $items['posts/books/2013-08-11-best-book.md']->getAttributes();
588
        $this->assertArrayNotHasKey('avoid_renderizer', $itemAttributes);
589
    }
590
591
    /**
592
     * @expectedException Yosymfony\Spress\Core\ContentManager\Exception\MissingAttributeException
593
     */
594
    public function testLoadMethodMustThrowAMissingAttributeExceptionWhenTheClassDoesNotHaveConfigParams()
595
    {
596
        $fsDataSource = new FilesystemDataSource([]);
597
        $fsDataSource->load();
598
    }
599
600
    /**
601
     * @expectedException \Yosymfony\Spress\Core\ContentManager\Exception\MissingAttributeException
602
     */
603
    public function testLoadMethodMustThrowAMissingAttributeExceptionWhenTheClassDoesNotHaveSetTextExtensionsOption()
604
    {
605
        $fsDataSource = new FilesystemDataSource([
606
            'source_root' => $this->sourcePath,
607
        ]);
608
        $fsDataSource->load();
609
    }
610
611
    /**
612
     * @expectedException Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException
613
     */
614
    public function testLoadMethodMustThrowAnAttributeValueExceptionWhenTheClassHasAnInvalidSourceRootParam()
615
    {
616
        $fsDataSource = new FilesystemDataSource([
617
            'source_root' => [],
618
            'text_extensions' => $this->textExtensions,
619
        ]);
620
        $fsDataSource->load();
621
    }
622
623
    /**
624
     * @expectedException Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException
625
     */
626 View Code Duplication
    public function testLoadMethodMustThrowAnAttributeValueExceptionWhenTheClassHasAnInvalidIncludeParam()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
627
    {
628
        $fsDataSource = new FilesystemDataSource([
629
            'source_root' => $this->sourcePath,
630
            'include' => './',
631
            'text_extensions' => $this->textExtensions,
632
        ]);
633
        $fsDataSource->load();
634
    }
635
636
    /**
637
     * @expectedException Yosymfony\Spress\Core\ContentManager\Exception\AttributeValueException
638
     */
639 View Code Duplication
    public function testLoadMethodMustThrowAnAttributeValueExceptionWhenTheClassHasAnInvalidExcludeParam()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
640
    {
641
        $fsDataSource = new FilesystemDataSource([
642
            'source_root' => $this->sourcePath,
643
            'exclude' => './',
644
            'text_extensions' => $this->textExtensions,
645
        ]);
646
        $fsDataSource->load();
647
    }
648
}
649