3 require_once 'Sabre/TestUtil.php';
5 class Sabre_DAV_ObjectTreeTest extends PHPUnit_Framework_TestCase {
11 Sabre_TestUtil::clearTempDir();
12 mkdir(SABRE_TEMPDIR . '/root');
13 mkdir(SABRE_TEMPDIR . '/root/subdir');
14 file_put_contents(SABRE_TEMPDIR . '/root/file.txt','contents');
15 file_put_contents(SABRE_TEMPDIR . '/root/subdir/subfile.txt','subcontents');
16 $rootNode = new Sabre_DAV_FSExt_Directory(SABRE_TEMPDIR . '/root');
17 $this->tree = new Sabre_DAV_ObjectTree($rootNode);
23 Sabre_TestUtil::clearTempDir();
27 function testGetRootNode() {
29 $root = $this->tree->getNodeForPath('');
30 $this->assertInstanceOf('Sabre_DAV_FSExt_Directory',$root);
34 function testGetSubDir() {
36 $root = $this->tree->getNodeForPath('subdir');
37 $this->assertInstanceOf('Sabre_DAV_FSExt_Directory',$root);
41 function testCopyFile() {
43 $this->tree->copy('file.txt','file2.txt');
44 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt'));
45 $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt'));
50 * @depends testCopyFile
52 function testCopyDirectory() {
54 $this->tree->copy('subdir','subdir2');
55 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2'));
56 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
57 $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
62 * @depends testCopyFile
64 function testMoveFile() {
66 $this->tree->move('file.txt','file2.txt');
67 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt'));
68 $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt'));
69 $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt'));
74 * @depends testMoveFile
76 function testMoveFileNewParent() {
78 $this->tree->move('file.txt','subdir/file2.txt');
79 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir/file2.txt'));
80 $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt'));
81 $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/subdir/file2.txt'));
86 * @depends testCopyDirectory
88 function testMoveDirectory() {
90 $this->tree->move('subdir','subdir2');
91 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2'));
92 $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
93 $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/subdir'));
94 $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));