1<?php
2
3namespace Sabre\DAV;
4
5class PropFindTest extends \PHPUnit_Framework_TestCase {
6
7    function testHandle() {
8
9        $propFind = new PropFind('foo', ['{DAV:}displayname']);
10        $propFind->handle('{DAV:}displayname', 'foobar');
11
12        $this->assertEquals([
13            200 => ['{DAV:}displayname' => 'foobar'],
14            404 => [],
15        ], $propFind->getResultForMultiStatus());
16
17    }
18
19    function testHandleCallBack() {
20
21        $propFind = new PropFind('foo', ['{DAV:}displayname']);
22        $propFind->handle('{DAV:}displayname', function() { return 'foobar'; });
23
24        $this->assertEquals([
25            200 => ['{DAV:}displayname' => 'foobar'],
26            404 => [],
27        ], $propFind->getResultForMultiStatus());
28
29    }
30
31    function testAllPropDefaults() {
32
33        $propFind = new PropFind('foo', ['{DAV:}displayname'], 0, PropFind::ALLPROPS);
34
35        $this->assertEquals([
36            200 => [],
37        ], $propFind->getResultForMultiStatus());
38
39    }
40
41    function testSet() {
42
43        $propFind = new PropFind('foo', ['{DAV:}displayname']);
44        $propFind->set('{DAV:}displayname', 'bar');
45
46        $this->assertEquals([
47            200 => ['{DAV:}displayname' => 'bar'],
48            404 => [],
49        ], $propFind->getResultForMultiStatus());
50
51    }
52
53    function testSetAllpropCustom() {
54
55        $propFind = new PropFind('foo', ['{DAV:}displayname'], 0, PropFind::ALLPROPS);
56        $propFind->set('{DAV:}customproperty', 'bar');
57
58        $this->assertEquals([
59            200 => ['{DAV:}customproperty' => 'bar'],
60        ], $propFind->getResultForMultiStatus());
61
62    }
63
64    function testSetUnset() {
65
66        $propFind = new PropFind('foo', ['{DAV:}displayname']);
67        $propFind->set('{DAV:}displayname', 'bar');
68        $propFind->set('{DAV:}displayname', null);
69
70        $this->assertEquals([
71            200 => [],
72            404 => ['{DAV:}displayname' => null],
73        ], $propFind->getResultForMultiStatus());
74
75    }
76}
77