|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Lichtenwallner (https://lichtenwallner.at) |
|
4
|
|
|
* |
|
5
|
|
|
* @see https://github.com/jolicht/markdown-cms for the canonical source repository |
|
6
|
|
|
* @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT |
|
7
|
|
|
* @copyright Copyright (c) Johannes Lichtenwallner |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types = 1); |
|
10
|
|
|
namespace JolichtTest\MarkdownCms\Parser; |
|
11
|
|
|
|
|
12
|
|
|
use Jolicht\MarkdownCms\ModuleConfig; |
|
13
|
|
|
use Jolicht\MarkdownCms\Parser\ContentParser; |
|
14
|
|
|
use Jolicht\MarkdownCms\Iterator\MarkdownFileIterator; |
|
15
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentCreator; |
|
16
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocumentParser; |
|
17
|
|
|
use PHPUnit\Framework\TestCase; |
|
18
|
|
|
use Mni\FrontYAML\Parser; |
|
19
|
|
|
|
|
20
|
|
|
class ContentParserTest extends TestCase |
|
21
|
|
|
{ |
|
22
|
|
|
private $parser, $markdownFileIterator, $contentCreator, $mdDocumentParser, $markdownOptions; |
|
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
$moduleConfig = new ModuleConfig(); |
|
27
|
|
|
$config = $moduleConfig(); |
|
28
|
|
|
|
|
29
|
|
|
$this->markdownFileIterator = new MarkdownFileIterator( |
|
30
|
|
|
new \RecursiveIteratorIterator( |
|
31
|
|
|
new \RecursiveDirectoryIterator(__DIR__ . '/_files') |
|
32
|
|
|
), |
|
33
|
|
|
'/^.+\.md$/i', |
|
34
|
|
|
\RecursiveRegexIterator::MATCH |
|
35
|
|
|
); |
|
36
|
|
|
$this->contentCreator = new ContentCreator($config['markdown_cms']['options']); |
|
37
|
|
|
$this->mdDocumentParser = new MarkdownDocumentParser(new Parser()); |
|
38
|
|
|
$this->markdownOptions = [ |
|
39
|
|
|
'content_dir' => __DIR__ . '/_files' |
|
40
|
|
|
]; |
|
41
|
|
|
|
|
42
|
|
|
$this->parser = new ContentParser( |
|
43
|
|
|
$this->markdownFileIterator, |
|
44
|
|
|
$this->contentCreator, |
|
45
|
|
|
$this->mdDocumentParser, |
|
46
|
|
|
$this->markdownOptions); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testGetMarkdownFileIterator() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertSame($this->markdownFileIterator, $this->parser->getMarkdownFileIterator()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testGetContentCreator() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertSame($this->contentCreator, $this->parser->getContentCreator()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetMarkdownDocumentParser() |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertSame($this->mdDocumentParser, $this->parser->getMarkdownDocumentParser()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testGetMarkdownOptions() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->assertEquals($this->markdownOptions, $this->parser->getMarkdownOptions()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function testParse() |
|
70
|
|
|
{ |
|
71
|
|
|
$all = [ |
|
72
|
|
|
'testBlogEntryId' => [ |
|
73
|
|
|
'src' => 'blog/2017/2017-03-19-TestBlogbeitrag.md' |
|
74
|
|
|
], |
|
75
|
|
|
'testBlogEntryId1' => [ |
|
76
|
|
|
'src' => 'blog/2017/2017-03-18-TestBlogbeitrag1.md', |
|
77
|
|
|
], |
|
78
|
|
|
'testPageId' => [ |
|
79
|
|
|
'src' => 'pages/testpage.md', |
|
80
|
|
|
], |
|
81
|
|
|
'anotherId' => [ |
|
82
|
|
|
'src' => 'pages/anotherpage.md', |
|
83
|
|
|
], |
|
84
|
|
|
'testDraftBlogEntryId' => [ |
|
85
|
|
|
'src' => 'blog/2017/2017-03-20-TestBlogbeitragDraft.md', |
|
86
|
|
|
], |
|
87
|
|
|
'testDraftPageId' => [ |
|
88
|
|
|
'src' => 'pages/testpage-draft.md', |
|
89
|
|
|
], |
|
90
|
|
|
]; |
|
91
|
|
|
|
|
92
|
|
|
$blogEntryByCreated = [ |
|
93
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId', |
|
94
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1', |
|
95
|
|
|
]; |
|
96
|
|
|
$blogEntryTags = [ |
|
97
|
|
|
'tdd' => [ |
|
98
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId', |
|
99
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1', |
|
100
|
|
|
], |
|
101
|
|
|
'markdown' => [ |
|
102
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId' |
|
103
|
|
|
], |
|
104
|
|
|
'php' => [ |
|
105
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId' |
|
106
|
|
|
], |
|
107
|
|
|
'zend' => [ |
|
108
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1' |
|
109
|
|
|
] |
|
110
|
|
|
]; |
|
111
|
|
|
$pagesByCreated = [ |
|
112
|
|
|
'2017-03-22T04:30:00' => 'anotherId', |
|
113
|
|
|
'2017-03-19T05:30:00' => 'testPageId', |
|
114
|
|
|
]; |
|
115
|
|
|
|
|
116
|
|
|
$actual = $this->parser->__invoke(); |
|
117
|
|
|
|
|
118
|
|
|
$this->assertEquals($all, $actual['all']); |
|
119
|
|
|
$this->assertSame($blogEntryByCreated, $actual['content_types']['blogEntry']['all']); |
|
120
|
|
|
$this->assertSame($blogEntryTags, $actual['content_types']['blogEntry']['tags']); |
|
121
|
|
|
$this->assertSame($pagesByCreated, $actual['content_types']['page']['all']); |
|
122
|
|
|
} |
|
123
|
|
|
} |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.