ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TreeTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\DAV;
4 
6 
7  function testNodeExists() {
8 
9  $tree = new TreeMock();
10 
11  $this->assertTrue($tree->nodeExists('hi'));
12  $this->assertFalse($tree->nodeExists('hello'));
13 
14  }
15 
16  function testCopy() {
17 
18  $tree = new TreeMock();
19  $tree->copy('hi', 'hi2');
20 
21  $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories);
22  $this->assertEquals('foobar', $tree->getNodeForPath('hi/file')->get());
23  $this->assertEquals(['test1' => 'value'], $tree->getNodeForPath('hi/file')->getProperties([]));
24 
25  }
26 
27  function testMove() {
28 
29  $tree = new TreeMock();
30  $tree->move('hi', 'hi2');
31 
32  $this->assertEquals('hi2', $tree->getNodeForPath('hi')->getName());
33  $this->assertTrue($tree->getNodeForPath('hi')->isRenamed);
34 
35  }
36 
37  function testDeepMove() {
38 
39  $tree = new TreeMock();
40  $tree->move('hi/sub', 'hi2');
41 
42  $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories);
43  $this->assertTrue($tree->getNodeForPath('hi/sub')->isDeleted);
44 
45  }
46 
47  function testDelete() {
48 
49  $tree = new TreeMock();
50  $tree->delete('hi');
51  $this->assertTrue($tree->getNodeForPath('hi')->isDeleted);
52 
53  }
54 
55  function testGetChildren() {
56 
57  $tree = new TreeMock();
58  $children = $tree->getChildren('');
59  $this->assertEquals(2, count($children));
60  $this->assertEquals('hi', $children[0]->getName());
61 
62  }
63 
64  function testGetMultipleNodes() {
65 
66  $tree = new TreeMock();
67  $result = $tree->getMultipleNodes(['hi/sub', 'hi/file']);
68  $this->assertArrayHasKey('hi/sub', $result);
69  $this->assertArrayHasKey('hi/file', $result);
70 
71  $this->assertEquals('sub', $result['hi/sub']->getName());
72  $this->assertEquals('file', $result['hi/file']->getName());
73 
74  }
75  function testGetMultipleNodes2() {
76 
77  $tree = new TreeMock();
78  $result = $tree->getMultipleNodes(['multi/1', 'multi/2']);
79  $this->assertArrayHasKey('multi/1', $result);
80  $this->assertArrayHasKey('multi/2', $result);
81 
82  }
83 
84 }
85 
86 class TreeMock extends Tree {
87 
88  private $nodes = [];
89 
90  function __construct() {
91 
92  $file = new TreeFileTester('file');
93  $file->properties = ['test1' => 'value'];
94  $file->data = 'foobar';
95 
96  parent::__construct(
97  new TreeDirectoryTester('root', [
98  new TreeDirectoryTester('hi', [
99  new TreeDirectoryTester('sub'),
100  $file,
101  ]),
102  new TreeMultiGetTester('multi', [
103  new TreeFileTester('1'),
104  new TreeFileTester('2'),
105  new TreeFileTester('3'),
106  ])
107  ])
108  );
109 
110  }
111 
112 }
113 
115 
116  public $newDirectories = [];
117  public $newFiles = [];
118  public $isDeleted = false;
119  public $isRenamed = false;
120 
121  function createDirectory($name) {
122 
123  $this->newDirectories[$name] = true;
124 
125  }
126 
127  function createFile($name, $data = null) {
128 
129  $this->newFiles[$name] = $data;
130 
131  }
132 
133  function getChild($name) {
134 
135  if (isset($this->newDirectories[$name])) return new self($name);
136  if (isset($this->newFiles[$name])) return new TreeFileTester($name, $this->newFiles[$name]);
137  return parent::getChild($name);
138 
139  }
140 
141  function childExists($name) {
142 
143  return !!$this->getChild($name);
144 
145  }
146 
147  function delete() {
148 
149  $this->isDeleted = true;
150 
151  }
152 
153  function setName($name) {
154 
155  $this->isRenamed = true;
156  $this->name = $name;
157 
158  }
159 
160 }
161 
162 class TreeFileTester extends File implements IProperties {
163 
164  public $name;
165  public $data;
166  public $properties;
167 
168  function __construct($name, $data = null) {
169 
170  $this->name = $name;
171  if (is_null($data)) $data = 'bla';
172  $this->data = $data;
173 
174  }
175 
176  function getName() {
177 
178  return $this->name;
179 
180  }
181 
182  function get() {
183 
184  return $this->data;
185 
186  }
187 
188  function getProperties($properties) {
189 
190  return $this->properties;
191 
192  }
193 
206  function propPatch(PropPatch $propPatch) {
207 
208  $this->properties = $propPatch->getMutations();
209  $propPatch->setRemainingResultCode(200);
210 
211  }
212 
213 }
214 
216 
226  function getMultipleChildren(array $paths) {
227 
228  $result = [];
229  foreach ($paths as $path) {
230  try {
231  $child = $this->getChild($path);
232  $result[] = $child;
233  } catch (Exception\NotFound $e) {
234  // Do nothing
235  }
236  }
237 
238  return $result;
239 
240  }
241 
242 }
$path
Definition: aliased.php:25
This class represents a set of properties that are going to be updated.
Definition: PropPatch.php:20
$result
if($argc< 2) $paths
Definition: migrateto20.php:44
getChild($name)
Returns a specific child node, referenced by its name.
Definition: TreeTest.php:133
createFile($name, $data=null)
Creates a new file in the directory.
Definition: TreeTest.php:127
getProperties($properties)
Returns a list of properties for this nodes.
Definition: TreeTest.php:188
setRemainingResultCode($resultCode)
Sets the result code for all properties that did not have a result yet.
Definition: PropPatch.php:168
createDirectory($name)
Creates a new subdirectory.
Definition: TreeTest.php:121
__construct($name, $data=null)
Definition: TreeTest.php:168
childExists($name)
Checks if a child-node with the specified name exists.
Definition: TreeTest.php:141
setName($name)
Renames the node.
Definition: TreeTest.php:153
getMutations()
Returns the full list of mutations.
Definition: PropPatch.php:367
getName()
Returns the name of the node.
Definition: TreeTest.php:176
$this data['403_header']
IProperties interface.
Definition: IProperties.php:14
propPatch(PropPatch $propPatch)
Updates properties on this node.
Definition: TreeTest.php:206
getMultipleChildren(array $paths)
This method receives a list of paths in it&#39;s first argument.
Definition: TreeTest.php:226
The tree object is responsible for basic tree operations.
Definition: Tree.php:17
$data
Definition: bench.php:6