Completed
Push — master ( c02fce...0001a8 )
by Johannes
03:23
created

SitemapObserverTest::testInvoke()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 27
rs 8.8571
c 1
b 0
f 0
cc 2
eloc 16
nc 2
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\Observer;
11
12
use PHPUnit\Framework\TestCase;
13
use Jolicht\MarkdownCms\Parser\Observer\SitemapObserver;
14
use Sabre\Xml\Writer as XmlWriter;
15
16
class SitemapObserverTest extends TestCase
17
{
18
    private $observer, $xmlWriter;
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...
19
20
    protected function setUp()
21
    {
22
        $this->xmlWriter = new XmlWriter();
23
        $this->observer = new SitemapObserver($this->xmlWriter, __DIR__ . '/_files/sitemap.xml', 'https://test.at/');
24
    }
25
26
    public function testGetXmlWriter()
27
    {
28
        $this->assertSame($this->xmlWriter, $this->observer->getXmlWriter());
29
    }
30
31
    public function testGetSitemapPath()
32
    {
33
        $this->assertSame(__DIR__ . '/_files/sitemap.xml', $this->observer->getSitemapPath());
34
    }
35
36
    public function testGetBaseUrl()
37
    {
38
        $this->assertSame('https://test.at', $this->observer->getBaseUrl());
39
    }
40
41
    public function testInvoke()
42
    {
43
        $sitemapPath = $this->observer->getSitemapPath();
44
        if (file_exists($sitemapPath)) {
45
            unlink($sitemapPath);
46
        }
47
48
        $config = [
49
            'content_types' => [
50
                'blogEntry' => [
51
                    'all' => [
52
                        '2017-03-16T06:30:00' => 'blogbeitrag-1',
53
                        '2017-03-14T06:30:00' => 'blogbeitrag-2',
54
                    ],
55
                ],
56
                'page' => [
57
                    'all' => [
58
                        '2017-03-20T04:30:00' => 'page-1',
59
                        '2017-03-19T03:30:00' => 'page-2',
60
                    ],
61
                ],
62
            ]
63
        ];
64
65
        $this->observer->__invoke($config);
66
        $this->assertFileEquals(__DIR__ . '/_files/expected-sitemap.xml', $this->observer->getSitemapPath());
67
    }
68
69
    public function testInvokeNoContent()
70
    {
71
        $config = [
72
            'content_types' => [
73
            ]
74
        ];
75
76
        $this->observer->__invoke($config);
77
        $this->assertFileEquals(__DIR__ . '/_files/expected-sitemap.no-content.xml', $this->observer->getSitemapPath());
78
    }
79
}