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