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; |
|
|
|
|
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
|
|
|
} |
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.