1<?php
2
3namespace Sabre\DAV;
4
5class SyncTokenPropertyTest extends \Sabre\DAVServerTest {
6
7    /**
8     * The assumption in these tests is that a PROPFIND is going on, and to
9     * fetch the sync-token, the event handler is just able to use the existing
10     * result.
11     *
12     * @param string $name
13     * @param mixed $value
14     *
15     * @dataProvider data
16     */
17    function testAlreadyThere1($name, $value) {
18
19        $propFind = new PropFind('foo', [
20            '{http://calendarserver.org/ns/}getctag',
21            $name,
22        ]);
23
24        $propFind->set($name, $value);
25        $corePlugin = new CorePlugin();
26        $corePlugin->propFindLate($propFind, new SimpleCollection('hi'));
27
28        $this->assertEquals("hello", $propFind->get('{http://calendarserver.org/ns/}getctag'));
29
30    }
31
32    /**
33     * In these test-cases, the plugin is forced to do a local propfind to
34     * fetch the items.
35     *
36     * @param string $name
37     * @param mixed $value
38     *
39     * @dataProvider data
40     */
41    function testRefetch($name, $value) {
42
43        $this->server->tree = new Tree(
44            new SimpleCollection('root', [
45                new Mock\PropertiesCollection(
46                    'foo',
47                    [],
48                    [$name => $value]
49                )
50            ])
51        );
52        $propFind = new PropFind('foo', [
53            '{http://calendarserver.org/ns/}getctag',
54            $name,
55        ]);
56
57        $corePlugin = $this->server->getPlugin('core');
58        $corePlugin->propFindLate($propFind, new SimpleCollection('hi'));
59
60        $this->assertEquals("hello", $propFind->get('{http://calendarserver.org/ns/}getctag'));
61
62    }
63
64    function testNoData() {
65
66        $this->server->tree = new Tree(
67            new SimpleCollection('root', [
68                new Mock\PropertiesCollection(
69                    'foo',
70                    [],
71                    []
72                )
73            ])
74        );
75
76        $propFind = new PropFind('foo', [
77            '{http://calendarserver.org/ns/}getctag',
78        ]);
79
80        $corePlugin = $this->server->getPlugin('core');
81        $corePlugin->propFindLate($propFind, new SimpleCollection('hi'));
82
83        $this->assertNull($propFind->get('{http://calendarserver.org/ns/}getctag'));
84
85    }
86
87    function data() {
88
89        return [
90            [
91                '{http://sabredav.org/ns}sync-token',
92                "hello"
93            ],
94            [
95                '{DAV:}sync-token',
96                "hello"
97            ],
98            [
99                '{DAV:}sync-token',
100                new Xml\Property\Href(Sync\Plugin::SYNCTOKEN_PREFIX . "hello", false)
101            ]
102        ];
103
104    }
105
106}
107