Test Failed
Push — master ( c81326...794fe0 )
by Johannes
03:04
created

ContentParserTest::testParse()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 19
nc 1
nop 0
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;
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

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.

Loading history...
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
        $expected = [
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
            ],
76
            'content_types' => [
77
                'blogEntry' => [
78
                    'byCreated' => [
79
                        '2017-03-19T06:30:00+01:00' => 'testBlogEntryId',
80
                        '2017-03-18T06:30:00+01:00' => 'testBlogEntryId1',
81
                    ],
82
                    'tags' => [
83
                        'php' => ['testBlogEntryId'],
84
                        'markdown' => ['testBlogEntryId'],
85
                        'tdd' => ['testBlogEntryId', 'testBlogEntryId1'],
86
                        'zend' => ['testBlogEntryId1']
87
                    ]
88
                ]
89
            ]
90
        ];
91
92
        $actual = $this->parser->__invoke();
93
        $this->assertEquals($expected, $actual);
94
        $this->assertSame($expected['content_types']['blogEntry']['byCreated'], $actual['content_types']['blogEntry']['byCreated']);
95
    }
96
}