bc14f48762168d19e5b7cc517cd2c059c025b065
5 class StoreBatchTest
extends MediaWikiTestCase
{
7 public function setUp() {
9 $tmpDir = wfTempDir() . '/' . time() . '-' . mt_rand();
10 $this->repo
= new FSRepo( array(
12 'backend' => new FSFileBackend( array(
13 'name' => 'local-backend',
14 'lockManager' => 'nullLockManager',
15 'containerPaths' => array(
16 'test-public' => "$tmpDir/public",
17 'test-thumb' => "$tmpDir/thumb",
18 'test-temp' => "$tmpDir/temp",
19 'test-deleted' => "$tmpDir/deleted",
23 $this->date
= gmdate( "YmdHis" );
24 $this->createdFiles
= array();
26 'sysop' => new ApiTestUser(
27 'Uploadstashtestsysop',
28 'Upload Stash Test Sysop',
29 'upload_stash_test_sysop@example.com',
32 'uploader' => new ApiTestUser(
33 'Uploadstashtestuser',
34 'Upload Stash Test User',
35 'upload_stash_test_user@example.com',
42 * Store a file or virtual URL source into a media file name.
44 * @param $originalName string The title of the image
45 * @param $srcPath string The filepath or virtual URL
46 * @param $flags integer Flags to pass into repo::store().
48 private function storeit($originalName, $srcPath, $flags) {
49 $hashPath = $this->repo
->getHashPath( $originalName );
50 $dstRel = "$hashPath{$this->date}!$originalName";
51 $dstUrlRel = $hashPath . $this->date
. '!' . rawurlencode( $originalName );
53 $result = $this->repo
->store( $srcPath, 'temp', $dstRel, $flags );
54 $result->value
= $this->repo
->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
55 $this->createdFiles
[] = $result->value
;
60 * Test storing a file using different flags.
62 * @param $fn string The title of the image
63 * @param $infn string The name of the file (in the filesystem)
64 * @param $otherfn string The name of the different file (in the filesystem)
65 * @param $fromrepo logical 'true' if we want to copy from a virtual URL out of the Repo.
67 private function storecohort($fn, $infn, $otherfn, $fromrepo) {
68 $f = $this->storeit( $fn, $infn, 0 );
69 $this->assertTrue( $f->isOK(), 'failed to store a new file' );
70 $this->assertEquals( $f->failCount
, 0, "counts wrong {$f->successCount} {$f->failCount}" );
71 $this->assertEquals( $f->successCount
, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
73 $f = $this->storeit( "Other-$fn", $infn, FileRepo
::OVERWRITE
);
76 // This should work because we're allowed to overwrite
77 $f = $this->storeit( $fn, $infn, FileRepo
::OVERWRITE
);
78 $this->assertTrue( $f->isOK(), 'We should be allowed to overwrite' );
79 $this->assertEquals( $f->failCount
, 0, "counts wrong {$f->successCount} {$f->failCount}" );
80 $this->assertEquals( $f->successCount
, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
81 // This should fail because we're overwriting.
82 $f = $this->storeit( $fn, $infn, 0 );
83 $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite' );
84 $this->assertEquals( $f->failCount
, 1, "counts wrong {$f->successCount} {$f->failCount}" );
85 $this->assertEquals( $f->successCount
, 0 , "counts wrong {$f->successCount} {$f->failCount}" );
86 // This should succeed because we're overwriting the same content.
87 $f = $this->storeit( $fn, $infn, FileRepo
::OVERWRITE_SAME
);
88 $this->assertTrue( $f->isOK(), 'We should be able to overwrite the same content' );
89 $this->assertEquals( $f->failCount
, 0, "counts wrong {$f->successCount} {$f->failCount}" );
90 $this->assertEquals( $f->successCount
, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
91 // This should fail because we're overwriting different content.
93 $f = $this->storeit( "Other-$fn", $otherfn, FileRepo
::OVERWRITE
);
96 $f = $this->storeit( $fn, $otherfn, FileRepo
::OVERWRITE_SAME
);
97 $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite different content' );
98 $this->assertEquals( $f->failCount
, 1, "counts wrong {$f->successCount} {$f->failCount}" );
99 $this->assertEquals( $f->successCount
, 0 , "counts wrong {$f->successCount} {$f->failCount}" );
102 public function teststore() {
104 $this->storecohort( "Test1.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", false );
105 $this->storecohort( "Test2.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", true );
108 public function tearDown() {
109 $this->repo
->cleanupBatch( $this->createdFiles
);