Passed
Push — master ( 335181...c02fce )
by Johannes
03:11
created

SitemapObserverTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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\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
}