Completed
Push — master ( 280ca2...4c75e7 )
by Johannes
02:18
created

SitemapObserverTest::testInvoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 2
eloc 12
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
            ]
57
        ];
58
59
        $this->observer->__invoke($config);
60
        $this->assertFileEquals(__DIR__ . '/_files/expected-sitemap.xml', $this->observer->getSitemapPath());
61
    }
62
}