Test Failed
Push — master ( 215d68...967d39 )
by Yo!
07:35 queued 04:47
created

FilesystemDataSourceTest   B

Complexity

Total Complexity 38

Size/Duplication

Total Lines 614
Duplicated Lines 64.17 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 97.61%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 38
c 3
b 0
f 0
lcom 1
cbo 3
dl 394
loc 614
ccs 204
cts 209
cp 0.9761
rs 8.3999

38 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A tearDown() 0 5 1
B testProcessItems() 0 40 1
B testGetItemsMustReturnTheItemsOfASite() 0 27 1
A testGetLayoutsMustReturnTheLayoutsOfASite() 13 13 1
A testGetIncludesMustReturnTheLayoutsOfASite() 13 13 1
A testGetLayoutsMustReturnsAnArrayOfItemInterface() 17 17 1
A testGetIncludesMustReturnsAnArrayOfItemInterface() 17 17 1
A testGetItemsMustReturnsAnArrayOfItemInterface() 17 17 1
A testGetTypeOfAnIncludeItemMustBeInclude() 16 16 1
A testGetContentOfAnIncludeItemMustBeRight() 16 16 1
A testGetTypeOfAnLayoutItemMustBeLayout() 16 16 1
A testGetContentOfALayoutItemMustBeRight() 16 16 1
A testGetBinaryOfAnItemMustReturnTrueIfThereIsNotFilenameExtension() 15 15 1
A testGetBinaryOfAnItemMustReturnFalseIfTheFilenameExtensionBelongsToTextExtensions() 15 15 1
A testGetBinaryOfAnItemMustReturnTrueIfTheFilenameExtensionDoesNotBelongsToTextExtensions() 0 15 1
A testGetPathOfABinaryItemMustHasSourceAndRelativePaths() 20 20 1
A testGetPathOfATextItemMustHasOnlyARelativePaths() 20 20 1
A testGetAttributesMustReturnsTheBasicAttributes() 0 16 1
A testGetLayoutsMustGivesPreferenceSiteLayoutsOverThemeLayoutsWhenThereIsAEnabledTheme() 14 14 1
A testGetIncludesMustGivesPreferenceSiteIncludesOverThemeIncludesWhenThereIsAEnabledTheme() 14 14 1
A testGetItemsMustGivesPreferenceSiteAssetsOverThemeAssetsWhenThereIsAEnabledTheme() 12 12 1
A testGetItemsMustReturnThemeAssetsIfItDoesNotExistsInTheSiteAssetsWhenThereIsAEnabledTheme() 0 14 1
A testGetIncludesMustReturnThemeIncludesIfItDoesNotExistsInTheSiteIncludesWhenThereIsAEnabledTheme() 14 14 1
A testGetLayoutsMustReturnThemeLayoutsIfItDoesNotExistsInTheSiteLayoutsWhenThereIsAEnabledTheme() 14 14 1
A testGetItemsMustReturnAnExtraItemWhenIncludeOptionIsSetWithAFile() 13 13 1
A testGetItemsMustReturnDotItemsWhenThereAreDotFiles() 11 11 1
A testGetItemsMustNotReturnItemsInVCSFolders() 0 14 1
A testGetItemsMustReturnItemsOfIncludedFolderWhenIncludeOptionIsUsedWithAFolder() 11 11 1
A testGetItemMustNotContainExcludedItemWhenExcludeOptionIsSetWithAFile() 11 11 1
A testExcludeFolder() 11 11 1
A testAvoidRenderizerPath() 20 20 1
A testAvoidRenderizerFilenameExtension() 20 20 1
A testConfigNoParams() 0 5 1
A testNoParamTextExtensions() 0 7 1
A testBadParamSourceRoot() 0 8 1
A testBadParamInclude() 9 9 1
A testBadParamExclude() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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());
519
    }
520
521 View Code Duplication
    public function testExcludeFolder()
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());
531
    }
532
533 View Code Duplication
    public function testAvoidRenderizerPath()
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...
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()
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...
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()
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...
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()
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...
624
    {
625
        $fsDataSource = new FilesystemDataSource([
626
            'source_root' => $this->sourcePath,
627
            'exclude' => './',
628
            'text_extensions' => $this->textExtensions,
629
        ]);
630
        $fsDataSource->load();
631
    }
632
}
633