]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/ObjectTreeTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / ObjectTreeTest.php
1 <?php
2
3 require_once 'Sabre/TestUtil.php';
4
5 class Sabre_DAV_ObjectTreeTest extends PHPUnit_Framework_TestCase {
6
7     protected $tree;
8
9     function setup() {
10
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);
18
19     }
20
21     function teardown() {
22
23         Sabre_TestUtil::clearTempDir();
24
25     }
26
27     function testGetRootNode() {
28
29         $root = $this->tree->getNodeForPath('');
30         $this->assertInstanceOf('Sabre_DAV_FSExt_Directory',$root);
31
32     }
33
34     function testGetSubDir() {
35
36         $root = $this->tree->getNodeForPath('subdir');
37         $this->assertInstanceOf('Sabre_DAV_FSExt_Directory',$root);
38
39     }
40
41     function testCopyFile() {
42
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'));
46
47     }
48
49     /**
50      * @depends testCopyFile
51      */
52     function testCopyDirectory() {
53
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'));
58
59     }
60
61     /**
62      * @depends testCopyFile
63      */
64     function testMoveFile() {
65
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'));
70
71     }
72
73     /**
74      * @depends testMoveFile
75      */
76     function testMoveFileNewParent() {
77
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'));
82
83     }
84
85     /**
86      * @depends testCopyDirectory
87      */
88     function testMoveDirectory() {
89
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'));
95
96     }
97
98 }