27
27
use OCA \DAV \Connector \Sabre \Directory ;
28
28
use OCA \DAV \Upload \ChunkingPlugin ;
29
29
use OCA \DAV \Upload \FutureFile ;
30
+ use Sabre \DAV \Exception \NotFound ;
30
31
use Sabre \HTTP \RequestInterface ;
31
32
use Sabre \HTTP \ResponseInterface ;
32
33
use Test \TestCase ;
@@ -77,7 +78,7 @@ protected function setUp(): void {
77
78
public function testBeforeMoveFutureFileSkip () {
78
79
$ node = $ this ->createMock (Directory::class);
79
80
80
- $ this ->tree ->expects ($ this ->any ( ))
81
+ $ this ->tree ->expects ($ this ->at ( 0 ))
81
82
->method ('getNodeForPath ' )
82
83
->with ('source ' )
83
84
->willReturn ($ node );
@@ -87,16 +88,39 @@ public function testBeforeMoveFutureFileSkip() {
87
88
$ this ->assertNull ($ this ->plugin ->beforeMove ('source ' , 'target ' ));
88
89
}
89
90
91
+ public function testBeforeMoveDestinationIsDirectory () {
92
+ $ this ->expectException (\Sabre \DAV \Exception \BadRequest::class);
93
+ $ this ->expectExceptionMessage ('The given destination target is a directory. ' );
94
+
95
+ $ sourceNode = $ this ->createMock (FutureFile::class);
96
+ $ targetNode = $ this ->createMock (Directory::class);
97
+
98
+ $ this ->tree ->expects ($ this ->at (0 ))
99
+ ->method ('getNodeForPath ' )
100
+ ->with ('source ' )
101
+ ->willReturn ($ sourceNode );
102
+ $ this ->tree ->expects ($ this ->at (1 ))
103
+ ->method ('getNodeForPath ' )
104
+ ->with ('target ' )
105
+ ->willReturn ($ targetNode );
106
+
107
+ $ this ->assertNull ($ this ->plugin ->beforeMove ('source ' , 'target ' ));
108
+ }
109
+
90
110
public function testBeforeMoveFutureFileSkipNonExisting () {
91
111
$ sourceNode = $ this ->createMock (FutureFile::class);
92
112
$ sourceNode ->expects ($ this ->once ())
93
113
->method ('getSize ' )
94
114
->willReturn (4 );
95
115
96
- $ this ->tree ->expects ($ this ->any ( ))
116
+ $ this ->tree ->expects ($ this ->at ( 0 ))
97
117
->method ('getNodeForPath ' )
98
118
->with ('source ' )
99
119
->willReturn ($ sourceNode );
120
+ $ this ->tree ->expects ($ this ->at (1 ))
121
+ ->method ('getNodeForPath ' )
122
+ ->with ('target ' )
123
+ ->willThrowException (new NotFound ());
100
124
$ this ->tree ->expects ($ this ->any ())
101
125
->method ('nodeExists ' )
102
126
->with ('target ' )
@@ -117,10 +141,14 @@ public function testBeforeMoveFutureFileMoveIt() {
117
141
->method ('getSize ' )
118
142
->willReturn (4 );
119
143
120
- $ this ->tree ->expects ($ this ->any ( ))
144
+ $ this ->tree ->expects ($ this ->at ( 0 ))
121
145
->method ('getNodeForPath ' )
122
146
->with ('source ' )
123
147
->willReturn ($ sourceNode );
148
+ $ this ->tree ->expects ($ this ->at (1 ))
149
+ ->method ('getNodeForPath ' )
150
+ ->with ('target ' )
151
+ ->willThrowException (new NotFound ());
124
152
$ this ->tree ->expects ($ this ->any ())
125
153
->method ('nodeExists ' )
126
154
->with ('target ' )
@@ -143,7 +171,7 @@ public function testBeforeMoveFutureFileMoveIt() {
143
171
$ this ->assertFalse ($ this ->plugin ->beforeMove ('source ' , 'target ' ));
144
172
}
145
173
146
-
174
+
147
175
public function testBeforeMoveSizeIsWrong () {
148
176
$ this ->expectException (\Sabre \DAV \Exception \BadRequest::class);
149
177
$ this ->expectExceptionMessage ('Chunks on server do not sum up to 4 but to 3 bytes ' );
@@ -153,10 +181,14 @@ public function testBeforeMoveSizeIsWrong() {
153
181
->method ('getSize ' )
154
182
->willReturn (3 );
155
183
156
- $ this ->tree ->expects ($ this ->any ( ))
184
+ $ this ->tree ->expects ($ this ->at ( 0 ))
157
185
->method ('getNodeForPath ' )
158
186
->with ('source ' )
159
187
->willReturn ($ sourceNode );
188
+ $ this ->tree ->expects ($ this ->at (1 ))
189
+ ->method ('getNodeForPath ' )
190
+ ->with ('target ' )
191
+ ->willThrowException (new NotFound ());
160
192
$ this ->request ->expects ($ this ->once ())
161
193
->method ('getHeader ' )
162
194
->with ('OC-Total-Length ' )
0 commit comments