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, $markdownDocumentParser, $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->markdownDocumentParser = 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->markdownDocumentParser, |
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->markdownDocumentParser, $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
|
|
|
$src = [ |
72
|
|
|
'testBlogEntryId' => 'blog/2017/2017-03-19-TestBlogbeitrag.md', |
73
|
|
|
'testBlogEntryId1' => 'blog/2017/2017-03-18-TestBlogbeitrag1.md', |
74
|
|
|
'testPageId' => 'pages/testpage.md', |
75
|
|
|
'testDraftBlogEntryId' => 'blog/2017/2017-03-20-TestBlogbeitragDraft.md', |
76
|
|
|
'testDraftPageId' => 'pages/testpage-draft.md', |
77
|
|
|
]; |
78
|
|
|
|
79
|
|
|
$blogEntryByCreated = [ |
80
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId', |
81
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1', |
82
|
|
|
]; |
83
|
|
|
$blogEntryTags = [ |
84
|
|
|
'tdd' => [ |
85
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId', |
86
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1', |
87
|
|
|
], |
88
|
|
|
'markdown' => [ |
89
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId' |
90
|
|
|
], |
91
|
|
|
'php' => [ |
92
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId' |
93
|
|
|
], |
94
|
|
|
'zend' => [ |
95
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1' |
96
|
|
|
] |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
$actual = $this->parser->__invoke(); |
100
|
|
|
|
101
|
|
|
$this->assertEquals($src, $actual['src']); |
102
|
|
|
$this->assertSame($blogEntryByCreated, $actual['content_types']['blogEntry']['all']); |
103
|
|
|
$this->assertSame($blogEntryTags, $actual['content_types']['blogEntry']['tags']); |
104
|
|
|
} |
105
|
|
|
} |
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.