1<?php
2
3namespace Sabre\DAV\PropertyStorage;
4
5class PluginTest extends \Sabre\DAVServerTest {
6
7    protected $backend;
8    protected $plugin;
9
10    protected $setupFiles = true;
11
12    function setUp() {
13
14        parent::setUp();
15        $this->backend = new Backend\Mock();
16        $this->plugin = new Plugin(
17            $this->backend
18        );
19
20        $this->server->addPlugin($this->plugin);
21
22    }
23
24    function testGetInfo() {
25
26        $this->assertArrayHasKey(
27            'name',
28            $this->plugin->getPluginInfo()
29        );
30
31    }
32
33    function testSetProperty() {
34
35        $this->server->updateProperties('', ['{DAV:}displayname' => 'hi']);
36        $this->assertEquals([
37            '' => [
38                '{DAV:}displayname' => 'hi',
39            ]
40        ], $this->backend->data);
41
42    }
43
44    /**
45     * @depends testSetProperty
46     */
47    function testGetProperty() {
48
49        $this->testSetProperty();
50        $result = $this->server->getProperties('', ['{DAV:}displayname']);
51
52        $this->assertEquals([
53            '{DAV:}displayname' => 'hi',
54        ], $result);
55
56    }
57
58    /**
59     * @depends testSetProperty
60     */
61    function testDeleteProperty() {
62
63        $this->testSetProperty();
64        $this->server->emit('afterUnbind', ['']);
65        $this->assertEquals([],$this->backend->data);
66
67    }
68
69    function testMove() {
70
71        $this->server->tree->getNodeForPath('files')->createFile('source');
72        $this->server->updateProperties('files/source', ['{DAV:}displayname' => 'hi']);
73
74        $request = new \Sabre\HTTP\Request('MOVE', '/files/source', ['Destination' => '/files/dest']);
75        $this->assertHTTPStatus(201, $request);
76
77        $result = $this->server->getProperties('/files/dest', ['{DAV:}displayname']);
78
79        $this->assertEquals([
80            '{DAV:}displayname' => 'hi',
81        ], $result);
82
83        $this->server->tree->getNodeForPath('files')->createFile('source');
84        $result = $this->server->getProperties('/files/source', ['{DAV:}displayname']);
85
86        $this->assertEquals([], $result);
87
88    }
89
90    /**
91     * @depends testDeleteProperty
92     */
93    function testSetPropertyInFilteredPath() {
94
95        $this->plugin->pathFilter = function($path) {
96
97            return false;
98
99        };
100
101        $this->server->updateProperties('', ['{DAV:}displayname' => 'hi']);
102        $this->assertEquals([], $this->backend->data);
103
104    }
105
106    /**
107     * @depends testSetPropertyInFilteredPath
108     */
109    function testGetPropertyInFilteredPath() {
110
111        $this->testSetPropertyInFilteredPath();
112        $result = $this->server->getProperties('', ['{DAV:}displayname']);
113
114        $this->assertEquals([], $result);
115    }
116
117}
118