2011-12-20 03:52:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-01-12 18:44:00 +00:00
|
|
|
/**
|
|
|
|
|
* @group FileRepo
|
|
|
|
|
* @TODO: fix empty dir leakage
|
|
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
class FileBackendTest extends MediaWikiTestCase {
|
|
|
|
|
private $backend, $multiBackend;
|
|
|
|
|
private $filesToPrune, $pathsToPrune;
|
|
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
parent::setUp();
|
2012-01-20 19:46:27 +00:00
|
|
|
$tmpDir = wfTempDir() . '/file-backend-test-' . time() . '-' . mt_rand();
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->singleBackend = new FSFileBackend( array(
|
2011-12-20 03:52:06 +00:00
|
|
|
'name' => 'localtesting',
|
|
|
|
|
'lockManager' => 'fsLockManager',
|
|
|
|
|
'containerPaths' => array(
|
2012-01-08 08:40:00 +00:00
|
|
|
'cont1' => "$tmpDir/localtesting/cont1",
|
|
|
|
|
'cont2' => "$tmpDir/localtesting/cont2" )
|
2011-12-20 03:52:06 +00:00
|
|
|
) );
|
|
|
|
|
$this->multiBackend = new FileBackendMultiWrite( array(
|
2012-01-08 08:40:00 +00:00
|
|
|
'name' => 'localtesting',
|
2011-12-20 03:52:06 +00:00
|
|
|
'lockManager' => 'fsLockManager',
|
|
|
|
|
'backends' => array(
|
|
|
|
|
array(
|
|
|
|
|
'name' => 'localmutlitesting1',
|
|
|
|
|
'class' => 'FSFileBackend',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
|
|
|
|
'containerPaths' => array(
|
2012-01-08 08:40:00 +00:00
|
|
|
'cont1' => "$tmpDir/localtestingmulti1/cont1",
|
|
|
|
|
'cont2' => "$tmpDir/localtestingmulti1/cont2" ),
|
2011-12-20 03:52:06 +00:00
|
|
|
'isMultiMaster' => false
|
|
|
|
|
),
|
|
|
|
|
array(
|
|
|
|
|
'name' => 'localmutlitesting2',
|
|
|
|
|
'class' => 'FSFileBackend',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
|
|
|
|
'containerPaths' => array(
|
2012-01-08 08:40:00 +00:00
|
|
|
'cont1' => "$tmpDir/localtestingmulti2/cont1",
|
|
|
|
|
'cont2' => "$tmpDir/localtestingmulti2/cont2" ),
|
2011-12-20 03:52:06 +00:00
|
|
|
'isMultiMaster' => true
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) );
|
|
|
|
|
$this->filesToPrune = $this->pathsToPrune = array();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
private function baseStorePath() {
|
2011-12-20 03:52:06 +00:00
|
|
|
return 'mwstore://localtesting';
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
private function backendClass() {
|
|
|
|
|
return get_class( $this->backend );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testStore
|
|
|
|
|
*/
|
|
|
|
|
public function testStore( $op, $source, $dest ) {
|
|
|
|
|
$this->filesToPrune[] = $source;
|
|
|
|
|
$this->pathsToPrune[] = $dest;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestStore( $op, $source, $dest );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestStore( $op, $source, $dest );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doTestStore( $op, $source, $dest ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
file_put_contents( $source, "Unit test file" );
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Store from $source to $dest succeeded without warnings ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Store from $source to $dest succeeded ($backendName)." );
|
2012-01-08 22:10:53 +00:00
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Store from $source to $dest has proper 'success' field in Status ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, file_exists( $source ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source file $source still exists ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest exists ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( filesize( $source ),
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest has correct size ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$props1 = FSFile::getPropsFromPath( $source );
|
|
|
|
|
$props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
|
|
|
|
|
$this->assertEquals( $props1, $props2,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source and destination have the same props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provider_testStore() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
|
|
|
|
$tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath();
|
2012-01-08 08:40:00 +00:00
|
|
|
$toPath = $this->baseStorePath() . '/cont1/fun/obj1.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
$op = array( 'op' => 'store', 'src' => $tmpName, 'dst' => $toPath );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$tmpName, // source
|
|
|
|
|
$toPath, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2012-01-19 02:24:49 +00:00
|
|
|
$op['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$tmpName, // source
|
|
|
|
|
$toPath, // dest
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testCopy
|
|
|
|
|
*/
|
|
|
|
|
public function testCopy( $op, $source, $dest ) {
|
|
|
|
|
$this->pathsToPrune[] = $source;
|
|
|
|
|
$this->pathsToPrune[] = $dest;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestCopy( $op, $source, $dest );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestCopy( $op, $source, $dest );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doTestCopy( $op, $source, $dest ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Copy from $source to $dest succeeded without warnings ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Copy from $source to $dest succeeded ($backendName)." );
|
2012-01-08 22:10:53 +00:00
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Copy from $source to $dest has proper 'success' field in Status ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $source ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source file $source still exists ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest exists after copy ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $source ) ),
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest has correct size ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$props1 = $this->backend->getFileProps( array( 'src' => $source ) );
|
|
|
|
|
$props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
|
|
|
|
|
$this->assertEquals( $props1, $props2,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source and destination have the same props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provider_testCopy() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$source = $this->baseStorePath() . '/cont1/file.txt';
|
|
|
|
|
$dest = $this->baseStorePath() . '/cont2/fileMoved.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$op = array( 'op' => 'copy', 'src' => $source, 'dst' => $dest );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2012-01-19 02:24:49 +00:00
|
|
|
$op['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testMove
|
|
|
|
|
*/
|
|
|
|
|
public function testMove( $op, $source, $dest ) {
|
|
|
|
|
$this->pathsToPrune[] = $source;
|
|
|
|
|
$this->pathsToPrune[] = $dest;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestMove( $op, $source, $dest );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestMove( $op, $source, $dest );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doTestMove( $op, $source, $dest ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Move from $source to $dest succeeded without warnings ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Move from $source to $dest succeeded ($backendName)." );
|
2012-01-08 22:10:53 +00:00
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Move from $source to $dest has proper 'success' field in Status ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source file $source does not still exists ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest exists after move ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$this->assertNotEquals(
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $source ) ),
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest has correct size ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$props1 = $this->backend->getFileProps( array( 'src' => $source ) );
|
|
|
|
|
$props2 = $this->backend->getFileProps( array( 'src' => $dest ) );
|
|
|
|
|
$this->assertEquals( false, $props1['fileExists'],
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source file does not exist accourding to props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->assertEquals( true, $props2['fileExists'],
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file exists accourding to props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provider_testMove() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$source = $this->baseStorePath() . '/cont1/file.txt';
|
|
|
|
|
$dest = $this->baseStorePath() . '/cont2/fileMoved.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$op = array( 'op' => 'move', 'src' => $source, 'dst' => $dest );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2012-01-19 02:24:49 +00:00
|
|
|
$op['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testDelete
|
|
|
|
|
*/
|
|
|
|
|
public function testDelete( $op, $source, $withSource, $okStatus ) {
|
|
|
|
|
$this->pathsToPrune[] = $source;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestDelete( $op, $source, $withSource, $okStatus );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestDelete( $op, $source, $withSource, $okStatus );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doTestDelete( $op, $source, $withSource, $okStatus ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
if ( $withSource ) {
|
|
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
if ( $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Deletion of file at $source succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Deletion of file at $source succeeded ($backendName)." );
|
2012-01-08 22:10:53 +00:00
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Deletion of file at $source has proper 'success' field in Status ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
} else {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( false, $status->isOK(),
|
|
|
|
|
"Deletion of file at $source failed ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Source file $source does not exist after move ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $source ) ),
|
|
|
|
|
"Source file $source has correct size (false) ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$props1 = $this->backend->getFileProps( array( 'src' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertFalse( $props1['fileExists'],
|
|
|
|
|
"Source file $source does not exist according to props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provider_testDelete() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$source = $this->baseStorePath() . '/cont1/myfacefile.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$op = array( 'op' => 'delete', 'src' => $source );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
true, // with source
|
|
|
|
|
true // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
false, // without source
|
|
|
|
|
false // fails
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$op['ignoreMissingSource'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
false, // without source
|
|
|
|
|
true // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testCreate
|
|
|
|
|
*/
|
|
|
|
|
public function testCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) {
|
|
|
|
|
$this->pathsToPrune[] = $dest;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doTestCreate( $op, $dest, $alreadyExists, $okStatus, $newSize ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $dest ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$oldText = 'blah...blah...waahwaah';
|
|
|
|
|
if ( $alreadyExists ) {
|
|
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => $oldText, 'dst' => $dest ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of file at $dest succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
if ( $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Creation of file at $dest succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of file at $dest succeeded ($backendName)." );
|
2012-01-08 22:10:53 +00:00
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Creation of file at $dest has proper 'success' field in Status ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
} else {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( false, $status->isOK(),
|
|
|
|
|
"Creation of file at $dest failed ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $dest ) ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest exists after creation ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$props1 = $this->backend->getFileProps( array( 'src' => $dest ) );
|
|
|
|
|
$this->assertEquals( true, $props1['fileExists'],
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest exists according to props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
if ( $okStatus ) { // file content is what we saved
|
|
|
|
|
$this->assertEquals( $newSize, $props1['size'],
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest has expected size according to props ($backendName)." );
|
|
|
|
|
$this->assertEquals( $newSize,
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest has correct size ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
} else { // file content is some other previous text
|
|
|
|
|
$this->assertEquals( strlen( $oldText ), $props1['size'],
|
2012-01-08 08:40:00 +00:00
|
|
|
"Destination file $dest has original size according to props ($backendName)." );
|
|
|
|
|
$this->assertEquals( strlen( $oldText ),
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest has original size according to props ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testCreate
|
|
|
|
|
*/
|
|
|
|
|
public function provider_testCreate() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$source = $this->baseStorePath() . '/cont2/myspacefile.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$dummyText = 'hey hey';
|
|
|
|
|
$op = array( 'op' => 'create', 'content' => $dummyText, 'dst' => $source );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
false, // no dest already exists
|
|
|
|
|
true, // succeeds
|
|
|
|
|
strlen( $dummyText )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
true, // dest already exists
|
|
|
|
|
false, // fails
|
|
|
|
|
strlen( $dummyText )
|
|
|
|
|
);
|
|
|
|
|
|
2012-01-19 02:24:49 +00:00
|
|
|
$op['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
true, // dest already exists
|
|
|
|
|
true, // succeeds
|
|
|
|
|
strlen( $dummyText )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testConcatenate
|
|
|
|
|
*/
|
|
|
|
|
public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
|
|
|
|
|
$this->pathsToPrune = array_merge( $this->pathsToPrune, $srcs );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->filesToPrune[] = $op['dst'];
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
2012-01-08 09:25:15 +00:00
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
|
|
|
|
|
$this->tearDownFiles();
|
2012-01-08 08:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-08 09:25:15 +00:00
|
|
|
public function doTestConcatenate( $params, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$expContent = '';
|
|
|
|
|
// Create sources
|
|
|
|
|
$ops = array();
|
|
|
|
|
foreach ( $srcs as $i => $source ) {
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
$ops[] = array(
|
|
|
|
|
'op' => 'create', // operation
|
|
|
|
|
'dst' => $source, // source
|
|
|
|
|
'content' => $srcsContent[$i]
|
|
|
|
|
);
|
|
|
|
|
$expContent .= $srcsContent[$i];
|
|
|
|
|
}
|
|
|
|
|
$status = $this->backend->doOperations( $ops );
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of source files succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-08 09:25:15 +00:00
|
|
|
$dest = $params['dst'];
|
2011-12-20 03:52:06 +00:00
|
|
|
if ( $alreadyExists ) {
|
2011-12-23 18:59:39 +00:00
|
|
|
$ok = file_put_contents( $dest, 'blah...blah...waahwaah' ) !== false;
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $ok,
|
|
|
|
|
"Creation of file at $dest succeeded ($backendName)." );
|
2011-12-23 18:59:39 +00:00
|
|
|
} else {
|
|
|
|
|
$ok = file_put_contents( $dest, '' ) !== false;
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $ok,
|
|
|
|
|
"Creation of 0-byte file at $dest succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-08 09:25:15 +00:00
|
|
|
// Combine the files into one
|
|
|
|
|
$status = $this->backend->concatenate( $params );
|
2011-12-20 03:52:06 +00:00
|
|
|
if ( $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Creation of concat file at $dest succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of concat file at $dest succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
} else {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( false, $status->isOK(),
|
|
|
|
|
"Creation of concat file at $dest failed ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $okStatus ) {
|
2011-12-23 18:59:39 +00:00
|
|
|
$this->assertEquals( true, is_file( $dest ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Dest concat file $dest exists after creation ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
} else {
|
2011-12-23 18:59:39 +00:00
|
|
|
$this->assertEquals( true, is_file( $dest ),
|
2012-01-08 08:40:00 +00:00
|
|
|
"Dest concat file $dest exists after failed creation ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2011-12-23 18:59:39 +00:00
|
|
|
$contents = file_get_contents( $dest );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertNotEquals( false, $contents, "File at $dest exists ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
if ( $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( $expContent, $contents,
|
|
|
|
|
"Concat file at $dest has correct contents ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
} else {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertNotEquals( $expContent, $contents,
|
|
|
|
|
"Concat file at $dest has correct contents ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function provider_testConcatenate() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2011-12-23 18:59:39 +00:00
|
|
|
$rand = mt_rand( 0, 2000000000 ) . time();
|
|
|
|
|
$dest = wfTempDir() . "/randomfile!$rand.txt";
|
2011-12-20 03:52:06 +00:00
|
|
|
$srcs = array(
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->baseStorePath() . '/cont1/file1.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file2.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file3.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file4.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file5.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file6.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file7.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file8.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file9.txt',
|
|
|
|
|
$this->baseStorePath() . '/cont1/file10.txt'
|
2011-12-20 03:52:06 +00:00
|
|
|
);
|
|
|
|
|
$content = array(
|
|
|
|
|
'egfage',
|
|
|
|
|
'ageageag',
|
|
|
|
|
'rhokohlr',
|
|
|
|
|
'shgmslkg',
|
|
|
|
|
'kenga',
|
|
|
|
|
'owagmal',
|
|
|
|
|
'kgmae',
|
|
|
|
|
'g eak;g',
|
|
|
|
|
'lkaem;a',
|
|
|
|
|
'legma'
|
|
|
|
|
);
|
2012-01-08 09:25:15 +00:00
|
|
|
$params = array( 'srcs' => $srcs, 'dst' => $dest );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$cases[] = array(
|
2012-01-08 09:25:15 +00:00
|
|
|
$params, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
$srcs, // sources
|
|
|
|
|
$content, // content for each source
|
|
|
|
|
false, // no dest already exists
|
|
|
|
|
true, // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cases[] = array(
|
2012-01-08 09:25:15 +00:00
|
|
|
$params, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
$srcs, // sources
|
|
|
|
|
$content, // content for each source
|
2012-01-08 08:40:00 +00:00
|
|
|
true, // dest already exists
|
2011-12-20 03:52:06 +00:00
|
|
|
false, // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-04 02:15:07 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetFileContents
|
|
|
|
|
*/
|
|
|
|
|
public function testGetFileContents( $src, $content ) {
|
|
|
|
|
$this->pathsToPrune[] = $src;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestGetFileContents( $src, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestGetFileContents( $src, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetFileContents
|
|
|
|
|
*/
|
2012-01-13 23:30:46 +00:00
|
|
|
public function doTestGetFileContents( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
|
2012-01-04 02:15:07 +00:00
|
|
|
$status = $this->backend->doOperation(
|
2012-01-13 23:30:46 +00:00
|
|
|
array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2012-01-13 23:30:46 +00:00
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2012-01-04 02:15:07 +00:00
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$newContents = $this->backend->getFileContents( array( 'src' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertNotEquals( false, $newContents,
|
2012-01-13 23:30:46 +00:00
|
|
|
"Read of file at $source succeeded ($backendName)." );
|
2012-01-04 02:15:07 +00:00
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( $content, $newContents,
|
2012-01-13 23:30:46 +00:00
|
|
|
"Contents read match data at $source ($backendName)." );
|
2012-01-04 02:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function provider_testGetFileContents() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$base = $this->baseStorePath();
|
2012-01-04 02:15:07 +00:00
|
|
|
$cases[] = array( "$base/cont1/b/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/cont1/b/some-other_file.txt", "more file contents" );
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetLocalCopy
|
|
|
|
|
*/
|
|
|
|
|
public function testGetLocalCopy( $src, $content ) {
|
|
|
|
|
$this->pathsToPrune[] = $src;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestGetLocalCopy( $src, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestGetLocalCopy( $src, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
public function doTestGetLocalCopy( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation(
|
2012-01-13 23:30:46 +00:00
|
|
|
array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2012-01-13 23:30:46 +00:00
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertNotNull( $tmpFile,
|
2012-01-13 23:30:46 +00:00
|
|
|
"Creation of local copy of $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$contents = file_get_contents( $tmpFile->getPath() );
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function provider_testGetLocalCopy() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$base = $this->baseStorePath();
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" );
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-04 02:15:07 +00:00
|
|
|
* @dataProvider provider_testGetLocalReference
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
|
|
|
|
public function testGetLocalReference( $src, $content ) {
|
|
|
|
|
$this->pathsToPrune[] = $src;
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestGetLocalReference( $src, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestGetLocalReference( $src, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
public function doTestGetLocalReference( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation(
|
2012-01-13 23:30:46 +00:00
|
|
|
array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2012-01-13 23:30:46 +00:00
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-13 23:30:46 +00:00
|
|
|
$tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertNotNull( $tmpFile,
|
2012-01-13 23:30:46 +00:00
|
|
|
"Creation of local copy of $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$contents = file_get_contents( $tmpFile->getPath() );
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-04 02:15:07 +00:00
|
|
|
function provider_testGetLocalReference() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$base = $this->baseStorePath();
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array( "$base/cont1/a/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/cont1/a/some-other_file.txt", "more file contents" );
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-09 00:20:28 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testPrepareAndClean
|
|
|
|
|
*/
|
|
|
|
|
public function testPrepareAndClean( $path, $isOK ) {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestPrepareAndClean( $path, $isOK );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-09 00:20:28 +00:00
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestPrepareAndClean( $path, $isOK );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function provider_testPrepareAndClean() {
|
|
|
|
|
$base = $this->baseStorePath();
|
|
|
|
|
return array(
|
|
|
|
|
array( "$base/cont1/a/z/some_file1.txt", true ),
|
|
|
|
|
array( "$base/cont2/a/z/some_file2.txt", true ),
|
|
|
|
|
array( "$base/cont3/a/z/some_file3.txt", false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doTestPrepareAndClean( $path, $isOK ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->prepare( array( 'dir' => $path ) );
|
|
|
|
|
if ( $isOK ) {
|
|
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Preparing dir $path succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Preparing dir $path succeeded ($backendName)." );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( false, $status->isOK(),
|
|
|
|
|
"Preparing dir $path failed ($backendName)." );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-09 00:20:28 +00:00
|
|
|
$status = $this->backend->clean( array( 'dir' => $path ) );
|
|
|
|
|
if ( $isOK ) {
|
|
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Cleaning dir $path succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Cleaning dir $path succeeded ($backendName)." );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( false, $status->isOK(),
|
|
|
|
|
"Cleaning dir $path failed ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @TODO: testSecure
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-15 22:45:14 +00:00
|
|
|
public function testDoOperations() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestDoOperations();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestDoOperations();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function doTestDoOperations() {
|
|
|
|
|
$base = $this->baseStorePath();
|
|
|
|
|
|
|
|
|
|
$fileA = "$base/cont1/a/b/fileA.txt";
|
|
|
|
|
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
|
|
|
|
|
$fileB = "$base/cont1/a/b/fileB.txt";
|
|
|
|
|
$fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
|
|
|
|
|
$fileC = "$base/cont1/a/b/fileC.txt";
|
|
|
|
|
$fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
|
|
|
|
|
$fileD = "$base/cont1/a/b/fileD.txt";
|
|
|
|
|
|
|
|
|
|
$this->pathsToPrune[] = $fileA;
|
|
|
|
|
$this->pathsToPrune[] = $fileB;
|
|
|
|
|
$this->pathsToPrune[] = $fileC;
|
|
|
|
|
$this->pathsToPrune[] = $fileD;
|
|
|
|
|
|
|
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $fileA ) ) );
|
|
|
|
|
$this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
|
|
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $fileB ) ) );
|
|
|
|
|
$this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
|
|
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $fileC ) ) );
|
|
|
|
|
$this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperations( array(
|
2012-01-19 02:24:49 +00:00
|
|
|
array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
|
2012-01-15 22:45:14 +00:00
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<D> (file:<orginal contents>)
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<D>
|
2012-01-19 02:24:49 +00:00
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
|
2012-01-15 22:45:14 +00:00
|
|
|
// Now: A:<A>, B:<B>, C:<empty>, D:<A>
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
|
|
|
|
|
// Now: A:<A>, B:<empty>, C:<B>, D:<A>
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileD, 'dst' => $fileA, 'overwriteSame' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<empty>, C:<B>, D:<empty>
|
2012-01-19 02:24:49 +00:00
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
|
2012-01-15 22:45:14 +00:00
|
|
|
// Now: A:<B>, B:<empty>, C:<empty>, D:<empty>
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC ),
|
|
|
|
|
// Now: A:<B>, B:<empty>, C:<B>, D:<empty>
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileA, 'dst' => $fileC, 'overwriteSame' => 1 ),
|
|
|
|
|
// Now: A:<empty>, B:<empty>, C:<B>, D:<empty>
|
2012-01-19 02:24:49 +00:00
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
|
2012-01-15 22:45:14 +00:00
|
|
|
// Does nothing
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
|
|
|
|
|
// Does nothing
|
2012-01-19 02:24:49 +00:00
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
|
2012-01-15 22:45:14 +00:00
|
|
|
// Does nothing
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( array(), $status->errors, "Operation batch succeeded" );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
|
|
|
|
|
$this->assertEquals( 12, count( $status->success ),
|
|
|
|
|
"Operation batch has correct success array" );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileA ) ),
|
|
|
|
|
"File does not exist at $fileA" );
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
|
|
|
|
|
"File does not exist at $fileB" );
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
|
|
|
|
|
"File does not exist at $fileD" );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
|
|
|
|
|
"File exists at $fileC" );
|
|
|
|
|
$this->assertEquals( $fileBContents,
|
|
|
|
|
$this->backend->getFileContents( array( 'src' => $fileC ) ),
|
|
|
|
|
"Correct file contents of $fileC" );
|
|
|
|
|
$this->assertEquals( strlen( $fileBContents ),
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $fileC ) ),
|
|
|
|
|
"Correct file size of $fileC" );
|
|
|
|
|
$this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
|
|
|
|
|
$this->backend->getFileSha1Base36( array( 'src' => $fileC ) ),
|
|
|
|
|
"Correct file SHA-1 of $fileC" );
|
|
|
|
|
|
|
|
|
|
// @TODO: test some cases where the ops should fail
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
public function testGetFileList() {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestGetFileList();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestGetFileList();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doTestGetFileList() {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
|
|
|
|
$base = $this->baseStorePath();
|
2011-12-20 03:52:06 +00:00
|
|
|
$files = array(
|
|
|
|
|
"$base/cont1/test1.txt",
|
|
|
|
|
"$base/cont1/test2.txt",
|
|
|
|
|
"$base/cont1/test3.txt",
|
|
|
|
|
"$base/cont1/subdir1/test1.txt",
|
|
|
|
|
"$base/cont1/subdir1/test2.txt",
|
|
|
|
|
"$base/cont1/subdir2/test3.txt",
|
|
|
|
|
"$base/cont1/subdir2/test4.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/test1.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/test2.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/test3.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/test4.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/test5.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/sub/test0.txt",
|
|
|
|
|
"$base/cont1/subdir2/subdir/sub/120-px-file.txt",
|
|
|
|
|
);
|
|
|
|
|
$this->pathsToPrune = array_merge( $this->pathsToPrune, $files );
|
|
|
|
|
|
|
|
|
|
// Add the files
|
|
|
|
|
$ops = array();
|
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
|
2012-01-13 23:30:46 +00:00
|
|
|
$this->backend->prepare( array( 'dir' => dirname( $file ) ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
$status = $this->backend->doOperations( $ops );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of files succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
// Expected listing
|
|
|
|
|
$expected = array(
|
|
|
|
|
"test1.txt",
|
|
|
|
|
"test2.txt",
|
|
|
|
|
"test3.txt",
|
|
|
|
|
"subdir1/test1.txt",
|
|
|
|
|
"subdir1/test2.txt",
|
|
|
|
|
"subdir2/test3.txt",
|
2012-01-06 05:15:51 +00:00
|
|
|
"subdir2/test4.txt",
|
2011-12-20 03:52:06 +00:00
|
|
|
"subdir2/subdir/test1.txt",
|
|
|
|
|
"subdir2/subdir/test2.txt",
|
|
|
|
|
"subdir2/subdir/test3.txt",
|
|
|
|
|
"subdir2/subdir/test4.txt",
|
|
|
|
|
"subdir2/subdir/test5.txt",
|
|
|
|
|
"subdir2/subdir/sub/test0.txt",
|
|
|
|
|
"subdir2/subdir/sub/120-px-file.txt",
|
|
|
|
|
);
|
2012-01-06 05:15:51 +00:00
|
|
|
sort( $expected );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
// Actual listing (no trailing slash)
|
|
|
|
|
$list = array();
|
|
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/cont1" ) );
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
2012-01-06 05:15:51 +00:00
|
|
|
sort( $list );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
// Actual listing (with trailing slash)
|
|
|
|
|
$list = array();
|
|
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/" ) );
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
2012-01-06 05:15:51 +00:00
|
|
|
sort( $list );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
foreach ( $files as $file ) {
|
2011-12-21 08:46:10 +00:00
|
|
|
$this->backend->doOperation( array( 'op' => 'delete', 'src' => "$base/$file" ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/cont1/not/exists" ) );
|
|
|
|
|
foreach ( $iter as $iter ) {} // no errors
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
function tearDownFiles() {
|
2011-12-20 03:52:06 +00:00
|
|
|
foreach ( $this->filesToPrune as $file ) {
|
|
|
|
|
@unlink( $file );
|
|
|
|
|
}
|
|
|
|
|
foreach ( $this->pathsToPrune as $file ) {
|
|
|
|
|
$this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
|
|
|
|
|
}
|
2012-01-08 08:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
|
parent::tearDown();
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
}
|