]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/FSExt/NodeTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / FSExt / NodeTest.php
1 <?php
2
3 require_once 'Sabre/TestUtil.php';
4
5 class Sabre_DAV_FSExt_NodeTest extends PHPUnit_Framework_TestCase {
6
7     function setUp() {
8
9         mkdir(SABRE_TEMPDIR . '/dir');
10         file_put_contents(SABRE_TEMPDIR . '/dir/file.txt', 'Contents');
11         file_put_contents(SABRE_TEMPDIR . '/dir/file2.txt', 'Contents2');
12
13     }
14
15     function tearDown() {
16
17         Sabre_TestUtil::clearTempDir();
18
19     }
20
21     function testUpdateProperties() {
22
23         $file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
24         $properties = array(
25             '{http://sabredav.org/NS/2010}test1' => 'foo',
26             '{http://sabredav.org/NS/2010}test2' => 'bar',
27         );
28
29         $result = $file->updateProperties($properties);
30         $expected = true;
31
32         $this->assertEquals($expected, $result);
33
34         $getProperties = $file->getProperties(array_keys($properties));
35
36         $this->assertEquals($properties, $getProperties);
37
38     }
39
40     /**
41      * @depends testUpdateProperties
42      */
43     function testUpdatePropertiesAgain() {
44
45         $file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
46         $mutations = array(
47             '{http://sabredav.org/NS/2010}test1' => 'foo',
48             '{http://sabredav.org/NS/2010}test2' => 'bar',
49         );
50
51         $result = $file->updateProperties($mutations);
52
53         $this->assertEquals(true, $result);
54
55         $mutations = array(
56             '{http://sabredav.org/NS/2010}test1' => 'foo',
57             '{http://sabredav.org/NS/2010}test3' => 'baz',
58         );
59
60         $result = $file->updateProperties($mutations);
61
62         $this->assertEquals(true, $result);
63     }
64
65     /**
66      * @depends testUpdateProperties
67      */
68     function testUpdatePropertiesDelete() {
69
70         $file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
71
72         $mutations = array(
73             '{http://sabredav.org/NS/2010}test1' => 'foo',
74             '{http://sabredav.org/NS/2010}test2' => 'bar',
75         );
76
77         $result = $file->updateProperties($mutations);
78
79         $this->assertEquals(true, $result);
80
81         $mutations = array(
82             '{http://sabredav.org/NS/2010}test1' => null,
83             '{http://sabredav.org/NS/2010}test3' => null
84         );
85
86         $result = $file->updateProperties($mutations);
87
88         $this->assertEquals(true, $result);
89
90         $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
91
92         $this->assertEquals(array(
93             '{http://sabredav.org/NS/2010}test2' => 'bar',
94         ), $properties);
95     }
96
97     /**
98      * @depends testUpdateProperties
99      */
100     function testUpdatePropertiesMove() {
101
102         $file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
103
104         $mutations = array(
105             '{http://sabredav.org/NS/2010}test1' => 'foo',
106             '{http://sabredav.org/NS/2010}test2' => 'bar',
107         );
108
109         $result = $file->updateProperties($mutations);
110
111         $this->assertEquals(true, $result);
112
113         $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
114
115         $this->assertEquals(array(
116             '{http://sabredav.org/NS/2010}test1' => 'foo',
117             '{http://sabredav.org/NS/2010}test2' => 'bar',
118         ), $properties);
119
120         // Renaming
121         $file->setName('file3.txt');
122
123         $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt'));
124         $this->assertTrue(file_exists(SABRE_TEMPDIR . '/dir/file3.txt'));
125         $this->assertEquals('file3.txt',$file->getName());
126
127         $newFile = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file3.txt');
128         $this->assertEquals('file3.txt',$newFile->getName());
129
130         $properties = $newFile->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
131
132         $this->assertEquals(array(
133             '{http://sabredav.org/NS/2010}test1' => 'foo',
134             '{http://sabredav.org/NS/2010}test2' => 'bar',
135         ), $properties);
136     }
137
138     /**
139      * @depends testUpdatePropertiesMove
140      */
141     function testUpdatePropertiesDeleteBleed() {
142
143         $file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
144         $mutations = array(
145             '{http://sabredav.org/NS/2010}test1' => 'foo',
146             '{http://sabredav.org/NS/2010}test2' => 'bar',
147         );
148
149         $result = $file->updateProperties($mutations);
150
151         $this->assertEquals(true, $result);
152
153         $properties = $file->getProperties(array('{http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
154
155         $this->assertEquals(array(
156             '{http://sabredav.org/NS/2010}test1' => 'foo',
157             '{http://sabredav.org/NS/2010}test2' => 'bar',
158         ), $properties);
159
160         // Deleting
161         $file->delete();
162
163         $this->assertFalse(file_exists(SABRE_TEMPDIR . '/dir/file.txt'));
164
165         // Creating it again
166         file_put_contents(SABRE_TEMPDIR . '/dir/file.txt','New Contents');
167         $file = new Sabre_DAV_FSExt_File(SABRE_TEMPDIR . '/dir/file.txt');
168
169         $properties = $file->getProperties(array('http://sabredav.org/NS/2010}test1','{http://sabredav.org/NS/2010}test2','{http://sabredav.org/NS/2010}test3'));
170
171         $this->assertEquals(array(), $properties);
172
173     }
174
175 }