1<?php
2
3namespace Sabre\DAV\Xml\Property;
4
5use Sabre\DAV\Xml\XmlTest;
6use DateTime;
7use DateTimeZone;
8
9class LastModifiedTest extends XmlTest {
10
11    function testSerializeDateTime() {
12
13        $dt = new DateTime('2015-03-24 11:47:00', new DateTimeZone('America/Vancouver'));
14        $val = ['{DAV:}getlastmodified' => new GetLastModified($dt)];
15
16        $result = $this->write($val);
17        $expected = <<<XML
18<?xml version="1.0"?>
19<d:getlastmodified xmlns:d="DAV:">Tue, 24 Mar 2015 18:47:00 GMT</d:getlastmodified>
20XML;
21
22        $this->assertXmlStringEqualsXmlString($expected, $result);
23
24    }
25
26    function testSerializeTimeStamp() {
27
28        $dt = new DateTime('2015-03-24 11:47:00', new DateTimeZone('America/Vancouver'));
29        $dt = $dt->getTimeStamp();
30        $val = ['{DAV:}getlastmodified' => new GetLastModified($dt)];
31
32        $result = $this->write($val);
33        $expected = <<<XML
34<?xml version="1.0"?>
35<d:getlastmodified xmlns:d="DAV:">Tue, 24 Mar 2015 18:47:00 GMT</d:getlastmodified>
36XML;
37
38        $this->assertXmlStringEqualsXmlString($expected, $result);
39
40    }
41
42    function testDeserialize() {
43
44        $input = <<<XML
45<?xml version="1.0"?>
46<d:getlastmodified xmlns:d="DAV:">Tue, 24 Mar 2015 18:47:00 GMT</d:getlastmodified>
47XML;
48
49        $elementMap = ['{DAV:}getlastmodified' => 'Sabre\DAV\Xml\Property\GetLastModified'];
50        $result = $this->parse($input, $elementMap);
51
52        $this->assertEquals(
53            new DateTime('2015-03-24 18:47:00', new DateTimeZone('UTC')),
54            $result['value']->getTime()
55        );
56
57    }
58
59}
60