]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/TreeTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / TreeTest.php
1 <?php
2
3 /**
4  * @covers Sabre_DAV_Tree
5  */
6 class Sabre_DAV_TreeTest extends PHPUnit_Framework_TestCase {
7
8     function testNodeExists() {
9
10         $tree = new Sabre_DAV_TreeMock();
11
12         $this->assertTrue($tree->nodeExists('hi'));
13         $this->assertFalse($tree->nodeExists('hello'));
14
15     }
16
17     function testCopy() {
18
19         $tree = new Sabre_DAV_TreeMock();
20         $tree->copy('hi','hi2');
21
22         $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories);
23         $this->assertEquals('foobar', $tree->getNodeForPath('hi/file')->get());
24         $this->assertEquals(array('test1'=>'value'), $tree->getNodeForPath('hi/file')->getProperties(array()));
25
26     }
27
28     function testMove() {
29
30         $tree = new Sabre_DAV_TreeMock();
31         $tree->move('hi','hi2');
32
33         $this->assertEquals('hi2', $tree->getNodeForPath('hi')->getName());
34         $this->assertTrue($tree->getNodeForPath('hi')->isRenamed);
35
36     }
37
38     function testDeepMove() {
39
40         $tree = new Sabre_DAV_TreeMock();
41         $tree->move('hi/sub','hi2');
42
43         $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories);
44         $this->assertTrue($tree->getNodeForPath('hi/sub')->isDeleted);
45
46     }
47
48     function testDelete() {
49
50         $tree = new Sabre_DAV_TreeMock();
51         $tree->delete('hi');
52         $this->assertTrue($tree->getNodeForPath('hi')->isDeleted);
53
54     }
55
56     function testGetChildren() {
57
58         $tree = new Sabre_DAV_TreeMock();
59         $children = $tree->getChildren('');
60         $this->assertEquals(1,count($children));
61         $this->assertEquals('hi', $children[0]->getName());
62
63     }
64
65 }
66
67 class Sabre_DAV_TreeMock extends Sabre_DAV_Tree {
68
69     private $nodes = array();
70
71     function __construct() {
72
73         $this->nodes['hi/sub'] = new Sabre_DAV_TreeDirectoryTester('sub');
74         $this->nodes['hi/file'] = new Sabre_DAV_TreeFileTester('file');
75         $this->nodes['hi/file']->properties = array('test1' => 'value');
76         $this->nodes['hi/file']->data = 'foobar';
77         $this->nodes['hi'] = new Sabre_DAV_TreeDirectoryTester('hi',array($this->nodes['hi/sub'], $this->nodes['hi/file']));
78         $this->nodes[''] = new Sabre_DAV_TreeDirectoryTester('hi', array($this->nodes['hi']));
79
80     }
81
82     function getNodeForPath($path) {
83
84         if (isset($this->nodes[$path])) return $this->nodes[$path];
85         throw new Sabre_DAV_Exception_NotFound('item not found');
86
87     }
88
89 }
90
91 class Sabre_DAV_TreeDirectoryTester extends Sabre_DAV_SimpleCollection {
92
93     public $newDirectories = array();
94     public $newFiles = array();
95     public $isDeleted = false;
96     public $isRenamed = false;
97
98     function createDirectory($name) {
99
100         $this->newDirectories[$name] = true;
101
102     }
103
104     function createFile($name,$data = null) {
105
106         $this->newFiles[$name] = $data;
107
108     }
109
110     function getChild($name) {
111
112         if (isset($this->newDirectories[$name])) return new Sabre_DAV_TreeDirectoryTester($name);
113         if (isset($this->newFiles[$name])) return new Sabre_DAV_TreeFileTester($name, $this->newFiles[$name]);
114         return parent::getChild($name);
115
116     }
117
118     function delete() {
119
120         $this->isDeleted = true;
121
122     }
123
124     function setName($name) {
125
126         $this->isRenamed = true;
127         $this->name = $name;
128
129     }
130
131 }
132
133 class Sabre_DAV_TreeFileTester extends Sabre_DAV_File implements Sabre_DAV_IProperties {
134
135     public $name;
136     public $data;
137     public $properties;
138
139     function __construct($name, $data = null) {
140
141         $this->name = $name;
142         if (is_null($data)) $data = 'bla';
143         $this->data = $data;
144
145     }
146
147     function getName() {
148
149         return $this->name;
150
151     }
152
153     function get() {
154
155         return $this->data;
156
157     }
158
159     function getProperties($properties) {
160
161         return $this->properties;
162
163     }
164
165     function updateProperties($properties) {
166
167         $this->properties = $properties;
168         return true;
169
170     }
171
172 }
173