4 * @covers Sabre_DAV_Tree
6 class Sabre_DAV_TreeTest extends PHPUnit_Framework_TestCase {
8 function testNodeExists() {
10 $tree = new Sabre_DAV_TreeMock();
12 $this->assertTrue($tree->nodeExists('hi'));
13 $this->assertFalse($tree->nodeExists('hello'));
19 $tree = new Sabre_DAV_TreeMock();
20 $tree->copy('hi','hi2');
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()));
30 $tree = new Sabre_DAV_TreeMock();
31 $tree->move('hi','hi2');
33 $this->assertEquals('hi2', $tree->getNodeForPath('hi')->getName());
34 $this->assertTrue($tree->getNodeForPath('hi')->isRenamed);
38 function testDeepMove() {
40 $tree = new Sabre_DAV_TreeMock();
41 $tree->move('hi/sub','hi2');
43 $this->assertArrayHasKey('hi2', $tree->getNodeForPath('')->newDirectories);
44 $this->assertTrue($tree->getNodeForPath('hi/sub')->isDeleted);
48 function testDelete() {
50 $tree = new Sabre_DAV_TreeMock();
52 $this->assertTrue($tree->getNodeForPath('hi')->isDeleted);
56 function testGetChildren() {
58 $tree = new Sabre_DAV_TreeMock();
59 $children = $tree->getChildren('');
60 $this->assertEquals(1,count($children));
61 $this->assertEquals('hi', $children[0]->getName());
67 class Sabre_DAV_TreeMock extends Sabre_DAV_Tree {
69 private $nodes = array();
71 function __construct() {
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']));
82 function getNodeForPath($path) {
84 if (isset($this->nodes[$path])) return $this->nodes[$path];
85 throw new Sabre_DAV_Exception_NotFound('item not found');
91 class Sabre_DAV_TreeDirectoryTester extends Sabre_DAV_SimpleCollection {
93 public $newDirectories = array();
94 public $newFiles = array();
95 public $isDeleted = false;
96 public $isRenamed = false;
98 function createDirectory($name) {
100 $this->newDirectories[$name] = true;
104 function createFile($name,$data = null) {
106 $this->newFiles[$name] = $data;
110 function getChild($name) {
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);
120 $this->isDeleted = true;
124 function setName($name) {
126 $this->isRenamed = true;
133 class Sabre_DAV_TreeFileTester extends Sabre_DAV_File implements Sabre_DAV_IProperties {
139 function __construct($name, $data = null) {
142 if (is_null($data)) $data = 'bla';
159 function getProperties($properties) {
161 return $this->properties;
165 function updateProperties($properties) {
167 $this->properties = $properties;