1<?php
2
3namespace Sabre\CalDAV\Xml\Notification;
4
5use Sabre\CalDAV;
6use Sabre\DAV;
7use Sabre\Xml\Writer;
8
9class SystemStatusTest extends \PHPUnit_Framework_TestCase {
10
11    /**
12     * @dataProvider dataProvider
13     */
14    function testSerializers($notification, $expected1, $expected2) {
15
16        $this->assertEquals('foo', $notification->getId());
17        $this->assertEquals('"1"', $notification->getETag());
18
19        $writer = new Writer();
20        $writer->namespaceMap = [
21            'http://calendarserver.org/ns/' => 'cs',
22        ];
23        $writer->openMemory();
24        $writer->startDocument('1.0', 'UTF-8');
25        $writer->startElement('{http://calendarserver.org/ns/}root');
26        $writer->write($notification);
27        $writer->endElement();
28        $this->assertXmlStringEqualsXmlString($expected1, $writer->outputMemory());
29
30        $writer = new Writer();
31        $writer->namespaceMap = [
32            'http://calendarserver.org/ns/' => 'cs',
33            'DAV:' => 'd',
34        ];
35        $writer->openMemory();
36        $writer->startDocument('1.0', 'UTF-8');
37        $writer->startElement('{http://calendarserver.org/ns/}root');
38        $notification->xmlSerializeFull($writer);;
39        $writer->endElement();
40        $this->assertXmlStringEqualsXmlString($expected2, $writer->outputMemory());
41
42    }
43
44    function dataProvider() {
45
46        return [
47
48            [
49                new SystemStatus('foo', '"1"'),
50                '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:systemstatus type="high"/></cs:root>' . "\n",
51                '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"><cs:systemstatus type="high"/></cs:root>' . "\n",
52            ],
53            [
54                new SystemStatus('foo', '"1"', SystemStatus::TYPE_MEDIUM,'bar'),
55                '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:systemstatus type="medium"/></cs:root>' . "\n",
56                '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"><cs:systemstatus type="medium"><cs:description>bar</cs:description></cs:systemstatus></cs:root>' . "\n",
57            ],
58            [
59                new SystemStatus('foo', '"1"', SystemStatus::TYPE_LOW,null,'http://example.org/'),
60                '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:systemstatus type="low"/></cs:root>' . "\n",
61                '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"><cs:systemstatus type="low"><d:href>http://example.org/</d:href></cs:systemstatus></cs:root>' . "\n",
62            ]
63        ];
64
65    }
66
67}
68