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 Reddogs\Test\ServiceManagerAwareTestCase; |
13
|
|
|
use Jolicht\MarkdownCms\ModuleConfig; |
14
|
|
|
use Jolicht\MarkdownCms\Parser\ContentParser; |
15
|
|
|
use Jolicht\MarkdownCms\Iterator\MarkdownFileIterator; |
16
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentCreator; |
17
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocumentParser; |
18
|
|
|
|
19
|
|
|
class ContentParserTest extends ServiceManagerAwareTestCase |
20
|
|
|
{ |
21
|
|
|
private $parser, $markdownFileIterator, $contentCreator, $markdownDocumentParser, $markdownOptions; |
|
|
|
|
22
|
|
|
|
23
|
|
|
protected function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->setConfigProviders([ModuleConfig::class]); |
26
|
|
|
parent::setUp(); |
27
|
|
|
|
28
|
|
|
$this->markdownOptions = [ |
29
|
|
|
'content_dir' => __DIR__ . '/_files', |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
$container = $this->getContainer(); |
33
|
|
|
$config = $container->get('config'); |
34
|
|
|
$config['markdown_cms']['options'] = array_merge($config['markdown_cms']['options'], $this->markdownOptions); |
35
|
|
|
$container->setAllowOverride(true); |
36
|
|
|
$container->setService('config', $config); |
37
|
|
|
$container->setAllowOverride(false); |
38
|
|
|
|
39
|
|
|
$this->markdownFileIterator = $container->get(MarkdownFileIterator::class); |
40
|
|
|
$this->contentCreator = $container->get(ContentCreator::class); |
41
|
|
|
$this->markdownDocumentParser = $container->get(MarkdownDocumentParser::class); |
42
|
|
|
|
43
|
|
|
$this->parser = new ContentParser($this->markdownFileIterator, $this->contentCreator, |
44
|
|
|
$this->markdownDocumentParser, $config['markdown_cms']['options']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testGetMarkdownFileIterator() |
48
|
|
|
{ |
49
|
|
|
$this->assertSame($this->markdownFileIterator, $this->parser->getMarkdownFileIterator()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testGetContentCreator() |
53
|
|
|
{ |
54
|
|
|
$this->assertSame($this->contentCreator, $this->parser->getContentCreator()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGetMarkdownDocumentParser() |
58
|
|
|
{ |
59
|
|
|
$this->assertSame($this->markdownDocumentParser, $this->parser->getMarkdownDocumentParser()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetMarkdownOptions() |
63
|
|
|
{ |
64
|
|
|
$config = $this->getContainer()->get('config'); |
65
|
|
|
$this->assertEquals($config['markdown_cms']['options'], $this->parser->getMarkdownOptions()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testParse() |
69
|
|
|
{ |
70
|
|
|
$src = [ |
71
|
|
|
'testBlogEntryId' => 'blog/2017/2017-03-19-TestBlogbeitrag.md', |
72
|
|
|
'testBlogEntryId1' => 'blog/2017/2017-03-18-TestBlogbeitrag1.md', |
73
|
|
|
'testPageId' => 'pages/testpage.md', |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$blogEntryByCreated = [ |
77
|
|
|
'2017-03-19T06:30:00' => 'testBlogEntryId', |
78
|
|
|
'2017-03-18T06:30:00' => 'testBlogEntryId1', |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
$actual = $this->parser->__invoke(); |
82
|
|
|
$this->assertEquals($src, $actual['src']); |
83
|
|
|
$this->assertSame($blogEntryByCreated, $actual['content_types']['blogEntry']['byCreated']); |
84
|
|
|
$this->assertCount(4, $actual['content_types']['blogEntry']['tags']); |
85
|
|
|
$this->assertCount(1, $actual['content_types']['blogEntry']['tags']['php']); |
86
|
|
|
$this->assertCount(1, $actual['content_types']['blogEntry']['tags']['markdown']); |
87
|
|
|
$this->assertCount(2, $actual['content_types']['blogEntry']['tags']['tdd']); |
88
|
|
|
$this->assertCount(1, $actual['content_types']['blogEntry']['tags']['zend']); |
89
|
|
|
} |
90
|
|
|
} |
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.