In FileBackend:
[lhc/web/wiklou.git] / tests / phpunit / includes / filerepo / FileBackendTest.php
1 <?php
2
3 // @TODO: fix empty dir leakage
4 class FileBackendTest extends MediaWikiTestCase {
5 private $backend, $multiBackend;
6 private $filesToPrune, $pathsToPrune;
7
8 function setUp() {
9 parent::setUp();
10 $tmpDir = wfTempDir() . '/' . time() . '-' . mt_rand();
11 $this->singleBackend = new FSFileBackend( array(
12 'name' => 'localtesting',
13 'lockManager' => 'fsLockManager',
14 'containerPaths' => array(
15 'cont1' => "$tmpDir/localtesting/cont1",
16 'cont2' => "$tmpDir/localtesting/cont2" )
17 ) );
18 $this->multiBackend = new FileBackendMultiWrite( array(
19 'name' => 'localtesting',
20 'lockManager' => 'fsLockManager',
21 'backends' => array(
22 array(
23 'name' => 'localmutlitesting1',
24 'class' => 'FSFileBackend',
25 'lockManager' => 'nullLockManager',
26 'containerPaths' => array(
27 'cont1' => "$tmpDir/localtestingmulti1/cont1",
28 'cont2' => "$tmpDir/localtestingmulti1/cont2" ),
29 'isMultiMaster' => false
30 ),
31 array(
32 'name' => 'localmutlitesting2',
33 'class' => 'FSFileBackend',
34 'lockManager' => 'nullLockManager',
35 'containerPaths' => array(
36 'cont1' => "$tmpDir/localtestingmulti2/cont1",
37 'cont2' => "$tmpDir/localtestingmulti2/cont2" ),
38 'isMultiMaster' => true
39 )
40 )
41 ) );
42 $this->filesToPrune = $this->pathsToPrune = array();
43 }
44
45 private function baseStorePath() {
46 return 'mwstore://localtesting';
47 }
48
49 private function backendClass() {
50 return get_class( $this->backend );
51 }
52
53 /**
54 * @dataProvider provider_testStore
55 */
56 public function testStore( $op, $source, $dest ) {
57 $this->filesToPrune[] = $source;
58 $this->pathsToPrune[] = $dest;
59
60 $this->backend = $this->singleBackend;
61 $this->doTestStore( $op, $source, $dest );
62 $this->tearDownFiles();
63
64 $this->backend = $this->multiBackend;
65 $this->doTestStore( $op, $source, $dest );
66 $this->tearDownFiles();
67 }
68
69 function doTestStore( $op, $source, $dest ) {
70 $backendName = $this->backendClass();
71
72 file_put_contents( $source, "Unit test file" );
73 $status = $this->backend->doOperation( $op );
74
75 $this->assertEquals( array(), $status->errors,
76 "Store from $source to $dest succeeded without warnings ($backendName)." );
77 $this->assertEquals( true, $status->isOK(),
78 "Store from $source to $dest succeeded ($backendName)." );
79 $this->assertEquals( true, file_exists( $source ),
80 "Source file $source still exists ($backendName)." );
81 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
82 "Destination file $dest exists ($backendName)." );
83
84 $this->assertEquals( filesize( $source ),
85 $this->backend->getFileSize( array( 'src' => $dest ) ),
86 "Destination file $dest has correct size ($backendName)." );
87
88 $props1 = FSFile::getPropsFromPath( $source );
89 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
90 $this->assertEquals( $props1, $props2,
91 "Source and destination have the same props ($backendName)." );
92 }
93
94 public function provider_testStore() {
95 $cases = array();
96
97 $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath();
98 $toPath = $this->baseStorePath() . '/cont1/fun/obj1.txt';
99 $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath );
100 $cases[] = array(
101 $op, // operation
102 $tmpName, // source
103 $toPath, // dest
104 );
105
106 $op['overwriteDest'] = true;
107 $cases[] = array(
108 $op, // operation
109 $tmpName, // source
110 $toPath, // dest
111 );
112
113 return $cases;
114 }
115
116 /**
117 * @dataProvider provider_testCopy
118 */
119 public function testCopy( $op, $source, $dest ) {
120 $this->pathsToPrune[] = $source;
121 $this->pathsToPrune[] = $dest;
122
123 $this->backend = $this->singleBackend;
124 $this->doTestCopy( $op, $source, $dest );
125 $this->tearDownFiles();
126
127 $this->backend = $this->multiBackend;
128 $this->doTestCopy( $op, $source, $dest );
129 $this->tearDownFiles();
130 }
131
132 function doTestCopy( $op, $source, $dest ) {
133 $backendName = $this->backendClass();
134
135 $status = $this->backend->doOperation(
136 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
137 $this->assertEquals( true, $status->isOK(),
138 "Creation of file at $source succeeded ($backendName)." );
139
140 $status = $this->backend->doOperation( $op );
141 $this->assertEquals( array(), $status->errors,
142 "Copy from $source to $dest succeeded without warnings ($backendName)." );
143 $this->assertEquals( true, $status->isOK(),
144 "Copy from $source to $dest succeeded ($backendName)." );
145 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $source ) ),
146 "Source file $source still exists ($backendName)." );
147 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
148 "Destination file $dest exists after copy ($backendName)." );
149
150 $this->assertEquals(
151 $this->backend->getFileSize( array( 'src' => $source ) ),
152 $this->backend->getFileSize( array( 'src' => $dest ) ),
153 "Destination file $dest has correct size ($backendName)." );
154
155 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
156 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
157 $this->assertEquals( $props1, $props2,
158 "Source and destination have the same props ($backendName)." );
159 }
160
161 public function provider_testCopy() {
162 $cases = array();
163
164 $source = $this->baseStorePath() . '/cont1/file.txt';
165 $dest = $this->baseStorePath() . '/cont2/fileMoved.txt';
166
167 $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest );
168 $cases[] = array(
169 $op, // operation
170 $source, // source
171 $dest, // dest
172 );
173
174 $op['overwriteDest'] = true;
175 $cases[] = array(
176 $op, // operation
177 $source, // source
178 $dest, // dest
179 );
180
181 return $cases;
182 }
183
184 /**
185 * @dataProvider provider_testMove
186 */
187 public function testMove( $op, $source, $dest ) {
188 $this->pathsToPrune[] = $source;
189 $this->pathsToPrune[] = $dest;
190
191 $this->backend = $this->singleBackend;
192 $this->doTestMove( $op, $source, $dest );
193 $this->tearDownFiles();
194
195 $this->backend = $this->multiBackend;
196 $this->doTestMove( $op, $source, $dest );
197 $this->tearDownFiles();
198 }
199
200 public function doTestMove( $op, $source, $dest ) {
201 $backendName = $this->backendClass();
202
203 $status = $this->backend->doOperation(
204 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
205 $this->assertEquals( true, $status->isOK(),
206 "Creation of file at $source succeeded ($backendName)." );
207
208 $status = $this->backend->doOperation( $op );
209 $this->assertEquals( array(), $status->errors,
210 "Move from $source to $dest succeeded without warnings ($backendName)." );
211 $this->assertEquals( true, $status->isOK(),
212 "Move from $source to $dest succeeded ($backendName)." );
213 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
214 "Source file $source does not still exists ($backendName)." );
215 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
216 "Destination file $dest exists after move ($backendName)." );
217
218 $this->assertNotEquals(
219 $this->backend->getFileSize( array( 'src' => $source ) ),
220 $this->backend->getFileSize( array( 'src' => $dest ) ),
221 "Destination file $dest has correct size ($backendName)." );
222
223 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
224 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
225 $this->assertEquals( false, $props1['fileExists'],
226 "Source file does not exist accourding to props ($backendName)." );
227 $this->assertEquals( true, $props2['fileExists'],
228 "Destination file exists accourding to props ($backendName)." );
229 }
230
231 public function provider_testMove() {
232 $cases = array();
233
234 $source = $this->baseStorePath() . '/cont1/file.txt';
235 $dest = $this->baseStorePath() . '/cont2/fileMoved.txt';
236
237 $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest );
238 $cases[] = array(
239 $op, // operation
240 $source, // source
241 $dest, // dest
242 );
243
244 $op['overwriteDest'] = true;
245 $cases[] = array(
246 $op, // operation
247 $source, // source
248 $dest, // dest
249 );
250
251 return $cases;
252 }
253
254 /**
255 * @dataProvider provider_testDelete
256 */
257 public function testDelete( $op, $source, $withSource, $okStatus ) {
258 $this->pathsToPrune[] = $source;
259
260 $this->backend = $this->singleBackend;
261 $this->doTestDelete( $op, $source, $withSource, $okStatus );
262 $this->tearDownFiles();
263
264 $this->backend = $this->multiBackend;
265 $this->doTestDelete( $op, $source, $withSource, $okStatus );
266 $this->tearDownFiles();
267 }
268
269 public function doTestDelete( $op, $source, $withSource, $okStatus ) {
270 $backendName = $this->backendClass();
271
272 if ( $withSource ) {
273 $status = $this->backend->doOperation(
274 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
275 $this->assertEquals( true, $status->isOK(),
276 "Creation of file at $source succeeded ($backendName)." );
277 }
278
279 $status = $this->backend->doOperation( $op );
280 if ( $okStatus ) {
281 $this->assertEquals( array(), $status->errors,
282 "Deletion of file at $source succeeded without warnings ($backendName)." );
283 $this->assertEquals( true, $status->isOK(),
284 "Deletion of file at $source succeeded ($backendName)." );
285 } else {
286 $this->assertEquals( false, $status->isOK(),
287 "Deletion of file at $source failed ($backendName)." );
288 }
289
290 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
291 "Source file $source does not exist after move ($backendName)." );
292
293 $this->assertFalse(
294 $this->backend->getFileSize( array( 'src' => $source ) ),
295 "Source file $source has correct size (false) ($backendName)." );
296
297 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
298 $this->assertFalse( $props1['fileExists'],
299 "Source file $source does not exist according to props ($backendName)." );
300 }
301
302 public function provider_testDelete() {
303 $cases = array();
304
305 $source = $this->baseStorePath() . '/cont1/myfacefile.txt';
306
307 $op = array( 'op' => 'delete', 'src' => $source );
308 $cases[] = array(
309 $op, // operation
310 $source, // source
311 true, // with source
312 true // succeeds
313 );
314
315 $cases[] = array(
316 $op, // operation
317 $source, // source
318 false, // without source
319 false // fails
320 );
321
322 $op['ignoreMissingSource'] = true;
323 $cases[] = array(
324 $op, // operation
325 $source, // source
326 false, // without source
327 true // succeeds
328 );
329
330 return $cases;
331 }
332
333 /**
334 * @dataProvider provider_testCreate
335 */
336 public function testCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) {
337 $this->pathsToPrune[] = $dest;
338
339 $this->backend = $this->singleBackend;
340 $this->doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize );
341 $this->tearDownFiles();
342
343 $this->backend = $this->multiBackend;
344 $this->doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize );
345 $this->tearDownFiles();
346 }
347
348 public function doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) {
349 $backendName = $this->backendClass();
350
351 $oldText = 'blah...blah...waahwaah';
352 if ( $alreadyExists ) {
353 $status = $this->backend->doOperation(
354 array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) );
355 $this->assertEquals( true, $status->isOK(),
356 "Creation of file at $dest succeeded ($backendName)." );
357 }
358
359 $status = $this->backend->doOperation( $op );
360 if ( $okStatus ) {
361 $this->assertEquals( array(), $status->errors,
362 "Creation of file at $dest succeeded without warnings ($backendName)." );
363 $this->assertEquals( true, $status->isOK(),
364 "Creation of file at $dest succeeded ($backendName)." );
365 } else {
366 $this->assertEquals( false, $status->isOK(),
367 "Creation of file at $dest failed ($backendName)." );
368 }
369
370 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
371 "Destination file $dest exists after creation ($backendName)." );
372
373 $props1 = $this->backend->getFileProps( array( 'src' => $dest ) );
374 $this->assertEquals( true, $props1['fileExists'],
375 "Destination file $dest exists according to props ($backendName)." );
376 if ( $okStatus ) { // file content is what we saved
377 $this->assertEquals( $newSize, $props1['size'],
378 "Destination file $dest has expected size according to props ($backendName)." );
379 $this->assertEquals( $newSize,
380 $this->backend->getFileSize( array( 'src' => $dest ) ),
381 "Destination file $dest has correct size ($backendName)." );
382 } else { // file content is some other previous text
383 $this->assertEquals( strlen( $oldText ), $props1['size'],
384 "Destination file $dest has original size according to props ($backendName)." );
385 $this->assertEquals( strlen( $oldText ),
386 $this->backend->getFileSize( array( 'src' => $dest ) ),
387 "Destination file $dest has original size according to props ($backendName)." );
388 }
389 }
390
391 /**
392 * @dataProvider provider_testCreate
393 */
394 public function provider_testCreate() {
395 $cases = array();
396
397 $source = $this->baseStorePath() . '/cont2/myspacefile.txt';
398
399 $dummyText = 'hey hey';
400 $op = array( 'op' => 'create', 'content' => $dummyText, 'dst' => $source );
401 $cases[] = array(
402 $op, // operation
403 $source, // source
404 false, // no dest already exists
405 true, // succeeds
406 strlen( $dummyText )
407 );
408
409 $cases[] = array(
410 $op, // operation
411 $source, // source
412 true, // dest already exists
413 false, // fails
414 strlen( $dummyText )
415 );
416
417 $op['overwriteDest'] = true;
418 $cases[] = array(
419 $op, // operation
420 $source, // source
421 true, // dest already exists
422 true, // succeeds
423 strlen( $dummyText )
424 );
425
426 return $cases;
427 }
428
429 /**
430 * @dataProvider provider_testConcatenate
431 */
432 public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
433 $this->pathsToPrune = array_merge( $this->pathsToPrune, $srcs );
434 $this->filesToPrune[] = $op['dst'];
435
436 $this->backend = $this->singleBackend;
437 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
438 $this->tearDownFiles();
439
440 # FIXME
441 #$this->backend = $this->multiBackend;
442 #$this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
443 #$this->tearDownFiles();
444 }
445
446 public function doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
447 $backendName = $this->backendClass();
448
449 $expContent = '';
450 // Create sources
451 $ops = array();
452 foreach ( $srcs as $i => $source ) {
453 $ops[] = array(
454 'op' => 'create', // operation
455 'dst' => $source, // source
456 'content' => $srcsContent[$i]
457 );
458 $expContent .= $srcsContent[$i];
459 }
460 $status = $this->backend->doOperations( $ops );
461
462 $this->assertEquals( true, $status->isOK(),
463 "Creation of source files succeeded ($backendName)." );
464
465 $dest = $op['dst'];
466 if ( $alreadyExists ) {
467 $ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
468 $this->assertEquals( true, $ok,
469 "Creation of file at $dest succeeded ($backendName)." );
470 } else {
471 $ok = file_put_contents( $dest, '' ) !== false;
472 $this->assertEquals( true, $ok,
473 "Creation of 0-byte file at $dest succeeded ($backendName)." );
474 }
475
476 // Combine them
477 $status = $this->backend->doOperation( $op );
478 if ( $okStatus ) {
479 $this->assertEquals( array(), $status->errors,
480 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
481 $this->assertEquals( true, $status->isOK(),
482 "Creation of concat file at $dest succeeded ($backendName)." );
483 } else {
484 $this->assertEquals( false, $status->isOK(),
485 "Creation of concat file at $dest failed ($backendName)." );
486 }
487
488 if ( $okStatus ) {
489 $this->assertEquals( true, is_file( $dest ),
490 "Dest concat file $dest exists after creation ($backendName)." );
491 } else {
492 $this->assertEquals( true, is_file( $dest ),
493 "Dest concat file $dest exists after failed creation ($backendName)." );
494 }
495
496 $contents = file_get_contents( $dest );
497 $this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
498
499 if ( $okStatus ) {
500 $this->assertEquals( $expContent, $contents,
501 "Concat file at $dest has correct contents ($backendName)." );
502 } else {
503 $this->assertNotEquals( $expContent, $contents,
504 "Concat file at $dest has correct contents ($backendName)." );
505 }
506 }
507
508 function provider_testConcatenate() {
509 $cases = array();
510
511 $rand = mt_rand( 0, 2000000000 ) . time();
512 $dest = wfTempDir() . "/randomfile!$rand.txt";
513 $srcs = array(
514 $this->baseStorePath() . '/cont1/file1.txt',
515 $this->baseStorePath() . '/cont1/file2.txt',
516 $this->baseStorePath() . '/cont1/file3.txt',
517 $this->baseStorePath() . '/cont1/file4.txt',
518 $this->baseStorePath() . '/cont1/file5.txt',
519 $this->baseStorePath() . '/cont1/file6.txt',
520 $this->baseStorePath() . '/cont1/file7.txt',
521 $this->baseStorePath() . '/cont1/file8.txt',
522 $this->baseStorePath() . '/cont1/file9.txt',
523 $this->baseStorePath() . '/cont1/file10.txt'
524 );
525 $content = array(
526 'egfage',
527 'ageageag',
528 'rhokohlr',
529 'shgmslkg',
530 'kenga',
531 'owagmal',
532 'kgmae',
533 'g eak;g',
534 'lkaem;a',
535 'legma'
536 );
537 $op = array( 'op' => 'concatenate', 'srcs' => $srcs, 'dst' => $dest );
538
539 $cases[] = array(
540 $op, // operation
541 $srcs, // sources
542 $content, // content for each source
543 false, // no dest already exists
544 true, // succeeds
545 );
546
547 $cases[] = array(
548 $op, // operation
549 $srcs, // sources
550 $content, // content for each source
551 true, // dest already exists
552 false, // succeeds
553 );
554
555 return $cases;
556 }
557
558 /**
559 * @dataProvider provider_testGetFileContents
560 */
561 public function testGetFileContents( $src, $content ) {
562 $this->pathsToPrune[] = $src;
563
564 $this->backend = $this->singleBackend;
565 $this->doTestGetFileContents( $src, $content );
566 $this->tearDownFiles();
567
568 $this->backend = $this->multiBackend;
569 $this->doTestGetFileContents( $src, $content );
570 $this->tearDownFiles();
571 }
572
573 /**
574 * @dataProvider provider_testGetFileContents
575 */
576 public function doTestGetFileContents( $src, $content ) {
577 $backendName = $this->backendClass();
578
579 $status = $this->backend->doOperation(
580 array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
581 $this->assertEquals( true, $status->isOK(),
582 "Creation of file at $src succeeded ($backendName)." );
583
584 $newContents = $this->backend->getFileContents( array( 'src' => $src ) );
585 $this->assertNotEquals( false, $newContents,
586 "Read of file at $src succeeded ($backendName)." );
587
588 $this->assertEquals( $content, $newContents,
589 "Contents read match data at $src ($backendName)." );
590 }
591
592 function provider_testGetFileContents() {
593 $cases = array();
594
595 $base = $this->baseStorePath();
596 $cases[] = array( "$base/cont1/b/z/some_file.txt", "some file contents" );
597 $cases[] = array( "$base/cont1/b/some-other_file.txt", "more file contents" );
598
599 return $cases;
600 }
601
602 /**
603 * @dataProvider provider_testGetLocalCopy
604 */
605 public function testGetLocalCopy( $src, $content ) {
606 $this->pathsToPrune[] = $src;
607
608 $this->backend = $this->singleBackend;
609 $this->doTestGetLocalCopy( $src, $content );
610 $this->tearDownFiles();
611
612 $this->backend = $this->multiBackend;
613 $this->doTestGetLocalCopy( $src, $content );
614 $this->tearDownFiles();
615 }
616
617 public function doTestGetLocalCopy( $src, $content ) {
618 $backendName = $this->backendClass();
619
620 $status = $this->backend->doOperation(
621 array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
622 $this->assertEquals( true, $status->isOK(),
623 "Creation of file at $src succeeded ($backendName)." );
624
625 $tmpFile = $this->backend->getLocalCopy( array( 'src' => $src ) );
626 $this->assertNotNull( $tmpFile,
627 "Creation of local copy of $src succeeded ($backendName)." );
628
629 $contents = file_get_contents( $tmpFile->getPath() );
630 $this->assertNotEquals( false, $contents, "Local copy of $src exists ($backendName)." );
631 }
632
633 function provider_testGetLocalCopy() {
634 $cases = array();
635
636 $base = $this->baseStorePath();
637 $cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" );
638 $cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" );
639
640 return $cases;
641 }
642
643 /**
644 * @dataProvider provider_testGetLocalReference
645 */
646 public function testGetLocalReference( $src, $content ) {
647 $this->pathsToPrune[] = $src;
648
649 $this->backend = $this->singleBackend;
650 $this->doTestGetLocalReference( $src, $content );
651 $this->tearDownFiles();
652
653 $this->backend = $this->multiBackend;
654 $this->doTestGetLocalReference( $src, $content );
655 $this->tearDownFiles();
656 }
657
658 public function doTestGetLocalReference( $src, $content ) {
659 $backendName = $this->backendClass();
660
661 $status = $this->backend->doOperation(
662 array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
663 $this->assertEquals( true, $status->isOK(),
664 "Creation of file at $src succeeded ($backendName)." );
665
666 $tmpFile = $this->backend->getLocalReference( array( 'src' => $src ) );
667 $this->assertNotNull( $tmpFile,
668 "Creation of local copy of $src succeeded ($backendName)." );
669
670 $contents = file_get_contents( $tmpFile->getPath() );
671 $this->assertNotEquals( false, $contents, "Local copy of $src exists ($backendName)." );
672 }
673
674 function provider_testGetLocalReference() {
675 $cases = array();
676
677 $base = $this->baseStorePath();
678 $cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" );
679 $cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" );
680
681 return $cases;
682 }
683
684 // @TODO: testPrepare
685
686 // @TODO: testSecure
687
688 // @TODO: testClean
689
690 // @TODO: testDoOperations
691
692 public function testGetFileList() {
693 $this->backend = $this->singleBackend;
694 $this->doTestGetFileList();
695 $this->tearDownFiles();
696
697 $this->backend = $this->multiBackend;
698 $this->doTestGetFileList();
699 $this->tearDownFiles();
700 }
701
702 public function doTestGetFileList() {
703 $backendName = $this->backendClass();
704
705 $base = $this->baseStorePath();
706 $files = array(
707 "$base/cont1/test1.txt",
708 "$base/cont1/test2.txt",
709 "$base/cont1/test3.txt",
710 "$base/cont1/subdir1/test1.txt",
711 "$base/cont1/subdir1/test2.txt",
712 "$base/cont1/subdir2/test3.txt",
713 "$base/cont1/subdir2/test4.txt",
714 "$base/cont1/subdir2/subdir/test1.txt",
715 "$base/cont1/subdir2/subdir/test2.txt",
716 "$base/cont1/subdir2/subdir/test3.txt",
717 "$base/cont1/subdir2/subdir/test4.txt",
718 "$base/cont1/subdir2/subdir/test5.txt",
719 "$base/cont1/subdir2/subdir/sub/test0.txt",
720 "$base/cont1/subdir2/subdir/sub/120-px-file.txt",
721 );
722 $this->pathsToPrune = array_merge( $this->pathsToPrune, $files );
723
724 // Add the files
725 $ops = array();
726 foreach ( $files as $file ) {
727 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
728 }
729 $status = $this->backend->doOperations( $ops );
730 $this->assertEquals( true, $status->isOK(),
731 "Creation of files succeeded ($backendName)." );
732
733 // Expected listing
734 $expected = array(
735 "test1.txt",
736 "test2.txt",
737 "test3.txt",
738 "subdir1/test1.txt",
739 "subdir1/test2.txt",
740 "subdir2/test3.txt",
741 "subdir2/test4.txt",
742 "subdir2/subdir/test1.txt",
743 "subdir2/subdir/test2.txt",
744 "subdir2/subdir/test3.txt",
745 "subdir2/subdir/test4.txt",
746 "subdir2/subdir/test5.txt",
747 "subdir2/subdir/sub/test0.txt",
748 "subdir2/subdir/sub/120-px-file.txt",
749 );
750 sort( $expected );
751
752 // Actual listing (no trailing slash)
753 $list = array();
754 $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1" ) );
755 foreach ( $iter as $file ) {
756 $list[] = $file;
757 }
758 sort( $list );
759
760 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
761
762 // Actual listing (with trailing slash)
763 $list = array();
764 $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/" ) );
765 foreach ( $iter as $file ) {
766 $list[] = $file;
767 }
768 sort( $list );
769
770 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
771
772 foreach ( $files as $file ) {
773 $this->backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$file" ) );
774 }
775
776 $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/not/exists" ) );
777 foreach ( $iter as $iter ) {} // no errors
778 }
779
780 function tearDownFiles() {
781 foreach ( $this->filesToPrune as $file ) {
782 @unlink( $file );
783 }
784 foreach ( $this->pathsToPrune as $file ) {
785 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
786 }
787 }
788
789 function tearDown() {
790 parent::tearDown();
791 }
792 }