2011-10-11 19:49:29 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-01-12 18:44:00 +00:00
|
|
|
* @group FileRepo
|
2011-10-11 19:49:29 +00:00
|
|
|
*/
|
|
|
|
|
class StoreBatchTest extends MediaWikiTestCase {
|
|
|
|
|
|
|
|
|
|
public function setUp() {
|
|
|
|
|
parent::setUp();
|
2012-01-10 14:26:17 +00:00
|
|
|
|
|
|
|
|
# Forge a FSRepo object to not have to rely on local wiki settings
|
2012-01-20 20:15:26 +00:00
|
|
|
$this->tmpDir = wfTempDir() . '/store-batch-test-' . time() . '-' . mt_rand();
|
2012-01-07 06:13:01 +00:00
|
|
|
$this->repo = new FSRepo( array(
|
|
|
|
|
'name' => 'test',
|
|
|
|
|
'backend' => new FSFileBackend( array(
|
|
|
|
|
'name' => 'local-backend',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
|
|
|
|
'containerPaths' => array(
|
2012-01-20 20:15:26 +00:00
|
|
|
'test-public' => $this->tmpDir . "/public",
|
|
|
|
|
'test-thumb' => $this->tmpDir . "/thumb",
|
|
|
|
|
'test-temp' => $this->tmpDir . "/temp",
|
|
|
|
|
'test-deleted' => $this->tmpDir . "/deleted",
|
2012-01-07 06:13:01 +00:00
|
|
|
)
|
|
|
|
|
) )
|
|
|
|
|
) );
|
2012-01-10 14:26:17 +00:00
|
|
|
|
2011-10-11 19:49:29 +00:00
|
|
|
$this->date = gmdate( "YmdHis" );
|
2011-12-16 19:59:58 +00:00
|
|
|
$this->createdFiles = array();
|
2012-01-10 14:26:17 +00:00
|
|
|
|
2012-01-18 15:50:00 +00:00
|
|
|
// ApiTestUser requires a database connection. Code below does not
|
|
|
|
|
// seem to be needed so it is commented out to not make this test
|
|
|
|
|
// requires a database connection.
|
|
|
|
|
/**
|
2011-10-11 19:49:29 +00:00
|
|
|
$this->users = array(
|
|
|
|
|
'sysop' => new ApiTestUser(
|
|
|
|
|
'Uploadstashtestsysop',
|
|
|
|
|
'Upload Stash Test Sysop',
|
2011-12-21 22:22:01 +00:00
|
|
|
'upload_stash_test_sysop@example.com',
|
2011-10-11 19:49:29 +00:00
|
|
|
array( 'sysop' )
|
|
|
|
|
),
|
|
|
|
|
'uploader' => new ApiTestUser(
|
|
|
|
|
'Uploadstashtestuser',
|
|
|
|
|
'Upload Stash Test User',
|
2011-12-21 22:22:01 +00:00
|
|
|
'upload_stash_test_user@example.com',
|
2011-10-11 19:49:29 +00:00
|
|
|
array()
|
|
|
|
|
)
|
|
|
|
|
);
|
2012-01-18 15:50:00 +00:00
|
|
|
**/
|
2011-10-11 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a file or virtual URL source into a media file name.
|
|
|
|
|
*
|
|
|
|
|
* @param $originalName string The title of the image
|
|
|
|
|
* @param $srcPath string The filepath or virtual URL
|
|
|
|
|
* @param $flags integer Flags to pass into repo::store().
|
|
|
|
|
*/
|
|
|
|
|
private function storeit($originalName, $srcPath, $flags) {
|
|
|
|
|
$hashPath = $this->repo->getHashPath( $originalName );
|
|
|
|
|
$dstRel = "$hashPath{$this->date}!$originalName";
|
|
|
|
|
$dstUrlRel = $hashPath . $this->date . '!' . rawurlencode( $originalName );
|
|
|
|
|
|
|
|
|
|
$result = $this->repo->store( $srcPath, 'temp', $dstRel, $flags );
|
|
|
|
|
$result->value = $this->repo->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
|
2011-12-16 19:59:58 +00:00
|
|
|
$this->createdFiles[] = $result->value;
|
2011-10-11 19:49:29 +00:00
|
|
|
return $result;
|
|
|
|
|
}
|
2012-01-07 06:13:01 +00:00
|
|
|
|
2011-10-11 19:49:29 +00:00
|
|
|
/**
|
|
|
|
|
* Test storing a file using different flags.
|
|
|
|
|
*
|
|
|
|
|
* @param $fn string The title of the image
|
|
|
|
|
* @param $infn string The name of the file (in the filesystem)
|
|
|
|
|
* @param $otherfn string The name of the different file (in the filesystem)
|
|
|
|
|
* @param $fromrepo logical 'true' if we want to copy from a virtual URL out of the Repo.
|
|
|
|
|
*/
|
|
|
|
|
private function storecohort($fn, $infn, $otherfn, $fromrepo) {
|
|
|
|
|
$f = $this->storeit( $fn, $infn, 0 );
|
|
|
|
|
$this->assertTrue( $f->isOK(), 'failed to store a new file' );
|
2011-10-16 22:18:18 +00:00
|
|
|
$this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
|
|
|
|
|
$this->assertEquals( $f->successCount, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
|
2011-10-11 19:49:29 +00:00
|
|
|
if ( $fromrepo ) {
|
|
|
|
|
$f = $this->storeit( "Other-$fn", $infn, FileRepo::OVERWRITE);
|
|
|
|
|
$infn = $f->value;
|
|
|
|
|
}
|
|
|
|
|
// This should work because we're allowed to overwrite
|
|
|
|
|
$f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE );
|
|
|
|
|
$this->assertTrue( $f->isOK(), 'We should be allowed to overwrite' );
|
2011-10-16 22:18:18 +00:00
|
|
|
$this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
|
|
|
|
|
$this->assertEquals( $f->successCount, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
|
2011-10-11 19:49:29 +00:00
|
|
|
// This should fail because we're overwriting.
|
|
|
|
|
$f = $this->storeit( $fn, $infn, 0 );
|
|
|
|
|
$this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite' );
|
2011-10-16 22:18:18 +00:00
|
|
|
$this->assertEquals( $f->failCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
|
|
|
|
|
$this->assertEquals( $f->successCount, 0 , "counts wrong {$f->successCount} {$f->failCount}" );
|
2011-10-11 19:49:29 +00:00
|
|
|
// This should succeed because we're overwriting the same content.
|
|
|
|
|
$f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE_SAME );
|
|
|
|
|
$this->assertTrue( $f->isOK(), 'We should be able to overwrite the same content' );
|
2011-10-16 22:18:18 +00:00
|
|
|
$this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
|
|
|
|
|
$this->assertEquals( $f->successCount, 1 , "counts wrong {$f->successCount} {$f->failCount}" );
|
2011-10-11 19:49:29 +00:00
|
|
|
// This should fail because we're overwriting different content.
|
|
|
|
|
if ( $fromrepo ) {
|
|
|
|
|
$f = $this->storeit( "Other-$fn", $otherfn, FileRepo::OVERWRITE);
|
|
|
|
|
$otherfn = $f->value;
|
|
|
|
|
}
|
|
|
|
|
$f = $this->storeit( $fn, $otherfn, FileRepo::OVERWRITE_SAME );
|
|
|
|
|
$this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite different content' );
|
2011-10-16 22:18:18 +00:00
|
|
|
$this->assertEquals( $f->failCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
|
|
|
|
|
$this->assertEquals( $f->successCount, 0 , "counts wrong {$f->successCount} {$f->failCount}" );
|
2011-10-11 19:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function teststore() {
|
|
|
|
|
global $IP;
|
|
|
|
|
$this->storecohort( "Test1.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", false );
|
|
|
|
|
$this->storecohort( "Test2.png", "$IP/skins/monobook/wiki.png", "$IP/skins/monobook/video.png", true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function tearDown() {
|
2011-12-16 20:01:08 +00:00
|
|
|
$this->repo->cleanupBatch( $this->createdFiles );
|
2012-01-20 20:15:26 +00:00
|
|
|
foreach ( array( "temp/0/06", "temp/0", "temp/4/4d", "temp/4", "temp/3/31", "temp/3", "temp", "" ) as $tmp ) {
|
|
|
|
|
rmdir( $this->tmpDir . "/" . $tmp );
|
|
|
|
|
}
|
2011-10-11 19:49:29 +00:00
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
}
|