]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/Property/GetLastModifiedTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / Property / GetLastModifiedTest.php
1 <?php
2
3 class Sabre_DAV_Property_GetLastModifiedTest extends PHPUnit_Framework_TestCase {
4
5     function testConstructDateTime() {
6
7         $dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
8         $lastMod = new Sabre_DAV_Property_GetLastModified($dt);
9         $this->assertEquals($dt->format(DateTime::ATOM), $lastMod->getTime()->format(DateTime::ATOM));
10
11     }
12
13     function testConstructString() {
14
15         $dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
16         $lastMod = new Sabre_DAV_Property_GetLastModified('2010-03-14 16:35');
17         $this->assertEquals($dt->format(DateTime::ATOM), $lastMod->getTime()->format(DateTime::ATOM));
18
19     }
20
21     function testConstructInt() {
22
23         $dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
24         $lastMod = new Sabre_DAV_Property_GetLastModified((int)$dt->format('U'));
25         $this->assertEquals($dt->format(DateTime::ATOM), $lastMod->getTime()->format(DateTime::ATOM));
26
27     }
28
29     function testSerialize() {
30
31         $dt = new DateTime('2010-03-14 16:35', new DateTimeZone('UTC'));
32         $lastMod = new Sabre_DAV_Property_GetLastModified($dt);
33
34         $doc = new DOMDocument();
35         $root = $doc->createElement('d:getlastmodified');
36         $root->setAttribute('xmlns:d','DAV:');
37
38         $doc->appendChild($root);
39         $objectTree = new Sabre_DAV_ObjectTree(new Sabre_DAV_SimpleCollection('rootdir'));
40         $server = new Sabre_DAV_Server($objectTree);
41
42         $lastMod->serialize($server, $root);
43
44         $xml = $doc->saveXML();
45
46         $this->assertEquals(
47 '<?xml version="1.0"?>
48 <d:getlastmodified xmlns:d="DAV:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" b:dt="dateTime.rfc1123">' .
49 Sabre_HTTP_Util::toHTTPDate($dt) .
50 '</d:getlastmodified>
51 ', $xml);
52
53         $ok = false;
54         try {
55             Sabre_DAV_Property_GetLastModified::unserialize(Sabre_DAV_XMLUtil::loadDOMDocument($xml)->firstChild);
56         } catch (Sabre_DAV_Exception $e) {
57             $ok = true;
58         }
59         if (!$ok) $this->markTestFailed('Unserialize should not be supported');
60
61     }
62
63 }