aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/ObjectTreeTest.php
blob: 330058b6d8b71ea4ec2ac0191d9f4d1542aa21d9 (plain) (blame)
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
<?php

namespace Sabre\DAV;

require_once 'Sabre/TestUtil.php';

class ObjectTreeTest extends \PHPUnit_Framework_TestCase {

    protected $tree;

    function setup() {

        \Sabre\TestUtil::clearTempDir();
        mkdir(SABRE_TEMPDIR . '/root');
        mkdir(SABRE_TEMPDIR . '/root/subdir');
        file_put_contents(SABRE_TEMPDIR . '/root/file.txt','contents');
        file_put_contents(SABRE_TEMPDIR . '/root/subdir/subfile.txt','subcontents');
        $rootNode = new FSExt\Directory(SABRE_TEMPDIR . '/root');
        $this->tree = new ObjectTree($rootNode);

    }

    function teardown() {

        \Sabre\TestUtil::clearTempDir();

    }

    function testGetRootNode() {

        $root = $this->tree->getNodeForPath('');
        $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root);

    }

    function testGetSubDir() {

        $root = $this->tree->getNodeForPath('subdir');
        $this->assertInstanceOf('Sabre\\DAV\\FSExt\\Directory',$root);

    }

    function testCopyFile() {

       $this->tree->copy('file.txt','file2.txt');
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt'));
       $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt'));

    }

    /**
     * @depends testCopyFile
     */
    function testCopyDirectory() {

       $this->tree->copy('subdir','subdir2');
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2'));
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
       $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));

    }

    /**
     * @depends testCopyFile
     */
    function testMoveFile() {

       $this->tree->move('file.txt','file2.txt');
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/file2.txt'));
       $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt'));
       $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/file2.txt'));

    }

    /**
     * @depends testMoveFile
     */
    function testMoveFileNewParent() {

       $this->tree->move('file.txt','subdir/file2.txt');
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir/file2.txt'));
       $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/file.txt'));
       $this->assertEquals('contents',file_get_contents(SABRE_TEMPDIR.'/root/subdir/file2.txt'));

    }

    /**
     * @depends testCopyDirectory
     */
    function testMoveDirectory() {

       $this->tree->move('subdir','subdir2');
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2'));
       $this->assertTrue(file_exists(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));
       $this->assertFalse(file_exists(SABRE_TEMPDIR.'/root/subdir'));
       $this->assertEquals('subcontents',file_get_contents(SABRE_TEMPDIR.'/root/subdir2/subfile.txt'));

    }

}