1<?php
2
3namespace Sabre\DAV\Xml\Request;
4
5use Sabre\DAV\Xml\XmlTest;
6
7class SyncCollectionTest extends XmlTest {
8
9    function testDeserializeProp() {
10
11        $xml = '<?xml version="1.0"?>
12<d:sync-collection xmlns:d="DAV:">
13    <d:sync-token />
14    <d:sync-level>1</d:sync-level>
15    <d:prop>
16        <d:foo />
17    </d:prop>
18</d:sync-collection>
19';
20
21        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
22
23        $elem = new SyncCollectionReport();
24        $elem->syncLevel = 1;
25        $elem->properties = ['{DAV:}foo'];
26
27        $this->assertEquals($elem, $result['value']);
28
29    }
30
31
32    function testDeserializeLimit() {
33
34        $xml = '<?xml version="1.0"?>
35<d:sync-collection xmlns:d="DAV:">
36    <d:sync-token />
37    <d:sync-level>1</d:sync-level>
38    <d:prop>
39        <d:foo />
40    </d:prop>
41    <d:limit><d:nresults>5</d:nresults></d:limit>
42</d:sync-collection>
43';
44
45        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
46
47        $elem = new SyncCollectionReport();
48        $elem->syncLevel = 1;
49        $elem->properties = ['{DAV:}foo'];
50        $elem->limit = 5;
51
52        $this->assertEquals($elem, $result['value']);
53
54    }
55
56
57    function testDeserializeInfinity() {
58
59        $xml = '<?xml version="1.0"?>
60<d:sync-collection xmlns:d="DAV:">
61    <d:sync-token />
62    <d:sync-level>infinity</d:sync-level>
63    <d:prop>
64        <d:foo />
65    </d:prop>
66</d:sync-collection>
67';
68
69        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
70
71        $elem = new SyncCollectionReport();
72        $elem->syncLevel = \Sabre\DAV\Server::DEPTH_INFINITY;
73        $elem->properties = ['{DAV:}foo'];
74
75        $this->assertEquals($elem, $result['value']);
76
77    }
78
79    /**
80     * @expectedException \Sabre\DAV\Exception\BadRequest
81     */
82    function testDeserializeMissingElem() {
83
84        $xml = '<?xml version="1.0"?>
85<d:sync-collection xmlns:d="DAV:">
86    <d:sync-token />
87</d:sync-collection>
88';
89
90        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
91
92    }
93
94}
95