1<?php
2
3namespace Sabre\DAV;
4
5require_once 'Sabre/TestUtil.php';
6
7class ObjectTreeTest extends \PHPUnit_Framework_TestCase {
8
9    protected $tree;
10
11    function setup() {
12
13        \Sabre\TestUtil::clearTempDir();
14        mkdir(SABRE_TEMPDIR . '/root');
15        mkdir(SABRE_TEMPDIR . '/root/subdir');
16        file_put_contents(SABRE_TEMPDIR . '/root/file.txt','contents');
17        file_put_contents(SABRE_TEMPDIR . '/root/subdir/subfile.txt','subcontents');
18        $rootNode = new FSExt\Directory(SABRE_TEMPDIR . '/root');
19        $this->tree = new Tree($rootNode);
20
21    }
22
23    function teardown() {
24
25        \Sabre\TestUtil::clearTempDir();
26
27    }
28
29    function testGetRootNode() {
30
31        $root = $this->tree->getNodeForPath('');
32        $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root);
33
34    }
35
36    function testGetSubDir() {
37
38        $root = $this->tree->getNodeForPath('subdir');
39        $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root);
40
41    }
42
43    function testCopyFile() {
44
45       $this->tree->copy('file.txt','file2.txt');
46       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt'));
47       $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt'));
48
49    }
50
51    /**
52     * @depends testCopyFile
53     */
54    function testCopyDirectory() {
55
56       $this->tree->copy('subdir','subdir2');
57       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2'));
58       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
59       $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
60
61    }
62
63    /**
64     * @depends testCopyFile
65     */
66    function testMoveFile() {
67
68       $this->tree->move('file.txt','file2.txt');
69       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt'));
70       $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt'));
71       $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt'));
72
73    }
74
75    /**
76     * @depends testMoveFile
77     */
78    function testMoveFileNewParent() {
79
80       $this->tree->move('file.txt','subdir/file2.txt');
81       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir/file2.txt'));
82       $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt'));
83       $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/subdir/file2.txt'));
84
85    }
86
87    /**
88     * @depends testCopyDirectory
89     */
90    function testMoveDirectory() {
91
92       $this->tree->move('subdir','subdir2');
93       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2'));
94       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
95       $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/subdir'));
96       $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
97
98    }
99
100}
101