* Follow-up r107170: Moved FileBackend::concatenate() outside of doOperations() as...
[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 $this->backend = $this->multiBackend;
441 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
442 $this->tearDownFiles();
443 }
444
445 public function doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
446 $backendName = $this->backendClass();
447
448 $expContent = '';
449 // Create sources
450 $ops = array();
451 foreach ( $srcs as $i => $source ) {
452 $ops[] = array(
453 'op' => 'create', // operation
454 'dst' => $source, // source
455 'content' => $srcsContent[$i]
456 );
457 $expContent .= $srcsContent[$i];
458 }
459 $status = $this->backend->doOperations( $ops );
460
461 $this->assertEquals( true, $status->isOK(),
462 "Creation of source files succeeded ($backendName)." );
463
464 $dest = $params['dst'];
465 if ( $alreadyExists ) {
466 $ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
467 $this->assertEquals( true, $ok,
468 "Creation of file at $dest succeeded ($backendName)." );
469 } else {
470 $ok = file_put_contents( $dest, '' ) !== false;
471 $this->assertEquals( true, $ok,
472 "Creation of 0-byte file at $dest succeeded ($backendName)." );
473 }
474
475 // Combine the files into one
476 $status = $this->backend->concatenate( $params );
477 if ( $okStatus ) {
478 $this->assertEquals( array(), $status->errors,
479 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
480 $this->assertEquals( true, $status->isOK(),
481 "Creation of concat file at $dest succeeded ($backendName)." );
482 } else {
483 $this->assertEquals( false, $status->isOK(),
484 "Creation of concat file at $dest failed ($backendName)." );
485 }
486
487 if ( $okStatus ) {
488 $this->assertEquals( true, is_file( $dest ),
489 "Dest concat file $dest exists after creation ($backendName)." );
490 } else {
491 $this->assertEquals( true, is_file( $dest ),
492 "Dest concat file $dest exists after failed creation ($backendName)." );
493 }
494
495 $contents = file_get_contents( $dest );
496 $this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
497
498 if ( $okStatus ) {
499 $this->assertEquals( $expContent, $contents,
500 "Concat file at $dest has correct contents ($backendName)." );
501 } else {
502 $this->assertNotEquals( $expContent, $contents,
503 "Concat file at $dest has correct contents ($backendName)." );
504 }
505 }
506
507 function provider_testConcatenate() {
508 $cases = array();
509
510 $rand = mt_rand( 0, 2000000000 ) . time();
511 $dest = wfTempDir() . "/randomfile!$rand.txt";
512 $srcs = array(
513 $this->baseStorePath() . '/cont1/file1.txt',
514 $this->baseStorePath() . '/cont1/file2.txt',
515 $this->baseStorePath() . '/cont1/file3.txt',
516 $this->baseStorePath() . '/cont1/file4.txt',
517 $this->baseStorePath() . '/cont1/file5.txt',
518 $this->baseStorePath() . '/cont1/file6.txt',
519 $this->baseStorePath() . '/cont1/file7.txt',
520 $this->baseStorePath() . '/cont1/file8.txt',
521 $this->baseStorePath() . '/cont1/file9.txt',
522 $this->baseStorePath() . '/cont1/file10.txt'
523 );
524 $content = array(
525 'egfage',
526 'ageageag',
527 'rhokohlr',
528 'shgmslkg',
529 'kenga',
530 'owagmal',
531 'kgmae',
532 'g eak;g',
533 'lkaem;a',
534 'legma'
535 );
536 $params = array( 'srcs' => $srcs, 'dst' => $dest );
537
538 $cases[] = array(
539 $params, // operation
540 $srcs, // sources
541 $content, // content for each source
542 false, // no dest already exists
543 true, // succeeds
544 );
545
546 $cases[] = array(
547 $params, // operation
548 $srcs, // sources
549 $content, // content for each source
550 true, // dest already exists
551 false, // succeeds
552 );
553
554 return $cases;
555 }
556
557 /**
558 * @dataProvider provider_testGetFileContents
559 */
560 public function testGetFileContents( $src, $content ) {
561 $this->pathsToPrune[] = $src;
562
563 $this->backend = $this->singleBackend;
564 $this->doTestGetFileContents( $src, $content );
565 $this->tearDownFiles();
566
567 $this->backend = $this->multiBackend;
568 $this->doTestGetFileContents( $src, $content );
569 $this->tearDownFiles();
570 }
571
572 /**
573 * @dataProvider provider_testGetFileContents
574 */
575 public function doTestGetFileContents( $src, $content ) {
576 $backendName = $this->backendClass();
577
578 $status = $this->backend->doOperation(
579 array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
580 $this->assertEquals( true, $status->isOK(),
581 "Creation of file at $src succeeded ($backendName)." );
582
583 $newContents = $this->backend->getFileContents( array( 'src' => $src ) );
584 $this->assertNotEquals( false, $newContents,
585 "Read of file at $src succeeded ($backendName)." );
586
587 $this->assertEquals( $content, $newContents,
588 "Contents read match data at $src ($backendName)." );
589 }
590
591 function provider_testGetFileContents() {
592 $cases = array();
593
594 $base = $this->baseStorePath();
595 $cases[] = array( "$base/cont1/b/z/some_file.txt", "some file contents" );
596 $cases[] = array( "$base/cont1/b/some-other_file.txt", "more file contents" );
597
598 return $cases;
599 }
600
601 /**
602 * @dataProvider provider_testGetLocalCopy
603 */
604 public function testGetLocalCopy( $src, $content ) {
605 $this->pathsToPrune[] = $src;
606
607 $this->backend = $this->singleBackend;
608 $this->doTestGetLocalCopy( $src, $content );
609 $this->tearDownFiles();
610
611 $this->backend = $this->multiBackend;
612 $this->doTestGetLocalCopy( $src, $content );
613 $this->tearDownFiles();
614 }
615
616 public function doTestGetLocalCopy( $src, $content ) {
617 $backendName = $this->backendClass();
618
619 $status = $this->backend->doOperation(
620 array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
621 $this->assertEquals( true, $status->isOK(),
622 "Creation of file at $src succeeded ($backendName)." );
623
624 $tmpFile = $this->backend->getLocalCopy( array( 'src' => $src ) );
625 $this->assertNotNull( $tmpFile,
626 "Creation of local copy of $src succeeded ($backendName)." );
627
628 $contents = file_get_contents( $tmpFile->getPath() );
629 $this->assertNotEquals( false, $contents, "Local copy of $src exists ($backendName)." );
630 }
631
632 function provider_testGetLocalCopy() {
633 $cases = array();
634
635 $base = $this->baseStorePath();
636 $cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" );
637 $cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" );
638
639 return $cases;
640 }
641
642 /**
643 * @dataProvider provider_testGetLocalReference
644 */
645 public function testGetLocalReference( $src, $content ) {
646 $this->pathsToPrune[] = $src;
647
648 $this->backend = $this->singleBackend;
649 $this->doTestGetLocalReference( $src, $content );
650 $this->tearDownFiles();
651
652 $this->backend = $this->multiBackend;
653 $this->doTestGetLocalReference( $src, $content );
654 $this->tearDownFiles();
655 }
656
657 public function doTestGetLocalReference( $src, $content ) {
658 $backendName = $this->backendClass();
659
660 $status = $this->backend->doOperation(
661 array( 'op' => 'create', 'content' => $content, 'dst' => $src ) );
662 $this->assertEquals( true, $status->isOK(),
663 "Creation of file at $src succeeded ($backendName)." );
664
665 $tmpFile = $this->backend->getLocalReference( array( 'src' => $src ) );
666 $this->assertNotNull( $tmpFile,
667 "Creation of local copy of $src succeeded ($backendName)." );
668
669 $contents = file_get_contents( $tmpFile->getPath() );
670 $this->assertNotEquals( false, $contents, "Local copy of $src exists ($backendName)." );
671 }
672
673 function provider_testGetLocalReference() {
674 $cases = array();
675
676 $base = $this->baseStorePath();
677 $cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" );
678 $cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" );
679
680 return $cases;
681 }
682
683 // @TODO: testPrepare
684
685 // @TODO: testSecure
686
687 // @TODO: testClean
688
689 // @TODO: testDoOperations
690
691 public function testGetFileList() {
692 $this->backend = $this->singleBackend;
693 $this->doTestGetFileList();
694 $this->tearDownFiles();
695
696 $this->backend = $this->multiBackend;
697 $this->doTestGetFileList();
698 $this->tearDownFiles();
699 }
700
701 public function doTestGetFileList() {
702 $backendName = $this->backendClass();
703
704 $base = $this->baseStorePath();
705 $files = array(
706 "$base/cont1/test1.txt",
707 "$base/cont1/test2.txt",
708 "$base/cont1/test3.txt",
709 "$base/cont1/subdir1/test1.txt",
710 "$base/cont1/subdir1/test2.txt",
711 "$base/cont1/subdir2/test3.txt",
712 "$base/cont1/subdir2/test4.txt",
713 "$base/cont1/subdir2/subdir/test1.txt",
714 "$base/cont1/subdir2/subdir/test2.txt",
715 "$base/cont1/subdir2/subdir/test3.txt",
716 "$base/cont1/subdir2/subdir/test4.txt",
717 "$base/cont1/subdir2/subdir/test5.txt",
718 "$base/cont1/subdir2/subdir/sub/test0.txt",
719 "$base/cont1/subdir2/subdir/sub/120-px-file.txt",
720 );
721 $this->pathsToPrune = array_merge( $this->pathsToPrune, $files );
722
723 // Add the files
724 $ops = array();
725 foreach ( $files as $file ) {
726 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
727 }
728 $status = $this->backend->doOperations( $ops );
729 $this->assertEquals( true, $status->isOK(),
730 "Creation of files succeeded ($backendName)." );
731
732 // Expected listing
733 $expected = array(
734 "test1.txt",
735 "test2.txt",
736 "test3.txt",
737 "subdir1/test1.txt",
738 "subdir1/test2.txt",
739 "subdir2/test3.txt",
740 "subdir2/test4.txt",
741 "subdir2/subdir/test1.txt",
742 "subdir2/subdir/test2.txt",
743 "subdir2/subdir/test3.txt",
744 "subdir2/subdir/test4.txt",
745 "subdir2/subdir/test5.txt",
746 "subdir2/subdir/sub/test0.txt",
747 "subdir2/subdir/sub/120-px-file.txt",
748 );
749 sort( $expected );
750
751 // Actual listing (no trailing slash)
752 $list = array();
753 $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1" ) );
754 foreach ( $iter as $file ) {
755 $list[] = $file;
756 }
757 sort( $list );
758
759 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
760
761 // Actual listing (with trailing slash)
762 $list = array();
763 $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/" ) );
764 foreach ( $iter as $file ) {
765 $list[] = $file;
766 }
767 sort( $list );
768
769 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
770
771 foreach ( $files as $file ) {
772 $this->backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$file" ) );
773 }
774
775 $iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/not/exists" ) );
776 foreach ( $iter as $iter ) {} // no errors
777 }
778
779 function tearDownFiles() {
780 foreach ( $this->filesToPrune as $file ) {
781 @unlink( $file );
782 }
783 foreach ( $this->pathsToPrune as $file ) {
784 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
785 }
786 }
787
788 function tearDown() {
789 parent::tearDown();
790 }
791 }