1<?php
2
3namespace Sabre\DAV\Xml\Property;
4
5use Sabre\DAV\Xml\XmlTest;
6use Sabre\DAV\Locks\LockInfo;
7
8class LockDiscoveryTest extends XmlTest {
9
10    function testSerialize() {
11
12        $lock = new LockInfo();
13        $lock->owner = 'hello';
14        $lock->token = 'blabla';
15        $lock->timeout = 600;
16        $lock->created = strtotime('2015-03-25 19:21:00');
17        $lock->scope = LockInfo::EXCLUSIVE;
18        $lock->depth = 0;
19        $lock->uri = 'hi';
20
21        $prop = new LockDiscovery([$lock]);
22
23        $xml = $this->write(['{DAV:}root' => $prop]);
24
25        $this->assertXmlStringEqualsXmlString(
26'<?xml version="1.0"?>
27<d:root xmlns:d="DAV:">
28  <d:activelock>
29  <d:lockscope><d:exclusive /></d:lockscope>
30  <d:locktype><d:write /></d:locktype>
31  <d:lockroot>
32    <d:href>/hi</d:href>
33  </d:lockroot>
34  <d:depth>0</d:depth>
35  <d:timeout>Second-600</d:timeout>
36  <d:locktoken>
37    <d:href>opaquelocktoken:blabla</d:href>
38  </d:locktoken>
39  <d:owner>hello</d:owner>
40
41
42</d:activelock>
43</d:root>
44', $xml);
45
46    }
47
48    function testSerializeShared() {
49
50        $lock = new LockInfo();
51        $lock->owner = 'hello';
52        $lock->token = 'blabla';
53        $lock->timeout = 600;
54        $lock->created = strtotime('2015-03-25 19:21:00');
55        $lock->scope = LockInfo::SHARED;
56        $lock->depth = 0;
57        $lock->uri = 'hi';
58
59        $prop = new LockDiscovery([$lock]);
60
61        $xml = $this->write(['{DAV:}root' => $prop]);
62
63        $this->assertXmlStringEqualsXmlString(
64'<?xml version="1.0"?>
65<d:root xmlns:d="DAV:">
66  <d:activelock>
67  <d:lockscope><d:shared /></d:lockscope>
68  <d:locktype><d:write /></d:locktype>
69  <d:lockroot>
70    <d:href>/hi</d:href>
71  </d:lockroot>
72  <d:depth>0</d:depth>
73  <d:timeout>Second-600</d:timeout>
74  <d:locktoken>
75    <d:href>opaquelocktoken:blabla</d:href>
76  </d:locktoken>
77  <d:owner>hello</d:owner>
78
79
80</d:activelock>
81</d:root>
82', $xml);
83
84    }
85
86}
87