fcfa724fc5b103f62abfc253dc41156a0d33c517
[lhc/web/wiklou.git] / tests / phpunit / includes / filebackend / FileBackendTest.php
1 <?php
2
3 /**
4 * @group FileRepo
5 * @group FileBackend
6 * @group medium
7 */
8 class FileBackendTest extends MediaWikiTestCase {
9
10 /** @var FileBackend */
11 private $backend;
12 /** @var FileBackendMultiWrite */
13 private $multiBackend;
14 /** @var FSFileBackend */
15 public $singleBackend;
16 private $filesToPrune = array();
17 private static $backendToUse;
18
19 protected function setUp() {
20 global $wgFileBackends;
21 parent::setUp();
22 $uniqueId = time() . '-' . mt_rand();
23 $tmpPrefix = wfTempDir() . '/filebackend-unittest-' . $uniqueId;
24 if ( $this->getCliArg( 'use-filebackend=' ) ) {
25 if ( self::$backendToUse ) {
26 $this->singleBackend = self::$backendToUse;
27 } else {
28 $name = $this->getCliArg( 'use-filebackend=' );
29 $useConfig = array();
30 foreach ( $wgFileBackends as $conf ) {
31 if ( $conf['name'] == $name ) {
32 $useConfig = $conf;
33 break;
34 }
35 }
36 $useConfig['name'] = 'localtesting'; // swap name
37 $useConfig['shardViaHashLevels'] = array( // test sharding
38 'unittest-cont1' => array( 'levels' => 1, 'base' => 16, 'repeat' => 1 )
39 );
40 $class = $useConfig['class'];
41 self::$backendToUse = new $class( $useConfig );
42 $this->singleBackend = self::$backendToUse;
43 }
44 } else {
45 $this->singleBackend = new FSFileBackend( array(
46 'name' => 'localtesting',
47 'lockManager' => 'fsLockManager',
48 #'parallelize' => 'implicit',
49 'wikiId' => wfWikiID() . $uniqueId,
50 'containerPaths' => array(
51 'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1",
52 'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" )
53 ) );
54 }
55 $this->multiBackend = new FileBackendMultiWrite( array(
56 'name' => 'localtesting',
57 'lockManager' => 'fsLockManager',
58 'parallelize' => 'implicit',
59 'wikiId' => wfWikiId() . $uniqueId,
60 'backends' => array(
61 array(
62 'name' => 'localmultitesting1',
63 'class' => 'FSFileBackend',
64 'lockManager' => 'nullLockManager',
65 'containerPaths' => array(
66 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1",
67 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ),
68 'isMultiMaster' => false
69 ),
70 array(
71 'name' => 'localmultitesting2',
72 'class' => 'FSFileBackend',
73 'lockManager' => 'nullLockManager',
74 'containerPaths' => array(
75 'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1",
76 'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ),
77 'isMultiMaster' => true
78 )
79 )
80 ) );
81 $this->filesToPrune = array();
82 }
83
84 private static function baseStorePath() {
85 return 'mwstore://localtesting';
86 }
87
88 private function backendClass() {
89 return get_class( $this->backend );
90 }
91
92 /**
93 * @dataProvider provider_testIsStoragePath
94 * @covers FileBackend::isStoragePath
95 */
96 public function testIsStoragePath( $path, $isStorePath ) {
97 $this->assertEquals( $isStorePath, FileBackend::isStoragePath( $path ),
98 "FileBackend::isStoragePath on path '$path'" );
99 }
100
101 public static function provider_testIsStoragePath() {
102 return array(
103 array( 'mwstore://', true ),
104 array( 'mwstore://backend', true ),
105 array( 'mwstore://backend/container', true ),
106 array( 'mwstore://backend/container/', true ),
107 array( 'mwstore://backend/container/path', true ),
108 array( 'mwstore://backend//container/', true ),
109 array( 'mwstore://backend//container//', true ),
110 array( 'mwstore://backend//container//path', true ),
111 array( 'mwstore:///', true ),
112 array( 'mwstore:/', false ),
113 array( 'mwstore:', false ),
114 );
115 }
116
117 /**
118 * @dataProvider provider_testSplitStoragePath
119 * @covers FileBackend::splitStoragePath
120 */
121 public function testSplitStoragePath( $path, $res ) {
122 $this->assertEquals( $res, FileBackend::splitStoragePath( $path ),
123 "FileBackend::splitStoragePath on path '$path'" );
124 }
125
126 public static function provider_testSplitStoragePath() {
127 return array(
128 array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ),
129 array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ),
130 array( 'mwstore://backend/container/path', array( 'backend', 'container', 'path' ) ),
131 array( 'mwstore://backend/container//path', array( 'backend', 'container', '/path' ) ),
132 array( 'mwstore://backend//container/path', array( null, null, null ) ),
133 array( 'mwstore://backend//container//path', array( null, null, null ) ),
134 array( 'mwstore://', array( null, null, null ) ),
135 array( 'mwstore://backend', array( null, null, null ) ),
136 array( 'mwstore:///', array( null, null, null ) ),
137 array( 'mwstore:/', array( null, null, null ) ),
138 array( 'mwstore:', array( null, null, null ) )
139 );
140 }
141
142 /**
143 * @dataProvider provider_normalizeStoragePath
144 * @covers FileBackend::normalizeStoragePath
145 */
146 public function testNormalizeStoragePath( $path, $res ) {
147 $this->assertEquals( $res, FileBackend::normalizeStoragePath( $path ),
148 "FileBackend::normalizeStoragePath on path '$path'" );
149 }
150
151 public static function provider_normalizeStoragePath() {
152 return array(
153 array( 'mwstore://backend/container', 'mwstore://backend/container' ),
154 array( 'mwstore://backend/container/', 'mwstore://backend/container' ),
155 array( 'mwstore://backend/container/path', 'mwstore://backend/container/path' ),
156 array( 'mwstore://backend/container//path', 'mwstore://backend/container/path' ),
157 array( 'mwstore://backend/container///path', 'mwstore://backend/container/path' ),
158 array( 'mwstore://backend/container///path//to///obj', 'mwstore://backend/container/path/to/obj' ),
159 array( 'mwstore://', null ),
160 array( 'mwstore://backend', null ),
161 array( 'mwstore://backend//container/path', null ),
162 array( 'mwstore://backend//container//path', null ),
163 array( 'mwstore:///', null ),
164 array( 'mwstore:/', null ),
165 array( 'mwstore:', null ),
166 );
167 }
168
169 /**
170 * @dataProvider provider_testParentStoragePath
171 * @covers FileBackend::parentStoragePath
172 */
173 public function testParentStoragePath( $path, $res ) {
174 $this->assertEquals( $res, FileBackend::parentStoragePath( $path ),
175 "FileBackend::parentStoragePath on path '$path'" );
176 }
177
178 public static function provider_testParentStoragePath() {
179 return array(
180 array( 'mwstore://backend/container/path/to/obj', 'mwstore://backend/container/path/to' ),
181 array( 'mwstore://backend/container/path/to', 'mwstore://backend/container/path' ),
182 array( 'mwstore://backend/container/path', 'mwstore://backend/container' ),
183 array( 'mwstore://backend/container', null ),
184 array( 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ),
185 array( 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ),
186 array( 'mwstore://backend/container/path/', 'mwstore://backend/container' ),
187 array( 'mwstore://backend/container/', null ),
188 );
189 }
190
191 /**
192 * @dataProvider provider_testExtensionFromPath
193 * @covers FileBackend::extensionFromPath
194 */
195 public function testExtensionFromPath( $path, $res ) {
196 $this->assertEquals( $res, FileBackend::extensionFromPath( $path ),
197 "FileBackend::extensionFromPath on path '$path'" );
198 }
199
200 public static function provider_testExtensionFromPath() {
201 return array(
202 array( 'mwstore://backend/container/path.txt', 'txt' ),
203 array( 'mwstore://backend/container/path.svg.png', 'png' ),
204 array( 'mwstore://backend/container/path', '' ),
205 array( 'mwstore://backend/container/path.', '' ),
206 );
207 }
208
209 /**
210 * @dataProvider provider_testStore
211 */
212 public function testStore( $op ) {
213 $this->filesToPrune[] = $op['src'];
214
215 $this->backend = $this->singleBackend;
216 $this->tearDownFiles();
217 $this->doTestStore( $op );
218 $this->tearDownFiles();
219
220 $this->backend = $this->multiBackend;
221 $this->tearDownFiles();
222 $this->doTestStore( $op );
223 $this->filesToPrune[] = $op['src']; # avoid file leaking
224 $this->tearDownFiles();
225 }
226
227 /**
228 * @covers FileBackend::doOperation
229 */
230 private function doTestStore( $op ) {
231 $backendName = $this->backendClass();
232
233 $source = $op['src'];
234 $dest = $op['dst'];
235 $this->prepare( array( 'dir' => dirname( $dest ) ) );
236
237 file_put_contents( $source, "Unit test file" );
238
239 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
240 $this->backend->store( $op );
241 }
242
243 $status = $this->backend->doOperation( $op );
244
245 $this->assertGoodStatus( $status,
246 "Store from $source to $dest succeeded without warnings ($backendName)." );
247 $this->assertEquals( true, $status->isOK(),
248 "Store from $source to $dest succeeded ($backendName)." );
249 $this->assertEquals( array( 0 => true ), $status->success,
250 "Store from $source to $dest has proper 'success' field in Status ($backendName)." );
251 $this->assertEquals( true, file_exists( $source ),
252 "Source file $source still exists ($backendName)." );
253 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
254 "Destination file $dest exists ($backendName)." );
255
256 $this->assertEquals( filesize( $source ),
257 $this->backend->getFileSize( array( 'src' => $dest ) ),
258 "Destination file $dest has correct size ($backendName)." );
259
260 $props1 = FSFile::getPropsFromPath( $source );
261 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
262 $this->assertEquals( $props1, $props2,
263 "Source and destination have the same props ($backendName)." );
264
265 $this->assertBackendPathsConsistent( array( $dest ) );
266 }
267
268 public static function provider_testStore() {
269 $cases = array();
270
271 $tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath();
272 $toPath = self::baseStorePath() . '/unittest-cont1/e/fun/obj1.txt';
273 $op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath );
274 $cases[] = array(
275 $op, // operation
276 $tmpName, // source
277 $toPath, // dest
278 );
279
280 $op2 = $op;
281 $op2['overwrite'] = true;
282 $cases[] = array(
283 $op2, // operation
284 $tmpName, // source
285 $toPath, // dest
286 );
287
288 $op2 = $op;
289 $op2['overwriteSame'] = true;
290 $cases[] = array(
291 $op2, // operation
292 $tmpName, // source
293 $toPath, // dest
294 );
295
296 return $cases;
297 }
298
299 /**
300 * @dataProvider provider_testCopy
301 * @covers FileBackend::doOperation
302 */
303 public function testCopy( $op ) {
304 $this->backend = $this->singleBackend;
305 $this->tearDownFiles();
306 $this->doTestCopy( $op );
307 $this->tearDownFiles();
308
309 $this->backend = $this->multiBackend;
310 $this->tearDownFiles();
311 $this->doTestCopy( $op );
312 $this->tearDownFiles();
313 }
314
315 private function doTestCopy( $op ) {
316 $backendName = $this->backendClass();
317
318 $source = $op['src'];
319 $dest = $op['dst'];
320 $this->prepare( array( 'dir' => dirname( $source ) ) );
321 $this->prepare( array( 'dir' => dirname( $dest ) ) );
322
323 if ( isset( $op['ignoreMissingSource'] ) ) {
324 $status = $this->backend->doOperation( $op );
325 $this->assertGoodStatus( $status,
326 "Move from $source to $dest succeeded without warnings ($backendName)." );
327 $this->assertEquals( array( 0 => true ), $status->success,
328 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
329 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
330 "Source file $source does not exist ($backendName)." );
331 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ),
332 "Destination file $dest does not exist ($backendName)." );
333
334 return; // done
335 }
336
337 $status = $this->backend->doOperation(
338 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
339 $this->assertGoodStatus( $status,
340 "Creation of file at $source succeeded ($backendName)." );
341
342 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
343 $this->backend->copy( $op );
344 }
345
346 $status = $this->backend->doOperation( $op );
347
348 $this->assertGoodStatus( $status,
349 "Copy from $source to $dest succeeded without warnings ($backendName)." );
350 $this->assertEquals( true, $status->isOK(),
351 "Copy from $source to $dest succeeded ($backendName)." );
352 $this->assertEquals( array( 0 => true ), $status->success,
353 "Copy from $source to $dest has proper 'success' field in Status ($backendName)." );
354 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $source ) ),
355 "Source file $source still exists ($backendName)." );
356 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
357 "Destination file $dest exists after copy ($backendName)." );
358
359 $this->assertEquals(
360 $this->backend->getFileSize( array( 'src' => $source ) ),
361 $this->backend->getFileSize( array( 'src' => $dest ) ),
362 "Destination file $dest has correct size ($backendName)." );
363
364 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
365 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
366 $this->assertEquals( $props1, $props2,
367 "Source and destination have the same props ($backendName)." );
368
369 $this->assertBackendPathsConsistent( array( $source, $dest ) );
370 }
371
372 public static function provider_testCopy() {
373 $cases = array();
374
375 $source = self::baseStorePath() . '/unittest-cont1/e/file.txt';
376 $dest = self::baseStorePath() . '/unittest-cont2/a/fileMoved.txt';
377
378 $op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest );
379 $cases[] = array(
380 $op, // operation
381 $source, // source
382 $dest, // dest
383 );
384
385 $op2 = $op;
386 $op2['overwrite'] = true;
387 $cases[] = array(
388 $op2, // operation
389 $source, // source
390 $dest, // dest
391 );
392
393 $op2 = $op;
394 $op2['overwriteSame'] = true;
395 $cases[] = array(
396 $op2, // operation
397 $source, // source
398 $dest, // dest
399 );
400
401 $op2 = $op;
402 $op2['ignoreMissingSource'] = true;
403 $cases[] = array(
404 $op2, // operation
405 $source, // source
406 $dest, // dest
407 );
408
409 $op2 = $op;
410 $op2['ignoreMissingSource'] = true;
411 $cases[] = array(
412 $op2, // operation
413 self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source
414 $dest, // dest
415 );
416
417 return $cases;
418 }
419
420 /**
421 * @dataProvider provider_testMove
422 * @covers FileBackend::doOperation
423 */
424 public function testMove( $op ) {
425 $this->backend = $this->singleBackend;
426 $this->tearDownFiles();
427 $this->doTestMove( $op );
428 $this->tearDownFiles();
429
430 $this->backend = $this->multiBackend;
431 $this->tearDownFiles();
432 $this->doTestMove( $op );
433 $this->tearDownFiles();
434 }
435
436 private function doTestMove( $op ) {
437 $backendName = $this->backendClass();
438
439 $source = $op['src'];
440 $dest = $op['dst'];
441 $this->prepare( array( 'dir' => dirname( $source ) ) );
442 $this->prepare( array( 'dir' => dirname( $dest ) ) );
443
444 if ( isset( $op['ignoreMissingSource'] ) ) {
445 $status = $this->backend->doOperation( $op );
446 $this->assertGoodStatus( $status,
447 "Move from $source to $dest succeeded without warnings ($backendName)." );
448 $this->assertEquals( array( 0 => true ), $status->success,
449 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
450 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
451 "Source file $source does not exist ($backendName)." );
452 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ),
453 "Destination file $dest does not exist ($backendName)." );
454
455 return; // done
456 }
457
458 $status = $this->backend->doOperation(
459 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
460 $this->assertGoodStatus( $status,
461 "Creation of file at $source succeeded ($backendName)." );
462
463 if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
464 $this->backend->copy( $op );
465 }
466
467 $status = $this->backend->doOperation( $op );
468 $this->assertGoodStatus( $status,
469 "Move from $source to $dest succeeded without warnings ($backendName)." );
470 $this->assertEquals( true, $status->isOK(),
471 "Move from $source to $dest succeeded ($backendName)." );
472 $this->assertEquals( array( 0 => true ), $status->success,
473 "Move from $source to $dest has proper 'success' field in Status ($backendName)." );
474 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
475 "Source file $source does not still exists ($backendName)." );
476 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
477 "Destination file $dest exists after move ($backendName)." );
478
479 $this->assertNotEquals(
480 $this->backend->getFileSize( array( 'src' => $source ) ),
481 $this->backend->getFileSize( array( 'src' => $dest ) ),
482 "Destination file $dest has correct size ($backendName)." );
483
484 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
485 $props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
486 $this->assertEquals( false, $props1['fileExists'],
487 "Source file does not exist accourding to props ($backendName)." );
488 $this->assertEquals( true, $props2['fileExists'],
489 "Destination file exists accourding to props ($backendName)." );
490
491 $this->assertBackendPathsConsistent( array( $source, $dest ) );
492 }
493
494 public static function provider_testMove() {
495 $cases = array();
496
497 $source = self::baseStorePath() . '/unittest-cont1/e/file.txt';
498 $dest = self::baseStorePath() . '/unittest-cont2/a/fileMoved.txt';
499
500 $op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest );
501 $cases[] = array(
502 $op, // operation
503 $source, // source
504 $dest, // dest
505 );
506
507 $op2 = $op;
508 $op2['overwrite'] = true;
509 $cases[] = array(
510 $op2, // operation
511 $source, // source
512 $dest, // dest
513 );
514
515 $op2 = $op;
516 $op2['overwriteSame'] = true;
517 $cases[] = array(
518 $op2, // operation
519 $source, // source
520 $dest, // dest
521 );
522
523 $op2 = $op;
524 $op2['ignoreMissingSource'] = true;
525 $cases[] = array(
526 $op2, // operation
527 $source, // source
528 $dest, // dest
529 );
530
531 $op2 = $op;
532 $op2['ignoreMissingSource'] = true;
533 $cases[] = array(
534 $op2, // operation
535 self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source
536 $dest, // dest
537 );
538
539 return $cases;
540 }
541
542 /**
543 * @dataProvider provider_testDelete
544 * @covers FileBackend::doOperation
545 */
546 public function testDelete( $op, $withSource, $okStatus ) {
547 $this->backend = $this->singleBackend;
548 $this->tearDownFiles();
549 $this->doTestDelete( $op, $withSource, $okStatus );
550 $this->tearDownFiles();
551
552 $this->backend = $this->multiBackend;
553 $this->tearDownFiles();
554 $this->doTestDelete( $op, $withSource, $okStatus );
555 $this->tearDownFiles();
556 }
557
558 private function doTestDelete( $op, $withSource, $okStatus ) {
559 $backendName = $this->backendClass();
560
561 $source = $op['src'];
562 $this->prepare( array( 'dir' => dirname( $source ) ) );
563
564 if ( $withSource ) {
565 $status = $this->backend->doOperation(
566 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
567 $this->assertGoodStatus( $status,
568 "Creation of file at $source succeeded ($backendName)." );
569 }
570
571 $status = $this->backend->doOperation( $op );
572 if ( $okStatus ) {
573 $this->assertGoodStatus( $status,
574 "Deletion of file at $source succeeded without warnings ($backendName)." );
575 $this->assertEquals( true, $status->isOK(),
576 "Deletion of file at $source succeeded ($backendName)." );
577 $this->assertEquals( array( 0 => true ), $status->success,
578 "Deletion of file at $source has proper 'success' field in Status ($backendName)." );
579 } else {
580 $this->assertEquals( false, $status->isOK(),
581 "Deletion of file at $source failed ($backendName)." );
582 }
583
584 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
585 "Source file $source does not exist after move ($backendName)." );
586
587 $this->assertFalse(
588 $this->backend->getFileSize( array( 'src' => $source ) ),
589 "Source file $source has correct size (false) ($backendName)." );
590
591 $props1 = $this->backend->getFileProps( array( 'src' => $source ) );
592 $this->assertFalse( $props1['fileExists'],
593 "Source file $source does not exist according to props ($backendName)." );
594
595 $this->assertBackendPathsConsistent( array( $source ) );
596 }
597
598 public static function provider_testDelete() {
599 $cases = array();
600
601 $source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt';
602
603 $op = array( 'op' => 'delete', 'src' => $source );
604 $cases[] = array(
605 $op, // operation
606 true, // with source
607 true // succeeds
608 );
609
610 $cases[] = array(
611 $op, // operation
612 false, // without source
613 false // fails
614 );
615
616 $op['ignoreMissingSource'] = true;
617 $cases[] = array(
618 $op, // operation
619 false, // without source
620 true // succeeds
621 );
622
623 $op['ignoreMissingSource'] = true;
624 $op['src'] = self::baseStorePath() . '/unittest-cont-bad/e/file.txt';
625 $cases[] = array(
626 $op, // operation
627 false, // without source
628 true // succeeds
629 );
630
631 return $cases;
632 }
633
634 /**
635 * @dataProvider provider_testDescribe
636 * @covers FileBackend::doOperation
637 */
638 public function testDescribe( $op, $withSource, $okStatus ) {
639 $this->backend = $this->singleBackend;
640 $this->tearDownFiles();
641 $this->doTestDescribe( $op, $withSource, $okStatus );
642 $this->tearDownFiles();
643
644 $this->backend = $this->multiBackend;
645 $this->tearDownFiles();
646 $this->doTestDescribe( $op, $withSource, $okStatus );
647 $this->tearDownFiles();
648 }
649
650 private function doTestDescribe( $op, $withSource, $okStatus ) {
651 $backendName = $this->backendClass();
652
653 $source = $op['src'];
654 $this->prepare( array( 'dir' => dirname( $source ) ) );
655
656 if ( $withSource ) {
657 $status = $this->backend->doOperation(
658 array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
659 $this->assertGoodStatus( $status,
660 "Creation of file at $source succeeded ($backendName)." );
661 }
662
663 $status = $this->backend->doOperation( $op );
664 if ( $okStatus ) {
665 $this->assertGoodStatus( $status,
666 "Describe of file at $source succeeded without warnings ($backendName)." );
667 $this->assertEquals( true, $status->isOK(),
668 "Describe of file at $source succeeded ($backendName)." );
669 $this->assertEquals( array( 0 => true ), $status->success,
670 "Describe of file at $source has proper 'success' field in Status ($backendName)." );
671 } else {
672 $this->assertEquals( false, $status->isOK(),
673 "Describe of file at $source failed ($backendName)." );
674 }
675
676 $this->assertBackendPathsConsistent( array( $source ) );
677 }
678
679 public static function provider_testDescribe() {
680 $cases = array();
681
682 $source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt';
683
684 $op = array( 'op' => 'describe', 'src' => $source,
685 'headers' => array( 'X-Content-Length' => '91.3', 'Content-Old-Header' => '' ),
686 'disposition' => 'inline' );
687 $cases[] = array(
688 $op, // operation
689 true, // with source
690 true // succeeds
691 );
692
693 $cases[] = array(
694 $op, // operation
695 false, // without source
696 false // fails
697 );
698
699 return $cases;
700 }
701
702 /**
703 * @dataProvider provider_testCreate
704 * @covers FileBackend::doOperation
705 */
706 public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
707 $this->backend = $this->singleBackend;
708 $this->tearDownFiles();
709 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
710 $this->tearDownFiles();
711
712 $this->backend = $this->multiBackend;
713 $this->tearDownFiles();
714 $this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
715 $this->tearDownFiles();
716 }
717
718 private function doTestCreate( $op, $alreadyExists, $okStatus, $newSize ) {
719 $backendName = $this->backendClass();
720
721 $dest = $op['dst'];
722 $this->prepare( array( 'dir' => dirname( $dest ) ) );
723
724 $oldText = 'blah...blah...waahwaah';
725 if ( $alreadyExists ) {
726 $status = $this->backend->doOperation(
727 array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) );
728 $this->assertGoodStatus( $status,
729 "Creation of file at $dest succeeded ($backendName)." );
730 }
731
732 $status = $this->backend->doOperation( $op );
733 if ( $okStatus ) {
734 $this->assertGoodStatus( $status,
735 "Creation of file at $dest succeeded without warnings ($backendName)." );
736 $this->assertEquals( true, $status->isOK(),
737 "Creation of file at $dest succeeded ($backendName)." );
738 $this->assertEquals( array( 0 => true ), $status->success,
739 "Creation of file at $dest has proper 'success' field in Status ($backendName)." );
740 } else {
741 $this->assertEquals( false, $status->isOK(),
742 "Creation of file at $dest failed ($backendName)." );
743 }
744
745 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
746 "Destination file $dest exists after creation ($backendName)." );
747
748 $props1 = $this->backend->getFileProps( array( 'src' => $dest ) );
749 $this->assertEquals( true, $props1['fileExists'],
750 "Destination file $dest exists according to props ($backendName)." );
751 if ( $okStatus ) { // file content is what we saved
752 $this->assertEquals( $newSize, $props1['size'],
753 "Destination file $dest has expected size according to props ($backendName)." );
754 $this->assertEquals( $newSize,
755 $this->backend->getFileSize( array( 'src' => $dest ) ),
756 "Destination file $dest has correct size ($backendName)." );
757 } else { // file content is some other previous text
758 $this->assertEquals( strlen( $oldText ), $props1['size'],
759 "Destination file $dest has original size according to props ($backendName)." );
760 $this->assertEquals( strlen( $oldText ),
761 $this->backend->getFileSize( array( 'src' => $dest ) ),
762 "Destination file $dest has original size according to props ($backendName)." );
763 }
764
765 $this->assertBackendPathsConsistent( array( $dest ) );
766 }
767
768 /**
769 * @dataProvider provider_testCreate
770 */
771 public static function provider_testCreate() {
772 $cases = array();
773
774 $dest = self::baseStorePath() . '/unittest-cont2/a/myspacefile.txt';
775
776 $op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest );
777 $cases[] = array(
778 $op, // operation
779 false, // no dest already exists
780 true, // succeeds
781 strlen( $op['content'] )
782 );
783
784 $op2 = $op;
785 $op2['content'] = "\n";
786 $cases[] = array(
787 $op2, // operation
788 false, // no dest already exists
789 true, // succeeds
790 strlen( $op2['content'] )
791 );
792
793 $op2 = $op;
794 $op2['content'] = "fsf\n waf 3kt";
795 $cases[] = array(
796 $op2, // operation
797 true, // dest already exists
798 false, // fails
799 strlen( $op2['content'] )
800 );
801
802 $op2 = $op;
803 $op2['content'] = "egm'g gkpe gpqg eqwgwqg";
804 $op2['overwrite'] = true;
805 $cases[] = array(
806 $op2, // operation
807 true, // dest already exists
808 true, // succeeds
809 strlen( $op2['content'] )
810 );
811
812 $op2 = $op;
813 $op2['content'] = "39qjmg3-qg";
814 $op2['overwriteSame'] = true;
815 $cases[] = array(
816 $op2, // operation
817 true, // dest already exists
818 false, // succeeds
819 strlen( $op2['content'] )
820 );
821
822 return $cases;
823 }
824
825 /**
826 * @covers FileBackend::doQuickOperations
827 */
828 public function testDoQuickOperations() {
829 $this->backend = $this->singleBackend;
830 $this->doTestDoQuickOperations();
831 $this->tearDownFiles();
832
833 $this->backend = $this->multiBackend;
834 $this->doTestDoQuickOperations();
835 $this->tearDownFiles();
836 }
837
838 private function doTestDoQuickOperations() {
839 $backendName = $this->backendClass();
840
841 $base = self::baseStorePath();
842 $files = array(
843 "$base/unittest-cont1/e/fileA.a",
844 "$base/unittest-cont1/e/fileB.a",
845 "$base/unittest-cont1/e/fileC.a"
846 );
847 $createOps = array();
848 $purgeOps = array();
849 foreach ( $files as $path ) {
850 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
851 $this->assertGoodStatus( $status,
852 "Preparing $path succeeded without warnings ($backendName)." );
853 $createOps[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand( 0, 50000 ) );
854 $copyOps[] = array( 'op' => 'copy', 'src' => $path, 'dst' => "$path-2" );
855 $moveOps[] = array( 'op' => 'move', 'src' => "$path-2", 'dst' => "$path-3" );
856 $purgeOps[] = array( 'op' => 'delete', 'src' => $path );
857 $purgeOps[] = array( 'op' => 'delete', 'src' => "$path-3" );
858 }
859 $purgeOps[] = array( 'op' => 'null' );
860
861 $this->assertGoodStatus(
862 $this->backend->doQuickOperations( $createOps ),
863 "Creation of source files succeeded ($backendName)." );
864 foreach ( $files as $file ) {
865 $this->assertTrue( $this->backend->fileExists( array( 'src' => $file ) ),
866 "File $file exists." );
867 }
868
869 $this->assertGoodStatus(
870 $this->backend->doQuickOperations( $copyOps ),
871 "Quick copy of source files succeeded ($backendName)." );
872 foreach ( $files as $file ) {
873 $this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-2" ) ),
874 "File $file-2 exists." );
875 }
876
877 $this->assertGoodStatus(
878 $this->backend->doQuickOperations( $moveOps ),
879 "Quick move of source files succeeded ($backendName)." );
880 foreach ( $files as $file ) {
881 $this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-3" ) ),
882 "File $file-3 move in." );
883 $this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-2" ) ),
884 "File $file-2 moved away." );
885 }
886
887 $this->assertGoodStatus(
888 $this->backend->quickCopy( array( 'src' => $files[0], 'dst' => $files[0] ) ),
889 "Copy of file {$files[0]} over itself succeeded ($backendName)." );
890 $this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ),
891 "File {$files[0]} still exists." );
892
893 $this->assertGoodStatus(
894 $this->backend->quickMove( array( 'src' => $files[0], 'dst' => $files[0] ) ),
895 "Move of file {$files[0]} over itself succeeded ($backendName)." );
896 $this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ),
897 "File {$files[0]} still exists." );
898
899 $this->assertGoodStatus(
900 $this->backend->doQuickOperations( $purgeOps ),
901 "Quick deletion of source files succeeded ($backendName)." );
902 foreach ( $files as $file ) {
903 $this->assertFalse( $this->backend->fileExists( array( 'src' => $file ) ),
904 "File $file purged." );
905 $this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-3" ) ),
906 "File $file-3 purged." );
907 }
908 }
909
910 /**
911 * @dataProvider provider_testConcatenate
912 */
913 public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
914 $this->filesToPrune[] = $op['dst'];
915
916 $this->backend = $this->singleBackend;
917 $this->tearDownFiles();
918 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
919 $this->filesToPrune[] = $op['dst']; # avoid file leaking
920 $this->tearDownFiles();
921
922 $this->backend = $this->multiBackend;
923 $this->tearDownFiles();
924 $this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
925 $this->filesToPrune[] = $op['dst']; # avoid file leaking
926 $this->tearDownFiles();
927 }
928
929 private function doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
930 $backendName = $this->backendClass();
931
932 $expContent = '';
933 // Create sources
934 $ops = array();
935 foreach ( $srcs as $i => $source ) {
936 $this->prepare( array( 'dir' => dirname( $source ) ) );
937 $ops[] = array(
938 'op' => 'create', // operation
939 'dst' => $source, // source
940 'content' => $srcsContent[$i]
941 );
942 $expContent .= $srcsContent[$i];
943 }
944 $status = $this->backend->doOperations( $ops );
945
946 $this->assertGoodStatus( $status,
947 "Creation of source files succeeded ($backendName)." );
948
949 $dest = $params['dst'];
950 if ( $alreadyExists ) {
951 $ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
952 $this->assertEquals( true, $ok,
953 "Creation of file at $dest succeeded ($backendName)." );
954 } else {
955 $ok = file_put_contents( $dest, '' ) !== false;
956 $this->assertEquals( true, $ok,
957 "Creation of 0-byte file at $dest succeeded ($backendName)." );
958 }
959
960 // Combine the files into one
961 $status = $this->backend->concatenate( $params );
962 if ( $okStatus ) {
963 $this->assertGoodStatus( $status,
964 "Creation of concat file at $dest succeeded without warnings ($backendName)." );
965 $this->assertEquals( true, $status->isOK(),
966 "Creation of concat file at $dest succeeded ($backendName)." );
967 } else {
968 $this->assertEquals( false, $status->isOK(),
969 "Creation of concat file at $dest failed ($backendName)." );
970 }
971
972 if ( $okStatus ) {
973 $this->assertEquals( true, is_file( $dest ),
974 "Dest concat file $dest exists after creation ($backendName)." );
975 } else {
976 $this->assertEquals( true, is_file( $dest ),
977 "Dest concat file $dest exists after failed creation ($backendName)." );
978 }
979
980 $contents = file_get_contents( $dest );
981 $this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
982
983 if ( $okStatus ) {
984 $this->assertEquals( $expContent, $contents,
985 "Concat file at $dest has correct contents ($backendName)." );
986 } else {
987 $this->assertNotEquals( $expContent, $contents,
988 "Concat file at $dest has correct contents ($backendName)." );
989 }
990 }
991
992 public static function provider_testConcatenate() {
993 $cases = array();
994
995 $rand = mt_rand( 0, 2000000000 ) . time();
996 $dest = wfTempDir() . "/randomfile!$rand.txt";
997 $srcs = array(
998 self::baseStorePath() . '/unittest-cont1/e/file1.txt',
999 self::baseStorePath() . '/unittest-cont1/e/file2.txt',
1000 self::baseStorePath() . '/unittest-cont1/e/file3.txt',
1001 self::baseStorePath() . '/unittest-cont1/e/file4.txt',
1002 self::baseStorePath() . '/unittest-cont1/e/file5.txt',
1003 self::baseStorePath() . '/unittest-cont1/e/file6.txt',
1004 self::baseStorePath() . '/unittest-cont1/e/file7.txt',
1005 self::baseStorePath() . '/unittest-cont1/e/file8.txt',
1006 self::baseStorePath() . '/unittest-cont1/e/file9.txt',
1007 self::baseStorePath() . '/unittest-cont1/e/file10.txt'
1008 );
1009 $content = array(
1010 'egfage',
1011 'ageageag',
1012 'rhokohlr',
1013 'shgmslkg',
1014 'kenga',
1015 'owagmal',
1016 'kgmae',
1017 'g eak;g',
1018 'lkaem;a',
1019 'legma'
1020 );
1021 $params = array( 'srcs' => $srcs, 'dst' => $dest );
1022
1023 $cases[] = array(
1024 $params, // operation
1025 $srcs, // sources
1026 $content, // content for each source
1027 false, // no dest already exists
1028 true, // succeeds
1029 );
1030
1031 $cases[] = array(
1032 $params, // operation
1033 $srcs, // sources
1034 $content, // content for each source
1035 true, // dest already exists
1036 false, // succeeds
1037 );
1038
1039 return $cases;
1040 }
1041
1042 /**
1043 * @dataProvider provider_testGetFileStat
1044 * @covers FileBackend::getFileStat
1045 */
1046 public function testGetFileStat( $path, $content, $alreadyExists ) {
1047 $this->backend = $this->singleBackend;
1048 $this->tearDownFiles();
1049 $this->doTestGetFileStat( $path, $content, $alreadyExists );
1050 $this->tearDownFiles();
1051
1052 $this->backend = $this->multiBackend;
1053 $this->tearDownFiles();
1054 $this->doTestGetFileStat( $path, $content, $alreadyExists );
1055 $this->tearDownFiles();
1056 }
1057
1058 private function doTestGetFileStat( $path, $content, $alreadyExists ) {
1059 $backendName = $this->backendClass();
1060
1061 if ( $alreadyExists ) {
1062 $this->prepare( array( 'dir' => dirname( $path ) ) );
1063 $status = $this->create( array( 'dst' => $path, 'content' => $content ) );
1064 $this->assertGoodStatus( $status,
1065 "Creation of file at $path succeeded ($backendName)." );
1066
1067 $size = $this->backend->getFileSize( array( 'src' => $path ) );
1068 $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
1069 $stat = $this->backend->getFileStat( array( 'src' => $path ) );
1070
1071 $this->assertEquals( strlen( $content ), $size,
1072 "Correct file size of '$path'" );
1073 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10,
1074 "Correct file timestamp of '$path'" );
1075
1076 $size = $stat['size'];
1077 $time = $stat['mtime'];
1078 $this->assertEquals( strlen( $content ), $size,
1079 "Correct file size of '$path'" );
1080 $this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10,
1081 "Correct file timestamp of '$path'" );
1082
1083 $this->backend->clearCache( array( $path ) );
1084
1085 $size = $this->backend->getFileSize( array( 'src' => $path ) );
1086
1087 $this->assertEquals( strlen( $content ), $size,
1088 "Correct file size of '$path'" );
1089
1090 $this->backend->preloadCache( array( $path ) );
1091
1092 $size = $this->backend->getFileSize( array( 'src' => $path ) );
1093
1094 $this->assertEquals( strlen( $content ), $size,
1095 "Correct file size of '$path'" );
1096 } else {
1097 $size = $this->backend->getFileSize( array( 'src' => $path ) );
1098 $time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
1099 $stat = $this->backend->getFileStat( array( 'src' => $path ) );
1100
1101 $this->assertFalse( $size, "Correct file size of '$path'" );
1102 $this->assertFalse( $time, "Correct file timestamp of '$path'" );
1103 $this->assertFalse( $stat, "Correct file stat of '$path'" );
1104 }
1105 }
1106
1107 public static function provider_testGetFileStat() {
1108 $cases = array();
1109
1110 $base = self::baseStorePath();
1111 $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents", true );
1112 $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "", true );
1113 $cases[] = array( "$base/unittest-cont1/e/b/some-diff_file.txt", null, false );
1114
1115 return $cases;
1116 }
1117
1118 /**
1119 * @dataProvider provider_testGetFileContents
1120 * @covers FileBackend::getFileContents
1121 * @covers FileBackend::getFileContentsMulti
1122 */
1123 public function testGetFileContents( $source, $content ) {
1124 $this->backend = $this->singleBackend;
1125 $this->tearDownFiles();
1126 $this->doTestGetFileContents( $source, $content );
1127 $this->tearDownFiles();
1128
1129 $this->backend = $this->multiBackend;
1130 $this->tearDownFiles();
1131 $this->doTestGetFileContents( $source, $content );
1132 $this->tearDownFiles();
1133 }
1134
1135 private function doTestGetFileContents( $source, $content ) {
1136 $backendName = $this->backendClass();
1137
1138 $srcs = (array)$source;
1139 $content = (array)$content;
1140 foreach ( $srcs as $i => $src ) {
1141 $this->prepare( array( 'dir' => dirname( $src ) ) );
1142 $status = $this->backend->doOperation(
1143 array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
1144 $this->assertGoodStatus( $status,
1145 "Creation of file at $src succeeded ($backendName)." );
1146 }
1147
1148 if ( is_array( $source ) ) {
1149 $contents = $this->backend->getFileContentsMulti( array( 'srcs' => $source ) );
1150 foreach ( $contents as $path => $data ) {
1151 $this->assertNotEquals( false, $data, "Contents of $path exists ($backendName)." );
1152 $this->assertEquals( current( $content ), $data, "Contents of $path is correct ($backendName)." );
1153 next( $content );
1154 }
1155 $this->assertEquals( $source, array_keys( $contents ), "Contents in right order ($backendName)." );
1156 $this->assertEquals( count( $source ), count( $contents ), "Contents array size correct ($backendName)." );
1157 } else {
1158 $data = $this->backend->getFileContents( array( 'src' => $source ) );
1159 $this->assertNotEquals( false, $data, "Contents of $source exists ($backendName)." );
1160 $this->assertEquals( $content[0], $data, "Contents of $source is correct ($backendName)." );
1161 }
1162 }
1163
1164 public static function provider_testGetFileContents() {
1165 $cases = array();
1166
1167 $base = self::baseStorePath();
1168 $cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" );
1169 $cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "more file contents" );
1170 $cases[] = array(
1171 array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
1172 "$base/unittest-cont1/e/a/z.txt" ),
1173 array( "contents xx", "contents xy", "contents xz" )
1174 );
1175
1176 return $cases;
1177 }
1178
1179 /**
1180 * @dataProvider provider_testGetLocalCopy
1181 * @covers FileBackend::getLocalCopy
1182 */
1183 public function testGetLocalCopy( $source, $content ) {
1184 $this->backend = $this->singleBackend;
1185 $this->tearDownFiles();
1186 $this->doTestGetLocalCopy( $source, $content );
1187 $this->tearDownFiles();
1188
1189 $this->backend = $this->multiBackend;
1190 $this->tearDownFiles();
1191 $this->doTestGetLocalCopy( $source, $content );
1192 $this->tearDownFiles();
1193 }
1194
1195 private function doTestGetLocalCopy( $source, $content ) {
1196 $backendName = $this->backendClass();
1197
1198 $srcs = (array)$source;
1199 $content = (array)$content;
1200 foreach ( $srcs as $i => $src ) {
1201 $this->prepare( array( 'dir' => dirname( $src ) ) );
1202 $status = $this->backend->doOperation(
1203 array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
1204 $this->assertGoodStatus( $status,
1205 "Creation of file at $src succeeded ($backendName)." );
1206 }
1207
1208 if ( is_array( $source ) ) {
1209 $tmpFiles = $this->backend->getLocalCopyMulti( array( 'srcs' => $source ) );
1210 foreach ( $tmpFiles as $path => $tmpFile ) {
1211 $this->assertNotNull( $tmpFile,
1212 "Creation of local copy of $path succeeded ($backendName)." );
1213 $contents = file_get_contents( $tmpFile->getPath() );
1214 $this->assertNotEquals( false, $contents, "Local copy of $path exists ($backendName)." );
1215 $this->assertEquals( current( $content ), $contents, "Local copy of $path is correct ($backendName)." );
1216 next( $content );
1217 }
1218 $this->assertEquals( $source, array_keys( $tmpFiles ), "Local copies in right order ($backendName)." );
1219 $this->assertEquals( count( $source ), count( $tmpFiles ), "Local copies array size correct ($backendName)." );
1220 } else {
1221 $tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) );
1222 $this->assertNotNull( $tmpFile,
1223 "Creation of local copy of $source succeeded ($backendName)." );
1224 $contents = file_get_contents( $tmpFile->getPath() );
1225 $this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
1226 $this->assertEquals( $content[0], $contents, "Local copy of $source is correct ($backendName)." );
1227 }
1228
1229 $obj = new stdClass();
1230 $tmpFile->bind( $obj );
1231 }
1232
1233 public static function provider_testGetLocalCopy() {
1234 $cases = array();
1235
1236 $base = self::baseStorePath();
1237 $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
1238 $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
1239 $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
1240 $cases[] = array(
1241 array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
1242 "$base/unittest-cont1/e/a/z.txt" ),
1243 array( "contents xx", "contents xy", "contents xz" )
1244 );
1245
1246 return $cases;
1247 }
1248
1249 /**
1250 * @dataProvider provider_testGetLocalReference
1251 * @covers FileBackend::getLocalReference
1252 */
1253 public function testGetLocalReference( $source, $content ) {
1254 $this->backend = $this->singleBackend;
1255 $this->tearDownFiles();
1256 $this->doTestGetLocalReference( $source, $content );
1257 $this->tearDownFiles();
1258
1259 $this->backend = $this->multiBackend;
1260 $this->tearDownFiles();
1261 $this->doTestGetLocalReference( $source, $content );
1262 $this->tearDownFiles();
1263 }
1264
1265 private function doTestGetLocalReference( $source, $content ) {
1266 $backendName = $this->backendClass();
1267
1268 $srcs = (array)$source;
1269 $content = (array)$content;
1270 foreach ( $srcs as $i => $src ) {
1271 $this->prepare( array( 'dir' => dirname( $src ) ) );
1272 $status = $this->backend->doOperation(
1273 array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
1274 $this->assertGoodStatus( $status,
1275 "Creation of file at $src succeeded ($backendName)." );
1276 }
1277
1278 if ( is_array( $source ) ) {
1279 $tmpFiles = $this->backend->getLocalReferenceMulti( array( 'srcs' => $source ) );
1280 foreach ( $tmpFiles as $path => $tmpFile ) {
1281 $this->assertNotNull( $tmpFile,
1282 "Creation of local copy of $path succeeded ($backendName)." );
1283 $contents = file_get_contents( $tmpFile->getPath() );
1284 $this->assertNotEquals( false, $contents, "Local ref of $path exists ($backendName)." );
1285 $this->assertEquals( current( $content ), $contents, "Local ref of $path is correct ($backendName)." );
1286 next( $content );
1287 }
1288 $this->assertEquals( $source, array_keys( $tmpFiles ), "Local refs in right order ($backendName)." );
1289 $this->assertEquals( count( $source ), count( $tmpFiles ), "Local refs array size correct ($backendName)." );
1290 } else {
1291 $tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
1292 $this->assertNotNull( $tmpFile,
1293 "Creation of local copy of $source succeeded ($backendName)." );
1294 $contents = file_get_contents( $tmpFile->getPath() );
1295 $this->assertNotEquals( false, $contents, "Local ref of $source exists ($backendName)." );
1296 $this->assertEquals( $content[0], $contents, "Local ref of $source is correct ($backendName)." );
1297 }
1298 }
1299
1300 public static function provider_testGetLocalReference() {
1301 $cases = array();
1302
1303 $base = self::baseStorePath();
1304 $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
1305 $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
1306 $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
1307 $cases[] = array(
1308 array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
1309 "$base/unittest-cont1/e/a/z.txt" ),
1310 array( "contents xx", "contents xy", "contents xz" )
1311 );
1312
1313 return $cases;
1314 }
1315
1316 /**
1317 * @covers FileBackend::getLocalCopy
1318 * @covers FileBackend::getLocalReference
1319 */
1320 public function testGetLocalCopyAndReference404() {
1321 $this->backend = $this->singleBackend;
1322 $this->tearDownFiles();
1323 $this->doTestGetLocalCopyAndReference404();
1324 $this->tearDownFiles();
1325
1326 $this->backend = $this->multiBackend;
1327 $this->tearDownFiles();
1328 $this->doTestGetLocalCopyAndReference404();
1329 $this->tearDownFiles();
1330 }
1331
1332 public function doTestGetLocalCopyAndReference404() {
1333 $backendName = $this->backendClass();
1334
1335 $base = self::baseStorePath();
1336
1337 $tmpFile = $this->backend->getLocalCopy( array(
1338 'src' => "$base/unittest-cont1/not-there" ) );
1339 $this->assertEquals( null, $tmpFile, "Local copy of not existing file is null ($backendName)." );
1340
1341 $tmpFile = $this->backend->getLocalReference( array(
1342 'src' => "$base/unittest-cont1/not-there" ) );
1343 $this->assertEquals( null, $tmpFile, "Local ref of not existing file is null ($backendName)." );
1344 }
1345
1346 /**
1347 * @dataProvider provider_testGetFileHttpUrl
1348 * @covers FileBackend::getFileHttpUrl
1349 */
1350 public function testGetFileHttpUrl( $source, $content ) {
1351 $this->backend = $this->singleBackend;
1352 $this->tearDownFiles();
1353 $this->doTestGetFileHttpUrl( $source, $content );
1354 $this->tearDownFiles();
1355
1356 $this->backend = $this->multiBackend;
1357 $this->tearDownFiles();
1358 $this->doTestGetFileHttpUrl( $source, $content );
1359 $this->tearDownFiles();
1360 }
1361
1362 private function doTestGetFileHttpUrl( $source, $content ) {
1363 $backendName = $this->backendClass();
1364
1365 $this->prepare( array( 'dir' => dirname( $source ) ) );
1366 $status = $this->backend->doOperation(
1367 array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
1368 $this->assertGoodStatus( $status,
1369 "Creation of file at $source succeeded ($backendName)." );
1370
1371 $url = $this->backend->getFileHttpUrl( array( 'src' => $source ) );
1372
1373 if ( $url !== null ) { // supported
1374 $data = Http::request( "GET", $url );
1375 $this->assertEquals( $content, $data,
1376 "HTTP GET of URL has right contents ($backendName)." );
1377 }
1378 }
1379
1380 public static function provider_testGetFileHttpUrl() {
1381 $cases = array();
1382
1383 $base = self::baseStorePath();
1384 $cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
1385 $cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
1386 $cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
1387
1388 return $cases;
1389 }
1390
1391 /**
1392 * @dataProvider provider_testPrepareAndClean
1393 * @covers FileBackend::prepare
1394 * @covers FileBackend::clean
1395 */
1396 public function testPrepareAndClean( $path, $isOK ) {
1397 $this->backend = $this->singleBackend;
1398 $this->doTestPrepareAndClean( $path, $isOK );
1399 $this->tearDownFiles();
1400
1401 $this->backend = $this->multiBackend;
1402 $this->doTestPrepareAndClean( $path, $isOK );
1403 $this->tearDownFiles();
1404 }
1405
1406 public static function provider_testPrepareAndClean() {
1407 $base = self::baseStorePath();
1408
1409 return array(
1410 array( "$base/unittest-cont1/e/a/z/some_file1.txt", true ),
1411 array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
1412 # Specific to FS backend with no basePath field set
1413 #array( "$base/unittest-cont3/a/z/some_file3.txt", false ),
1414 );
1415 }
1416
1417 private function doTestPrepareAndClean( $path, $isOK ) {
1418 $backendName = $this->backendClass();
1419
1420 $status = $this->prepare( array( 'dir' => dirname( $path ) ) );
1421 if ( $isOK ) {
1422 $this->assertGoodStatus( $status,
1423 "Preparing dir $path succeeded without warnings ($backendName)." );
1424 $this->assertEquals( true, $status->isOK(),
1425 "Preparing dir $path succeeded ($backendName)." );
1426 } else {
1427 $this->assertEquals( false, $status->isOK(),
1428 "Preparing dir $path failed ($backendName)." );
1429 }
1430
1431 $status = $this->backend->clean( array( 'dir' => dirname( $path ) ) );
1432 if ( $isOK ) {
1433 $this->assertGoodStatus( $status,
1434 "Cleaning dir $path succeeded without warnings ($backendName)." );
1435 $this->assertEquals( true, $status->isOK(),
1436 "Cleaning dir $path succeeded ($backendName)." );
1437 } else {
1438 $this->assertEquals( false, $status->isOK(),
1439 "Cleaning dir $path failed ($backendName)." );
1440 }
1441 }
1442
1443 public function testRecursiveClean() {
1444 $this->backend = $this->singleBackend;
1445 $this->doTestRecursiveClean();
1446 $this->tearDownFiles();
1447
1448 $this->backend = $this->multiBackend;
1449 $this->doTestRecursiveClean();
1450 $this->tearDownFiles();
1451 }
1452
1453 /**
1454 * @covers FileBackend::clean
1455 */
1456 private function doTestRecursiveClean() {
1457 $backendName = $this->backendClass();
1458
1459 $base = self::baseStorePath();
1460 $dirs = array(
1461 "$base/unittest-cont1",
1462 "$base/unittest-cont1/e",
1463 "$base/unittest-cont1/e/a",
1464 "$base/unittest-cont1/e/a/b",
1465 "$base/unittest-cont1/e/a/b/c",
1466 "$base/unittest-cont1/e/a/b/c/d0",
1467 "$base/unittest-cont1/e/a/b/c/d1",
1468 "$base/unittest-cont1/e/a/b/c/d2",
1469 "$base/unittest-cont1/e/a/b/c/d0/1",
1470 "$base/unittest-cont1/e/a/b/c/d0/2",
1471 "$base/unittest-cont1/e/a/b/c/d1/3",
1472 "$base/unittest-cont1/e/a/b/c/d1/4",
1473 "$base/unittest-cont1/e/a/b/c/d2/5",
1474 "$base/unittest-cont1/e/a/b/c/d2/6"
1475 );
1476 foreach ( $dirs as $dir ) {
1477 $status = $this->prepare( array( 'dir' => $dir ) );
1478 $this->assertGoodStatus( $status,
1479 "Preparing dir $dir succeeded without warnings ($backendName)." );
1480 }
1481
1482 if ( $this->backend instanceof FSFileBackend ) {
1483 foreach ( $dirs as $dir ) {
1484 $this->assertEquals( true, $this->backend->directoryExists( array( 'dir' => $dir ) ),
1485 "Dir $dir exists ($backendName)." );
1486 }
1487 }
1488
1489 $status = $this->backend->clean(
1490 array( 'dir' => "$base/unittest-cont1", 'recursive' => 1 ) );
1491 $this->assertGoodStatus( $status,
1492 "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." );
1493
1494 foreach ( $dirs as $dir ) {
1495 $this->assertEquals( false, $this->backend->directoryExists( array( 'dir' => $dir ) ),
1496 "Dir $dir no longer exists ($backendName)." );
1497 }
1498 }
1499
1500 // @todo testSecure
1501
1502 /**
1503 * @covers FileBackend::doOperations
1504 */
1505 public function testDoOperations() {
1506 $this->backend = $this->singleBackend;
1507 $this->tearDownFiles();
1508 $this->doTestDoOperations();
1509 $this->tearDownFiles();
1510
1511 $this->backend = $this->multiBackend;
1512 $this->tearDownFiles();
1513 $this->doTestDoOperations();
1514 $this->tearDownFiles();
1515 }
1516
1517 private function doTestDoOperations() {
1518 $base = self::baseStorePath();
1519
1520 $fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
1521 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1522 $fileB = "$base/unittest-cont1/e/a/b/fileB.txt";
1523 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1524 $fileC = "$base/unittest-cont1/e/a/b/fileC.txt";
1525 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1526 $fileD = "$base/unittest-cont1/e/a/b/fileD.txt";
1527
1528 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1529 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1530 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1531 $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1532 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1533 $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1534 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1535
1536 $status = $this->backend->doOperations( array(
1537 array( 'op' => 'describe', 'src' => $fileA,
1538 'headers' => array( 'X-Content-Length' => '91.3' ), 'disposition' => 'inline' ),
1539 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1540 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1541 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1542 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1543 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1544 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1545 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1546 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1547 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1548 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1549 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1550 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1551 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1552 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1553 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1554 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1555 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1556 // Does nothing
1557 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1558 // Does nothing
1559 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1560 // Does nothing
1561 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1562 // Does nothing
1563 array( 'op' => 'null' ),
1564 // Does nothing
1565 ) );
1566
1567 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1568 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1569 $this->assertEquals( 14, count( $status->success ),
1570 "Operation batch has correct success array" );
1571
1572 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1573 "File does not exist at $fileA" );
1574 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1575 "File does not exist at $fileB" );
1576 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1577 "File does not exist at $fileD" );
1578
1579 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1580 "File exists at $fileC" );
1581 $this->assertEquals( $fileBContents,
1582 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1583 "Correct file contents of $fileC" );
1584 $this->assertEquals( strlen( $fileBContents ),
1585 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1586 "Correct file size of $fileC" );
1587 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1588 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1589 "Correct file SHA-1 of $fileC" );
1590 }
1591
1592 /**
1593 * @covers FileBackend::doOperations
1594 */
1595 public function testDoOperationsPipeline() {
1596 $this->backend = $this->singleBackend;
1597 $this->tearDownFiles();
1598 $this->doTestDoOperationsPipeline();
1599 $this->tearDownFiles();
1600
1601 $this->backend = $this->multiBackend;
1602 $this->tearDownFiles();
1603 $this->doTestDoOperationsPipeline();
1604 $this->tearDownFiles();
1605 }
1606
1607 // concurrency orientated
1608 private function doTestDoOperationsPipeline() {
1609 $base = self::baseStorePath();
1610
1611 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1612 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1613 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1614
1615 $tmpNameA = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1616 file_put_contents( $tmpNameA, $fileAContents );
1617 $tmpNameB = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1618 file_put_contents( $tmpNameB, $fileBContents );
1619 $tmpNameC = TempFSFile::factory( "unittests_", 'txt' )->getPath();
1620 file_put_contents( $tmpNameC, $fileCContents );
1621
1622 $this->filesToPrune[] = $tmpNameA; # avoid file leaking
1623 $this->filesToPrune[] = $tmpNameB; # avoid file leaking
1624 $this->filesToPrune[] = $tmpNameC; # avoid file leaking
1625
1626 $fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
1627 $fileB = "$base/unittest-cont1/e/a/b/fileB.txt";
1628 $fileC = "$base/unittest-cont1/e/a/b/fileC.txt";
1629 $fileD = "$base/unittest-cont1/e/a/b/fileD.txt";
1630
1631 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1632 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1633 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1634 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1635 $this->prepare( array( 'dir' => dirname( $fileD ) ) );
1636
1637 $status = $this->backend->doOperations( array(
1638 array( 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ),
1639 array( 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ),
1640 array( 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ),
1641 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1642 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1643 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1644 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1645 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
1646 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
1647 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
1648 // Now: A:<A>, B:<empty>, C:<B>, D:<A>
1649 array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
1650 // Now: A:<A>, B:<empty>, C:<B>, D:<empty>
1651 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
1652 // Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
1653 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
1654 // Now: A:<B>, B:<empty>, C:<B>, D:<empty>
1655 array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
1656 // Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
1657 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1658 // Does nothing
1659 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1660 // Does nothing
1661 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
1662 // Does nothing
1663 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
1664 // Does nothing
1665 array( 'op' => 'null' ),
1666 // Does nothing
1667 ) );
1668
1669 $this->assertGoodStatus( $status, "Operation batch succeeded" );
1670 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1671 $this->assertEquals( 16, count( $status->success ),
1672 "Operation batch has correct success array" );
1673
1674 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
1675 "File does not exist at $fileA" );
1676 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1677 "File does not exist at $fileB" );
1678 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1679 "File does not exist at $fileD" );
1680
1681 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1682 "File exists at $fileC" );
1683 $this->assertEquals( $fileBContents,
1684 $this->backend->getFileContents( array( 'src' => $fileC ) ),
1685 "Correct file contents of $fileC" );
1686 $this->assertEquals( strlen( $fileBContents ),
1687 $this->backend->getFileSize( array( 'src' => $fileC ) ),
1688 "Correct file size of $fileC" );
1689 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1690 $this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
1691 "Correct file SHA-1 of $fileC" );
1692 }
1693
1694 /**
1695 * @covers FileBackend::doOperations
1696 */
1697 public function testDoOperationsFailing() {
1698 $this->backend = $this->singleBackend;
1699 $this->tearDownFiles();
1700 $this->doTestDoOperationsFailing();
1701 $this->tearDownFiles();
1702
1703 $this->backend = $this->multiBackend;
1704 $this->tearDownFiles();
1705 $this->doTestDoOperationsFailing();
1706 $this->tearDownFiles();
1707 }
1708
1709 private function doTestDoOperationsFailing() {
1710 $base = self::baseStorePath();
1711
1712 $fileA = "$base/unittest-cont2/a/b/fileA.txt";
1713 $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
1714 $fileB = "$base/unittest-cont2/a/b/fileB.txt";
1715 $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
1716 $fileC = "$base/unittest-cont2/a/b/fileC.txt";
1717 $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
1718 $fileD = "$base/unittest-cont2/a/b/fileD.txt";
1719
1720 $this->prepare( array( 'dir' => dirname( $fileA ) ) );
1721 $this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
1722 $this->prepare( array( 'dir' => dirname( $fileB ) ) );
1723 $this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
1724 $this->prepare( array( 'dir' => dirname( $fileC ) ) );
1725 $this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
1726
1727 $status = $this->backend->doOperations( array(
1728 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1729 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
1730 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1731 // Now: A:<A>, B:<B>, C:<A>, D:<empty>
1732 array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
1733 // Now: A:<A>, B:<B>, C:<A>, D:<B>
1734 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
1735 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1736 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
1737 // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
1738 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
1739 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1740 array( 'op' => 'delete', 'src' => $fileD ),
1741 // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
1742 array( 'op' => 'null' ),
1743 // Does nothing
1744 ), array( 'force' => 1 ) );
1745
1746 $this->assertNotEquals( array(), $status->errors, "Operation had warnings" );
1747 $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
1748 $this->assertEquals( 8, count( $status->success ),
1749 "Operation batch has correct success array" );
1750
1751 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
1752 "File does not exist at $fileB" );
1753 $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
1754 "File does not exist at $fileD" );
1755
1756 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ),
1757 "File does not exist at $fileA" );
1758 $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
1759 "File exists at $fileC" );
1760 $this->assertEquals( $fileBContents,
1761 $this->backend->getFileContents( array( 'src' => $fileA ) ),
1762 "Correct file contents of $fileA" );
1763 $this->assertEquals( strlen( $fileBContents ),
1764 $this->backend->getFileSize( array( 'src' => $fileA ) ),
1765 "Correct file size of $fileA" );
1766 $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
1767 $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
1768 "Correct file SHA-1 of $fileA" );
1769 }
1770
1771 /**
1772 * @covers FileBackend::getFileList
1773 */
1774 public function testGetFileList() {
1775 $this->backend = $this->singleBackend;
1776 $this->tearDownFiles();
1777 $this->doTestGetFileList();
1778 $this->tearDownFiles();
1779
1780 $this->backend = $this->multiBackend;
1781 $this->tearDownFiles();
1782 $this->doTestGetFileList();
1783 $this->tearDownFiles();
1784 }
1785
1786 private function doTestGetFileList() {
1787 $backendName = $this->backendClass();
1788 $base = self::baseStorePath();
1789
1790 // Should have no errors
1791 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont-notexists" ) );
1792
1793 $files = array(
1794 "$base/unittest-cont1/e/test1.txt",
1795 "$base/unittest-cont1/e/test2.txt",
1796 "$base/unittest-cont1/e/test3.txt",
1797 "$base/unittest-cont1/e/subdir1/test1.txt",
1798 "$base/unittest-cont1/e/subdir1/test2.txt",
1799 "$base/unittest-cont1/e/subdir2/test3.txt",
1800 "$base/unittest-cont1/e/subdir2/test4.txt",
1801 "$base/unittest-cont1/e/subdir2/subdir/test1.txt",
1802 "$base/unittest-cont1/e/subdir2/subdir/test2.txt",
1803 "$base/unittest-cont1/e/subdir2/subdir/test3.txt",
1804 "$base/unittest-cont1/e/subdir2/subdir/test4.txt",
1805 "$base/unittest-cont1/e/subdir2/subdir/test5.txt",
1806 "$base/unittest-cont1/e/subdir2/subdir/sub/test0.txt",
1807 "$base/unittest-cont1/e/subdir2/subdir/sub/120-px-file.txt",
1808 );
1809
1810 // Add the files
1811 $ops = array();
1812 foreach ( $files as $file ) {
1813 $this->prepare( array( 'dir' => dirname( $file ) ) );
1814 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1815 }
1816 $status = $this->backend->doQuickOperations( $ops );
1817 $this->assertGoodStatus( $status,
1818 "Creation of files succeeded ($backendName)." );
1819 $this->assertEquals( true, $status->isOK(),
1820 "Creation of files succeeded with OK status ($backendName)." );
1821
1822 // Expected listing at root
1823 $expected = array(
1824 "e/test1.txt",
1825 "e/test2.txt",
1826 "e/test3.txt",
1827 "e/subdir1/test1.txt",
1828 "e/subdir1/test2.txt",
1829 "e/subdir2/test3.txt",
1830 "e/subdir2/test4.txt",
1831 "e/subdir2/subdir/test1.txt",
1832 "e/subdir2/subdir/test2.txt",
1833 "e/subdir2/subdir/test3.txt",
1834 "e/subdir2/subdir/test4.txt",
1835 "e/subdir2/subdir/test5.txt",
1836 "e/subdir2/subdir/sub/test0.txt",
1837 "e/subdir2/subdir/sub/120-px-file.txt",
1838 );
1839 sort( $expected );
1840
1841 // Actual listing (no trailing slash) at root
1842 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
1843 $list = $this->listToArray( $iter );
1844 sort( $list );
1845 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1846
1847 // Actual listing (no trailing slash) at root with advise
1848 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1", 'adviseStat' => 1 ) );
1849 $list = $this->listToArray( $iter );
1850 sort( $list );
1851 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1852
1853 // Actual listing (with trailing slash) at root
1854 $list = array();
1855 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
1856 foreach ( $iter as $file ) {
1857 $list[] = $file;
1858 }
1859 sort( $list );
1860 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1861
1862 // Expected listing at subdir
1863 $expected = array(
1864 "test1.txt",
1865 "test2.txt",
1866 "test3.txt",
1867 "test4.txt",
1868 "test5.txt",
1869 "sub/test0.txt",
1870 "sub/120-px-file.txt",
1871 );
1872 sort( $expected );
1873
1874 // Actual listing (no trailing slash) at subdir
1875 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
1876 $list = $this->listToArray( $iter );
1877 sort( $list );
1878 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1879
1880 // Actual listing (no trailing slash) at subdir with advise
1881 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir", 'adviseStat' => 1 ) );
1882 $list = $this->listToArray( $iter );
1883 sort( $list );
1884 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1885
1886 // Actual listing (with trailing slash) at subdir
1887 $list = array();
1888 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir/" ) );
1889 foreach ( $iter as $file ) {
1890 $list[] = $file;
1891 }
1892 sort( $list );
1893 $this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
1894
1895 // Actual listing (using iterator second time)
1896 $list = $this->listToArray( $iter );
1897 sort( $list );
1898 $this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
1899
1900 // Actual listing (top files only) at root
1901 $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1" ) );
1902 $list = $this->listToArray( $iter );
1903 sort( $list );
1904 $this->assertEquals( array(), $list, "Correct top file listing ($backendName)." );
1905
1906 // Expected listing (top files only) at subdir
1907 $expected = array(
1908 "test1.txt",
1909 "test2.txt",
1910 "test3.txt",
1911 "test4.txt",
1912 "test5.txt"
1913 );
1914 sort( $expected );
1915
1916 // Actual listing (top files only) at subdir
1917 $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
1918 $list = $this->listToArray( $iter );
1919 sort( $list );
1920 $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
1921
1922 // Actual listing (top files only) at subdir with advise
1923 $iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir", 'adviseStat' => 1 ) );
1924 $list = $this->listToArray( $iter );
1925 sort( $list );
1926 $this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
1927
1928 foreach ( $files as $file ) { // clean up
1929 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
1930 }
1931
1932 $iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
1933 foreach ( $iter as $iter ) {
1934 // no errors
1935 }
1936 }
1937
1938 /**
1939 * @covers FileBackend::getTopDirectoryList
1940 * @covers FileBackend::getDirectoryList
1941 */
1942 public function testGetDirectoryList() {
1943 $this->backend = $this->singleBackend;
1944 $this->tearDownFiles();
1945 $this->doTestGetDirectoryList();
1946 $this->tearDownFiles();
1947
1948 $this->backend = $this->multiBackend;
1949 $this->tearDownFiles();
1950 $this->doTestGetDirectoryList();
1951 $this->tearDownFiles();
1952 }
1953
1954 private function doTestGetDirectoryList() {
1955 $backendName = $this->backendClass();
1956
1957 $base = self::baseStorePath();
1958 $files = array(
1959 "$base/unittest-cont1/e/test1.txt",
1960 "$base/unittest-cont1/e/test2.txt",
1961 "$base/unittest-cont1/e/test3.txt",
1962 "$base/unittest-cont1/e/subdir1/test1.txt",
1963 "$base/unittest-cont1/e/subdir1/test2.txt",
1964 "$base/unittest-cont1/e/subdir2/test3.txt",
1965 "$base/unittest-cont1/e/subdir2/test4.txt",
1966 "$base/unittest-cont1/e/subdir2/subdir/test1.txt",
1967 "$base/unittest-cont1/e/subdir3/subdir/test2.txt",
1968 "$base/unittest-cont1/e/subdir4/subdir/test3.txt",
1969 "$base/unittest-cont1/e/subdir4/subdir/test4.txt",
1970 "$base/unittest-cont1/e/subdir4/subdir/test5.txt",
1971 "$base/unittest-cont1/e/subdir4/subdir/sub/test0.txt",
1972 "$base/unittest-cont1/e/subdir4/subdir/sub/120-px-file.txt",
1973 );
1974
1975 // Add the files
1976 $ops = array();
1977 foreach ( $files as $file ) {
1978 $this->prepare( array( 'dir' => dirname( $file ) ) );
1979 $ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
1980 }
1981 $status = $this->backend->doQuickOperations( $ops );
1982 $this->assertGoodStatus( $status,
1983 "Creation of files succeeded ($backendName)." );
1984 $this->assertEquals( true, $status->isOK(),
1985 "Creation of files succeeded with OK status ($backendName)." );
1986
1987 $this->assertEquals( true,
1988 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) ),
1989 "Directory exists in ($backendName)." );
1990 $this->assertEquals( true,
1991 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) ),
1992 "Directory exists in ($backendName)." );
1993 $this->assertEquals( false,
1994 $this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/test1.txt" ) ),
1995 "Directory does not exists in ($backendName)." );
1996
1997 // Expected listing
1998 $expected = array(
1999 "e",
2000 );
2001 sort( $expected );
2002
2003 // Actual listing (no trailing slash)
2004 $list = array();
2005 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) );
2006 foreach ( $iter as $file ) {
2007 $list[] = $file;
2008 }
2009 sort( $list );
2010
2011 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
2012
2013 // Expected listing
2014 $expected = array(
2015 "subdir1",
2016 "subdir2",
2017 "subdir3",
2018 "subdir4",
2019 );
2020 sort( $expected );
2021
2022 // Actual listing (no trailing slash)
2023 $list = array();
2024 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e" ) );
2025 foreach ( $iter as $file ) {
2026 $list[] = $file;
2027 }
2028 sort( $list );
2029
2030 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
2031
2032 // Actual listing (with trailing slash)
2033 $list = array();
2034 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/" ) );
2035 foreach ( $iter as $file ) {
2036 $list[] = $file;
2037 }
2038 sort( $list );
2039
2040 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
2041
2042 // Expected listing
2043 $expected = array(
2044 "subdir",
2045 );
2046 sort( $expected );
2047
2048 // Actual listing (no trailing slash)
2049 $list = array();
2050 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2" ) );
2051 foreach ( $iter as $file ) {
2052 $list[] = $file;
2053 }
2054 sort( $list );
2055
2056 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
2057
2058 // Actual listing (with trailing slash)
2059 $list = array();
2060 $iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2/" ) );
2061 foreach ( $iter as $file ) {
2062 $list[] = $file;
2063 }
2064 sort( $list );
2065
2066 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
2067
2068 // Actual listing (using iterator second time)
2069 $list = array();
2070 foreach ( $iter as $file ) {
2071 $list[] = $file;
2072 }
2073 sort( $list );
2074
2075 $this->assertEquals( $expected, $list, "Correct top dir listing ($backendName), second iteration." );
2076
2077 // Expected listing (recursive)
2078 $expected = array(
2079 "e",
2080 "e/subdir1",
2081 "e/subdir2",
2082 "e/subdir3",
2083 "e/subdir4",
2084 "e/subdir2/subdir",
2085 "e/subdir3/subdir",
2086 "e/subdir4/subdir",
2087 "e/subdir4/subdir/sub",
2088 );
2089 sort( $expected );
2090
2091 // Actual listing (recursive)
2092 $list = array();
2093 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
2094 foreach ( $iter as $file ) {
2095 $list[] = $file;
2096 }
2097 sort( $list );
2098
2099 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
2100
2101 // Expected listing (recursive)
2102 $expected = array(
2103 "subdir",
2104 "subdir/sub",
2105 );
2106 sort( $expected );
2107
2108 // Actual listing (recursive)
2109 $list = array();
2110 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir4" ) );
2111 foreach ( $iter as $file ) {
2112 $list[] = $file;
2113 }
2114 sort( $list );
2115
2116 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
2117
2118 // Actual listing (recursive, second time)
2119 $list = array();
2120 foreach ( $iter as $file ) {
2121 $list[] = $file;
2122 }
2123 sort( $list );
2124
2125 $this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
2126
2127 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) );
2128 $items = $this->listToArray( $iter );
2129 $this->assertEquals( array(), $items, "Directory listing is empty." );
2130
2131 foreach ( $files as $file ) { // clean up
2132 $this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
2133 }
2134
2135 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
2136 foreach ( $iter as $file ) {
2137 // no errors
2138 }
2139
2140 $items = $this->listToArray( $iter );
2141 $this->assertEquals( array(), $items, "Directory listing is empty." );
2142
2143 $iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/not/exists" ) );
2144 $items = $this->listToArray( $iter );
2145 $this->assertEquals( array(), $items, "Directory listing is empty." );
2146 }
2147
2148 /**
2149 * @covers FileBackend::lockFiles
2150 * @covers FileBackend::unlockFiles
2151 */
2152 public function testLockCalls() {
2153 $this->backend = $this->singleBackend;
2154 $this->doTestLockCalls();
2155 }
2156
2157 private function doTestLockCalls() {
2158 $backendName = $this->backendClass();
2159
2160 $paths = array(
2161 "test1.txt",
2162 "test2.txt",
2163 "test3.txt",
2164 "subdir1",
2165 "subdir1", // duplicate
2166 "subdir1/test1.txt",
2167 "subdir1/test2.txt",
2168 "subdir2",
2169 "subdir2", // duplicate
2170 "subdir2/test3.txt",
2171 "subdir2/test4.txt",
2172 "subdir2/subdir",
2173 "subdir2/subdir/test1.txt",
2174 "subdir2/subdir/test2.txt",
2175 "subdir2/subdir/test3.txt",
2176 "subdir2/subdir/test4.txt",
2177 "subdir2/subdir/test5.txt",
2178 "subdir2/subdir/sub",
2179 "subdir2/subdir/sub/test0.txt",
2180 "subdir2/subdir/sub/120-px-file.txt",
2181 );
2182
2183 for ( $i = 0; $i < 25; $i++ ) {
2184 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
2185 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2186 "Locking of files succeeded ($backendName) ($i)." );
2187 $this->assertEquals( true, $status->isOK(),
2188 "Locking of files succeeded with OK status ($backendName) ($i)." );
2189
2190 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
2191 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2192 "Locking of files succeeded ($backendName) ($i)." );
2193 $this->assertEquals( true, $status->isOK(),
2194 "Locking of files succeeded with OK status ($backendName) ($i)." );
2195
2196 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
2197 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2198 "Locking of files succeeded ($backendName) ($i)." );
2199 $this->assertEquals( true, $status->isOK(),
2200 "Locking of files succeeded with OK status ($backendName) ($i)." );
2201
2202 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
2203 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2204 "Locking of files succeeded ($backendName). ($i)" );
2205 $this->assertEquals( true, $status->isOK(),
2206 "Locking of files succeeded with OK status ($backendName) ($i)." );
2207
2208 ## Flip the acquire/release ordering around ##
2209
2210 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
2211 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2212 "Locking of files succeeded ($backendName) ($i)." );
2213 $this->assertEquals( true, $status->isOK(),
2214 "Locking of files succeeded with OK status ($backendName) ($i)." );
2215
2216 $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
2217 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2218 "Locking of files succeeded ($backendName) ($i)." );
2219 $this->assertEquals( true, $status->isOK(),
2220 "Locking of files succeeded with OK status ($backendName) ($i)." );
2221
2222 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
2223 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2224 "Locking of files succeeded ($backendName). ($i)" );
2225 $this->assertEquals( true, $status->isOK(),
2226 "Locking of files succeeded with OK status ($backendName) ($i)." );
2227
2228 $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
2229 $this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
2230 "Locking of files succeeded ($backendName) ($i)." );
2231 $this->assertEquals( true, $status->isOK(),
2232 "Locking of files succeeded with OK status ($backendName) ($i)." );
2233 }
2234
2235 $status = Status::newGood();
2236 $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status );
2237 $this->assertType( 'ScopedLock', $sl,
2238 "Scoped locking of files succeeded ($backendName)." );
2239 $this->assertEquals( array(), $status->errors,
2240 "Scoped locking of files succeeded ($backendName)." );
2241 $this->assertEquals( true, $status->isOK(),
2242 "Scoped locking of files succeeded with OK status ($backendName)." );
2243
2244 ScopedLock::release( $sl );
2245 $this->assertEquals( null, $sl,
2246 "Scoped unlocking of files succeeded ($backendName)." );
2247 $this->assertEquals( array(), $status->errors,
2248 "Scoped unlocking of files succeeded ($backendName)." );
2249 $this->assertEquals( true, $status->isOK(),
2250 "Scoped unlocking of files succeeded with OK status ($backendName)." );
2251 }
2252
2253 // helper function
2254 private function listToArray( $iter ) {
2255 return is_array( $iter ) ? $iter : iterator_to_array( $iter );
2256 }
2257
2258 // test helper wrapper for backend prepare() function
2259 private function prepare( array $params ) {
2260 return $this->backend->prepare( $params );
2261 }
2262
2263 // test helper wrapper for backend prepare() function
2264 private function create( array $params ) {
2265 $params['op'] = 'create';
2266
2267 return $this->backend->doQuickOperations( array( $params ) );
2268 }
2269
2270 function tearDownFiles() {
2271 foreach ( $this->filesToPrune as $file ) {
2272 if ( is_file( $file ) ) {
2273 unlink( $file );
2274 }
2275 }
2276 $containers = array( 'unittest-cont1', 'unittest-cont2' );
2277 foreach ( $containers as $container ) {
2278 $this->deleteFiles( $container );
2279 }
2280 $this->filesToPrune = array();
2281 }
2282
2283 private function deleteFiles( $container ) {
2284 $base = self::baseStorePath();
2285 $iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
2286 if ( $iter ) {
2287 foreach ( $iter as $file ) {
2288 $this->backend->quickDelete( array( 'src' => "$base/$container/$file" ) );
2289 }
2290 // free the directory, to avoid Permission denied under windows on rmdir
2291 unset( $iter );
2292 }
2293 $this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
2294 }
2295
2296 function assertBackendPathsConsistent( array $paths ) {
2297 if ( $this->backend instanceof FileBackendMultiWrite ) {
2298 $status = $this->backend->consistencyCheck( $paths );
2299 $this->assertGoodStatus( $status, "Files synced: " . implode( ',', $paths ) );
2300 }
2301 }
2302
2303 function assertGoodStatus( $status, $msg ) {
2304 $this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg );
2305 }
2306 }