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