5 class StoreBatchTest
extends MediaWikiTestCase
{
7 public function setUp() {
10 $this->repo
= RepoGroup
::singleton()->getLocalRepo();
11 $this->date
= gmdate( "YmdHis" );
12 $this->createdFiles
= array();
14 'sysop' => new ApiTestUser(
15 'Uploadstashtestsysop',
16 'Upload Stash Test Sysop',
17 'upload_stash_test_sysop@sample.com',
20 'uploader' => new ApiTestUser(
21 'Uploadstashtestuser',
22 'Upload Stash Test User',
23 'upload_stash_test_user@sample.com',
30 * Store a file or virtual URL source into a media file name.
32 * @param $originalName string The title of the image
33 * @param $srcPath string The filepath or virtual URL
34 * @param $flags integer Flags to pass into repo::store().
36 private function storeit($originalName, $srcPath, $flags) {
37 $hashPath = $this->repo
->getHashPath( $originalName );
38 $dstRel = "$hashPath{$this->date}!$originalName";
39 $dstUrlRel = $hashPath . $this->date
. '!' . rawurlencode( $originalName );
41 $result = $this->repo
->store( $srcPath, 'temp', $dstRel, $flags );
42 $result->value
= $this->repo
->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
43 $this->createdFiles
[] = $result->value
;
49 * Test storing a file using different flags.
51 * @param $fn string The title of the image
52 * @param $infn string The name of the file (in the filesystem)
53 * @param $otherfn string The name of the different file (in the filesystem)
54 * @param $fromrepo logical 'true' if we want to copy from a virtual URL out of the Repo.
56 private function storecohort($fn, $infn, $otherfn, $fromrepo) {
57 $f = $this->storeit( $fn, $infn, 0 );
58 $this->assertTrue( $f->isOK(), 'failed to store a new file' );
59 $this->assertEquals( $f->failCount
, 0, "counts wrong {$f->successCount} {$f->failCount}" );
60 $this->assertEquals( $f->successCount
, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
62 $f = $this->storeit( "Other-$fn", $infn, FileRepo
::OVERWRITE
);
65 // This should work because we're allowed to overwrite
66 $f = $this->storeit( $fn, $infn, FileRepo
::OVERWRITE
);
67 $this->assertTrue( $f->isOK(), 'We should be allowed to overwrite' );
68 $this->assertEquals( $f->failCount
, 0, "counts wrong {$f->successCount} {$f->failCount}" );
69 $this->assertEquals( $f->successCount
, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
70 // This should fail because we're overwriting.
71 $f = $this->storeit( $fn, $infn, 0 );
72 $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite' );
73 $this->assertEquals( $f->failCount
, 1, "counts wrong {$f->successCount} {$f->failCount}" );
74 $this->assertEquals( $f->successCount
, 0 , "counts wrong {$f->successCount} {$f->failCount}" );
75 // This should succeed because we're overwriting the same content.
76 $f = $this->storeit( $fn, $infn, FileRepo
::OVERWRITE_SAME
);
77 $this->assertTrue( $f->isOK(), 'We should be able to overwrite the same content' );
78 $this->assertEquals( $f->failCount
, 0, "counts wrong {$f->successCount} {$f->failCount}" );
79 $this->assertEquals( $f->successCount
, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
80 // This should fail because we're overwriting different content.
82 $f = $this->storeit( "Other-$fn", $otherfn, FileRepo
::OVERWRITE
);
85 $f = $this->storeit( $fn, $otherfn, FileRepo
::OVERWRITE_SAME
);
86 $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite different content' );
87 $this->assertEquals( $f->failCount
, 1, "counts wrong {$f->successCount} {$f->failCount}" );
88 $this->assertEquals( $f->successCount
, 0 , "counts wrong {$f->successCount} {$f->failCount}" );
91 public function teststore() {
93 $this->storecohort( "Test1.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", false );
94 $this->storecohort( "Test2.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", true );
97 public function tearDown() {
98 $this->repo
->cleanupBatch( $this->createdFile
);