2011-12-20 03:52:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
2012-01-12 18:44:00 +00:00
|
|
|
/**
|
|
|
|
|
* @group FileRepo
|
2012-01-29 21:28:31 +00:00
|
|
|
* @group FileBackend
|
2012-08-29 15:01:02 +00:00
|
|
|
* @group medium
|
2012-01-12 18:44:00 +00:00
|
|
|
*/
|
2011-12-20 03:52:06 +00:00
|
|
|
class FileBackendTest extends MediaWikiTestCase {
|
|
|
|
|
private $backend, $multiBackend;
|
2012-01-27 22:46:55 +00:00
|
|
|
private $filesToPrune = array();
|
2012-01-23 08:33:31 +00:00
|
|
|
private static $backendToUse;
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-01-22 00:34:04 +00:00
|
|
|
global $wgFileBackends;
|
2011-12-20 03:52:06 +00:00
|
|
|
parent::setUp();
|
2013-04-17 19:11:45 +00:00
|
|
|
$uniqueId = time() . '-' . mt_rand();
|
|
|
|
|
$tmpPrefix = wfTempDir() . '/filebackend-unittest-' . $uniqueId;
|
2012-01-22 00:34:04 +00:00
|
|
|
if ( $this->getCliArg( 'use-filebackend=' ) ) {
|
2012-01-23 08:33:31 +00:00
|
|
|
if ( self::$backendToUse ) {
|
|
|
|
|
$this->singleBackend = self::$backendToUse;
|
|
|
|
|
} else {
|
|
|
|
|
$name = $this->getCliArg( 'use-filebackend=' );
|
|
|
|
|
$useConfig = array();
|
|
|
|
|
foreach ( $wgFileBackends as $conf ) {
|
|
|
|
|
if ( $conf['name'] == $name ) {
|
|
|
|
|
$useConfig = $conf;
|
2012-04-17 17:25:52 +00:00
|
|
|
break;
|
2012-01-23 08:33:31 +00:00
|
|
|
}
|
2012-01-22 00:34:04 +00:00
|
|
|
}
|
2012-01-23 08:33:31 +00:00
|
|
|
$useConfig['name'] = 'localtesting'; // swap name
|
2012-06-13 00:23:53 +00:00
|
|
|
$useConfig['shardViaHashLevels'] = array( // test sharding
|
|
|
|
|
'unittest-cont1' => array( 'levels' => 1, 'base' => 16, 'repeat' => 1 )
|
|
|
|
|
);
|
2012-04-17 17:25:52 +00:00
|
|
|
$class = $useConfig['class'];
|
2012-01-27 22:46:55 +00:00
|
|
|
self::$backendToUse = new $class( $useConfig );
|
2012-01-23 08:33:31 +00:00
|
|
|
$this->singleBackend = self::$backendToUse;
|
2012-01-22 00:34:04 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->singleBackend = new FSFileBackend( array(
|
2013-03-25 23:27:14 +00:00
|
|
|
'name' => 'localtesting',
|
2012-01-22 00:34:04 +00:00
|
|
|
'lockManager' => 'fsLockManager',
|
2012-04-11 17:51:02 +00:00
|
|
|
#'parallelize' => 'implicit',
|
2013-04-17 19:11:45 +00:00
|
|
|
'wikiId' => wfWikiID() . $uniqueId,
|
2012-01-22 00:34:04 +00:00
|
|
|
'containerPaths' => array(
|
2012-01-27 22:46:55 +00:00
|
|
|
'unittest-cont1' => "{$tmpPrefix}-localtesting-cont1",
|
|
|
|
|
'unittest-cont2' => "{$tmpPrefix}-localtesting-cont2" )
|
2012-01-22 00:34:04 +00:00
|
|
|
) );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
$this->multiBackend = new FileBackendMultiWrite( array(
|
2013-03-25 23:27:14 +00:00
|
|
|
'name' => 'localtesting',
|
2011-12-20 03:52:06 +00:00
|
|
|
'lockManager' => 'fsLockManager',
|
2012-04-11 17:51:02 +00:00
|
|
|
'parallelize' => 'implicit',
|
2013-04-17 19:11:45 +00:00
|
|
|
'wikiId' => wfWikiId() . $uniqueId,
|
2013-03-25 23:27:14 +00:00
|
|
|
'backends' => array(
|
2011-12-20 03:52:06 +00:00
|
|
|
array(
|
2013-03-25 23:27:14 +00:00
|
|
|
'name' => 'localmultitesting1',
|
|
|
|
|
'class' => 'FSFileBackend',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
2011-12-20 03:52:06 +00:00
|
|
|
'containerPaths' => array(
|
2012-01-27 22:46:55 +00:00
|
|
|
'unittest-cont1' => "{$tmpPrefix}-localtestingmulti1-cont1",
|
|
|
|
|
'unittest-cont2' => "{$tmpPrefix}-localtestingmulti1-cont2" ),
|
2011-12-20 03:52:06 +00:00
|
|
|
'isMultiMaster' => false
|
|
|
|
|
),
|
|
|
|
|
array(
|
2013-03-25 23:27:14 +00:00
|
|
|
'name' => 'localmultitesting2',
|
|
|
|
|
'class' => 'FSFileBackend',
|
|
|
|
|
'lockManager' => 'nullLockManager',
|
2011-12-20 03:52:06 +00:00
|
|
|
'containerPaths' => array(
|
2012-01-27 22:46:55 +00:00
|
|
|
'unittest-cont1' => "{$tmpPrefix}-localtestingmulti2-cont1",
|
|
|
|
|
'unittest-cont2' => "{$tmpPrefix}-localtestingmulti2-cont2" ),
|
2011-12-20 03:52:06 +00:00
|
|
|
'isMultiMaster' => true
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) );
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->filesToPrune = array();
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
private static 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 );
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-29 21:28:31 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testIsStoragePath
|
|
|
|
|
*/
|
|
|
|
|
public function testIsStoragePath( $path, $isStorePath ) {
|
|
|
|
|
$this->assertEquals( $isStorePath, FileBackend::isStoragePath( $path ),
|
|
|
|
|
"FileBackend::isStoragePath on path '$path'" );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testIsStoragePath() {
|
2012-01-29 21:28:31 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'mwstore://', true ),
|
|
|
|
|
array( 'mwstore://backend', true ),
|
|
|
|
|
array( 'mwstore://backend/container', true ),
|
|
|
|
|
array( 'mwstore://backend/container/', true ),
|
|
|
|
|
array( 'mwstore://backend/container/path', true ),
|
|
|
|
|
array( 'mwstore://backend//container/', true ),
|
|
|
|
|
array( 'mwstore://backend//container//', true ),
|
|
|
|
|
array( 'mwstore://backend//container//path', true ),
|
|
|
|
|
array( 'mwstore:///', true ),
|
|
|
|
|
array( 'mwstore:/', false ),
|
|
|
|
|
array( 'mwstore:', false ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testSplitStoragePath
|
|
|
|
|
*/
|
|
|
|
|
public function testSplitStoragePath( $path, $res ) {
|
|
|
|
|
$this->assertEquals( $res, FileBackend::splitStoragePath( $path ),
|
|
|
|
|
"FileBackend::splitStoragePath on path '$path'" );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testSplitStoragePath() {
|
2012-01-29 21:28:31 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'mwstore://backend/container', array( 'backend', 'container', '' ) ),
|
|
|
|
|
array( 'mwstore://backend/container/', array( 'backend', 'container', '' ) ),
|
|
|
|
|
array( 'mwstore://backend/container/path', array( 'backend', 'container', 'path' ) ),
|
|
|
|
|
array( 'mwstore://backend/container//path', array( 'backend', 'container', '/path' ) ),
|
|
|
|
|
array( 'mwstore://backend//container/path', array( null, null, null ) ),
|
|
|
|
|
array( 'mwstore://backend//container//path', array( null, null, null ) ),
|
|
|
|
|
array( 'mwstore://', array( null, null, null ) ),
|
|
|
|
|
array( 'mwstore://backend', array( null, null, null ) ),
|
|
|
|
|
array( 'mwstore:///', array( null, null, null ) ),
|
|
|
|
|
array( 'mwstore:/', array( null, null, null ) ),
|
|
|
|
|
array( 'mwstore:', array( null, null, null ) )
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_normalizeStoragePath
|
|
|
|
|
*/
|
|
|
|
|
public function testNormalizeStoragePath( $path, $res ) {
|
|
|
|
|
$this->assertEquals( $res, FileBackend::normalizeStoragePath( $path ),
|
|
|
|
|
"FileBackend::normalizeStoragePath on path '$path'" );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_normalizeStoragePath() {
|
2012-01-29 21:28:31 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'mwstore://backend/container', 'mwstore://backend/container' ),
|
|
|
|
|
array( 'mwstore://backend/container/', 'mwstore://backend/container' ),
|
|
|
|
|
array( 'mwstore://backend/container/path', 'mwstore://backend/container/path' ),
|
|
|
|
|
array( 'mwstore://backend/container//path', 'mwstore://backend/container/path' ),
|
|
|
|
|
array( 'mwstore://backend/container///path', 'mwstore://backend/container/path' ),
|
2013-02-14 13:08:51 +00:00
|
|
|
array( 'mwstore://backend/container///path//to///obj', 'mwstore://backend/container/path/to/obj' ),
|
2012-01-29 21:28:31 +00:00
|
|
|
array( 'mwstore://', null ),
|
|
|
|
|
array( 'mwstore://backend', null ),
|
|
|
|
|
array( 'mwstore://backend//container/path', null ),
|
|
|
|
|
array( 'mwstore://backend//container//path', null ),
|
|
|
|
|
array( 'mwstore:///', null ),
|
|
|
|
|
array( 'mwstore:/', null ),
|
2013-02-14 13:08:51 +00:00
|
|
|
array( 'mwstore:', null ),
|
2012-01-29 21:28:31 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testParentStoragePath
|
|
|
|
|
*/
|
|
|
|
|
public function testParentStoragePath( $path, $res ) {
|
|
|
|
|
$this->assertEquals( $res, FileBackend::parentStoragePath( $path ),
|
|
|
|
|
"FileBackend::parentStoragePath on path '$path'" );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testParentStoragePath() {
|
2012-01-29 21:28:31 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'mwstore://backend/container/path/to/obj', 'mwstore://backend/container/path/to' ),
|
|
|
|
|
array( 'mwstore://backend/container/path/to', 'mwstore://backend/container/path' ),
|
|
|
|
|
array( 'mwstore://backend/container/path', 'mwstore://backend/container' ),
|
|
|
|
|
array( 'mwstore://backend/container', null ),
|
|
|
|
|
array( 'mwstore://backend/container/path/to/obj/', 'mwstore://backend/container/path/to' ),
|
|
|
|
|
array( 'mwstore://backend/container/path/to/', 'mwstore://backend/container/path' ),
|
|
|
|
|
array( 'mwstore://backend/container/path/', 'mwstore://backend/container' ),
|
|
|
|
|
array( 'mwstore://backend/container/', null ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testExtensionFromPath
|
|
|
|
|
*/
|
|
|
|
|
public function testExtensionFromPath( $path, $res ) {
|
|
|
|
|
$this->assertEquals( $res, FileBackend::extensionFromPath( $path ),
|
|
|
|
|
"FileBackend::extensionFromPath on path '$path'" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provider_testExtensionFromPath() {
|
2012-01-29 21:28:31 +00:00
|
|
|
return array(
|
|
|
|
|
array( 'mwstore://backend/container/path.txt', 'txt' ),
|
|
|
|
|
array( 'mwstore://backend/container/path.svg.png', 'png' ),
|
|
|
|
|
array( 'mwstore://backend/container/path', '' ),
|
|
|
|
|
array( 'mwstore://backend/container/path.', '' ),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testStore
|
|
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testStore( $op ) {
|
|
|
|
|
$this->filesToPrune[] = $op['src'];
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestStore( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestStore( $op );
|
2012-02-24 20:30:55 +00:00
|
|
|
$this->filesToPrune[] = $op['src']; # avoid file leaking
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private function doTestStore( $op ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
$source = $op['src'];
|
|
|
|
|
$dest = $op['dst'];
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $dest ) ) );
|
2012-01-13 23:30:46 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
file_put_contents( $source, "Unit test file" );
|
2012-01-23 08:33:31 +00:00
|
|
|
|
|
|
|
|
if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
|
|
|
|
|
$this->backend->store( $op );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Store from $source to $dest succeeded without warnings ($backendName)." );
|
2012-04-11 17:51:02 +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)." );
|
2012-05-17 23:34:52 +00:00
|
|
|
|
|
|
|
|
$this->assertBackendPathsConsistent( array( $dest ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provider_testStore() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
|
|
|
|
$tmpName = TempFSFile::factory( "unittests_", 'txt' )->getPath();
|
2012-10-08 10:56:20 +00:00
|
|
|
$toPath = self::baseStorePath() . '/unittest-cont1/e/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-23 08:33:31 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
$tmpName, // source
|
|
|
|
|
$toPath, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['overwriteSame'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
|
|
|
|
$tmpName, // source
|
|
|
|
|
$toPath, // dest
|
|
|
|
|
);
|
2012-01-22 00:34:04 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testCopy
|
|
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testCopy( $op ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestCopy( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestCopy( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private function doTestCopy( $op ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
$source = $op['src'];
|
|
|
|
|
$dest = $op['dst'];
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $dest ) ) );
|
2012-01-13 23:30:46 +00:00
|
|
|
|
2012-10-29 19:57:04 +00:00
|
|
|
if ( isset( $op['ignoreMissingSource'] ) ) {
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Move from $source to $dest succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Move from $source to $dest has proper 'success' field in Status ($backendName)." );
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
|
|
|
|
|
"Source file $source does not exist ($backendName)." );
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest does not exist ($backendName)." );
|
|
|
|
|
return; // done
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-23 08:33:31 +00:00
|
|
|
if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
|
|
|
|
|
$this->backend->copy( $op );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation( $op );
|
2012-01-23 08:33:31 +00:00
|
|
|
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"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)." );
|
2012-05-17 23:34:52 +00:00
|
|
|
|
|
|
|
|
$this->assertBackendPathsConsistent( array( $source, $dest ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provider_testCopy() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$source = self::baseStorePath() . '/unittest-cont1/e/file.txt';
|
|
|
|
|
$dest = self::baseStorePath() . '/unittest-cont2/a/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-23 08:33:31 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['overwriteSame'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2012-10-29 19:57:04 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['ignoreMissingSource'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2013-03-12 20:39:40 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['ignoreMissingSource'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
|
|
|
|
self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testMove
|
|
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testMove( $op ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestMove( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestMove( $op );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
private function doTestMove( $op ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
$source = $op['src'];
|
|
|
|
|
$dest = $op['dst'];
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $dest ) ) );
|
2012-01-13 23:30:46 +00:00
|
|
|
|
2012-10-29 19:57:04 +00:00
|
|
|
if ( isset( $op['ignoreMissingSource'] ) ) {
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Move from $source to $dest succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Move from $source to $dest has proper 'success' field in Status ($backendName)." );
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $source ) ),
|
|
|
|
|
"Source file $source does not exist ($backendName)." );
|
|
|
|
|
$this->assertEquals( false, $this->backend->fileExists( array( 'src' => $dest ) ),
|
|
|
|
|
"Destination file $dest does not exist ($backendName)." );
|
|
|
|
|
return; // done
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-23 08:33:31 +00:00
|
|
|
if ( isset( $op['overwrite'] ) || isset( $op['overwriteSame'] ) ) {
|
|
|
|
|
$this->backend->copy( $op );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$status = $this->backend->doOperation( $op );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"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)." );
|
2012-05-17 23:34:52 +00:00
|
|
|
|
|
|
|
|
$this->assertBackendPathsConsistent( array( $source, $dest ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provider_testMove() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$source = self::baseStorePath() . '/unittest-cont1/e/file.txt';
|
|
|
|
|
$dest = self::baseStorePath() . '/unittest-cont2/a/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-23 08:33:31 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['overwriteSame'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2012-10-29 19:57:04 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['ignoreMissingSource'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
|
|
|
|
$source, // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2013-03-12 20:39:40 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['ignoreMissingSource'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
|
|
|
|
self::baseStorePath() . '/unittest-cont-bad/e/file.txt', // source
|
|
|
|
|
$dest, // dest
|
|
|
|
|
);
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testDelete
|
|
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testDelete( $op, $withSource, $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestDelete( $op, $withSource, $okStatus );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestDelete( $op, $withSource, $okStatus );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
private function doTestDelete( $op, $withSource, $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
$source = $op['src'];
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $source ) ) );
|
2012-01-13 23:30:46 +00:00
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
if ( $withSource ) {
|
|
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
if ( $okStatus ) {
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"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)." );
|
2012-05-17 23:34:52 +00:00
|
|
|
|
|
|
|
|
$this->assertBackendPathsConsistent( array( $source ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provider_testDelete() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
$op = array( 'op' => 'delete', 'src' => $source );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
true, // with source
|
|
|
|
|
true // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
false, // without source
|
|
|
|
|
false // fails
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$op['ignoreMissingSource'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
false, // without source
|
|
|
|
|
true // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
2013-03-12 20:39:40 +00:00
|
|
|
$op['ignoreMissingSource'] = true;
|
|
|
|
|
$op['src'] = self::baseStorePath() . '/unittest-cont-bad/e/file.txt';
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
false, // without source
|
|
|
|
|
true // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-24 08:18:29 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testDescribe
|
|
|
|
|
*/
|
|
|
|
|
public function testDescribe( $op, $withSource, $okStatus ) {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestDescribe( $op, $withSource, $okStatus );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestDescribe( $op, $withSource, $okStatus );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doTestDescribe( $op, $withSource, $okStatus ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
|
|
|
|
$source = $op['src'];
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
|
|
|
|
|
if ( $withSource ) {
|
|
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => 'blahblah', 'dst' => $source ) );
|
|
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
if ( $okStatus ) {
|
|
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Describe of file at $source succeeded without warnings ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Describe of file at $source succeeded ($backendName)." );
|
|
|
|
|
$this->assertEquals( array( 0 => true ), $status->success,
|
|
|
|
|
"Describe of file at $source has proper 'success' field in Status ($backendName)." );
|
|
|
|
|
} else {
|
|
|
|
|
$this->assertEquals( false, $status->isOK(),
|
|
|
|
|
"Describe of file at $source failed ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertBackendPathsConsistent( array( $source ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function provider_testDescribe() {
|
|
|
|
|
$cases = array();
|
|
|
|
|
|
|
|
|
|
$source = self::baseStorePath() . '/unittest-cont1/e/myfacefile.txt';
|
|
|
|
|
|
|
|
|
|
$op = array( 'op' => 'describe', 'src' => $source,
|
2012-11-21 04:58:47 +00:00
|
|
|
'headers' => array( 'X-Content-Length' => '91.3', 'Content-Old-Header' => '' ),
|
2012-10-24 08:18:29 +00:00
|
|
|
'disposition' => 'inline' );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
true, // with source
|
|
|
|
|
true // succeeds
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
false, // without source
|
|
|
|
|
false // fails
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testCreate
|
|
|
|
|
*/
|
2012-01-25 01:57:28 +00:00
|
|
|
public function testCreate( $op, $alreadyExists, $okStatus, $newSize ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-25 01:57:28 +00:00
|
|
|
$this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-25 01:57:28 +00:00
|
|
|
$this->doTestCreate( $op, $alreadyExists, $okStatus, $newSize );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-25 01:57:28 +00:00
|
|
|
private function doTestCreate( $op, $alreadyExists, $okStatus, $newSize ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-25 01:57:28 +00:00
|
|
|
$dest = $op['dst'];
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $dest ) ) );
|
2012-01-13 23:30:46 +00:00
|
|
|
|
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-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Creation of file at $dest succeeded ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperation( $op );
|
|
|
|
|
if ( $okStatus ) {
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"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
|
|
|
}
|
2012-05-17 23:34:52 +00:00
|
|
|
|
|
|
|
|
$this->assertBackendPathsConsistent( array( $dest ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testCreate
|
|
|
|
|
*/
|
2012-10-08 10:56:20 +00:00
|
|
|
public static function provider_testCreate() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$dest = self::baseStorePath() . '/unittest-cont2/a/myspacefile.txt';
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-25 01:57:28 +00:00
|
|
|
$op = array( 'op' => 'create', 'content' => 'test test testing', 'dst' => $dest );
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
|
|
|
|
$op, // operation
|
|
|
|
|
false, // no dest already exists
|
|
|
|
|
true, // succeeds
|
2012-01-25 01:57:28 +00:00
|
|
|
strlen( $op['content'] )
|
2011-12-20 03:52:06 +00:00
|
|
|
);
|
|
|
|
|
|
2012-01-25 01:57:28 +00:00
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['content'] = "\n";
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
2012-01-25 01:57:28 +00:00
|
|
|
$op2, // operation
|
|
|
|
|
false, // no dest already exists
|
|
|
|
|
true, // succeeds
|
|
|
|
|
strlen( $op2['content'] )
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$op2 = $op;
|
|
|
|
|
$op2['content'] = "fsf\n waf 3kt";
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
true, // dest already exists
|
|
|
|
|
false, // fails
|
2012-01-25 01:57:28 +00:00
|
|
|
strlen( $op2['content'] )
|
2011-12-20 03:52:06 +00:00
|
|
|
);
|
|
|
|
|
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2 = $op;
|
2012-01-25 01:57:28 +00:00
|
|
|
$op2['content'] = "egm'g gkpe gpqg eqwgwqg";
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2['overwrite'] = true;
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases[] = array(
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2, // operation
|
2011-12-20 03:52:06 +00:00
|
|
|
true, // dest already exists
|
|
|
|
|
true, // succeeds
|
2012-01-25 01:57:28 +00:00
|
|
|
strlen( $op2['content'] )
|
2011-12-20 03:52:06 +00:00
|
|
|
);
|
|
|
|
|
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2 = $op;
|
2012-01-25 01:57:28 +00:00
|
|
|
$op2['content'] = "39qjmg3-qg";
|
2012-01-23 08:33:31 +00:00
|
|
|
$op2['overwriteSame'] = true;
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
$op2, // operation
|
|
|
|
|
true, // dest already exists
|
|
|
|
|
false, // succeeds
|
2012-01-25 01:57:28 +00:00
|
|
|
strlen( $op2['content'] )
|
2012-01-23 08:33:31 +00:00
|
|
|
);
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 00:42:20 +00:00
|
|
|
public function testDoQuickOperations() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestDoQuickOperations();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestDoQuickOperations();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doTestDoQuickOperations() {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-05-16 00:42:20 +00:00
|
|
|
$files = array(
|
2012-06-13 00:23:53 +00:00
|
|
|
"$base/unittest-cont1/e/fileA.a",
|
|
|
|
|
"$base/unittest-cont1/e/fileB.a",
|
|
|
|
|
"$base/unittest-cont1/e/fileC.a"
|
2012-05-16 00:42:20 +00:00
|
|
|
);
|
2013-03-20 23:25:05 +00:00
|
|
|
$createOps = array();
|
2012-05-16 00:42:20 +00:00
|
|
|
$purgeOps = array();
|
|
|
|
|
foreach ( $files as $path ) {
|
|
|
|
|
$status = $this->prepare( array( 'dir' => dirname( $path ) ) );
|
|
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Preparing $path succeeded without warnings ($backendName)." );
|
2013-03-25 23:27:14 +00:00
|
|
|
$createOps[] = array( 'op' => 'create', 'dst' => $path, 'content' => mt_rand( 0, 50000 ) );
|
2013-03-20 23:25:05 +00:00
|
|
|
$copyOps[] = array( 'op' => 'copy', 'src' => $path, 'dst' => "$path-2" );
|
|
|
|
|
$moveOps[] = array( 'op' => 'move', 'src' => "$path-2", 'dst' => "$path-3" );
|
2012-05-16 00:42:20 +00:00
|
|
|
$purgeOps[] = array( 'op' => 'delete', 'src' => $path );
|
2013-03-20 23:25:05 +00:00
|
|
|
$purgeOps[] = array( 'op' => 'delete', 'src' => "$path-3" );
|
2012-05-16 00:42:20 +00:00
|
|
|
}
|
|
|
|
|
$purgeOps[] = array( 'op' => 'null' );
|
|
|
|
|
|
2013-03-20 23:25:05 +00:00
|
|
|
$this->assertGoodStatus(
|
|
|
|
|
$this->backend->doQuickOperations( $createOps ),
|
|
|
|
|
"Creation of source files succeeded ($backendName)." );
|
2012-05-16 00:42:20 +00:00
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$this->assertTrue( $this->backend->fileExists( array( 'src' => $file ) ),
|
|
|
|
|
"File $file exists." );
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-20 23:25:05 +00:00
|
|
|
$this->assertGoodStatus(
|
|
|
|
|
$this->backend->doQuickOperations( $copyOps ),
|
|
|
|
|
"Quick copy of source files succeeded ($backendName)." );
|
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-2" ) ),
|
|
|
|
|
"File $file-2 exists." );
|
|
|
|
|
}
|
2012-05-16 00:42:20 +00:00
|
|
|
|
2013-03-20 23:25:05 +00:00
|
|
|
$this->assertGoodStatus(
|
|
|
|
|
$this->backend->doQuickOperations( $moveOps ),
|
|
|
|
|
"Quick move of source files succeeded ($backendName)." );
|
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$this->assertTrue( $this->backend->fileExists( array( 'src' => "$file-3" ) ),
|
|
|
|
|
"File $file-3 move in." );
|
|
|
|
|
$this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-2" ) ),
|
|
|
|
|
"File $file-2 moved away." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assertGoodStatus(
|
|
|
|
|
$this->backend->quickCopy( array( 'src' => $files[0], 'dst' => $files[0] ) ),
|
|
|
|
|
"Copy of file {$files[0]} over itself succeeded ($backendName)." );
|
|
|
|
|
$this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ),
|
|
|
|
|
"File {$files[0]} still exists." );
|
|
|
|
|
|
|
|
|
|
$this->assertGoodStatus(
|
|
|
|
|
$this->backend->quickMove( array( 'src' => $files[0], 'dst' => $files[0] ) ),
|
|
|
|
|
"Move of file {$files[0]} over itself succeeded ($backendName)." );
|
|
|
|
|
$this->assertTrue( $this->backend->fileExists( array( 'src' => $files[0] ) ),
|
|
|
|
|
"File {$files[0]} still exists." );
|
|
|
|
|
|
|
|
|
|
$this->assertGoodStatus(
|
|
|
|
|
$this->backend->doQuickOperations( $purgeOps ),
|
|
|
|
|
"Quick deletion of source files succeeded ($backendName)." );
|
2012-05-16 00:42:20 +00:00
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$this->assertFalse( $this->backend->fileExists( array( 'src' => $file ) ),
|
|
|
|
|
"File $file purged." );
|
2013-03-20 23:25:05 +00:00
|
|
|
$this->assertFalse( $this->backend->fileExists( array( 'src' => "$file-3" ) ),
|
|
|
|
|
"File $file-3 purged." );
|
2012-05-16 00:42:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testConcatenate
|
|
|
|
|
*/
|
|
|
|
|
public function testConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->filesToPrune[] = $op['dst'];
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
|
2013-04-17 18:20:50 +00:00
|
|
|
$this->filesToPrune[] = $op['dst']; # avoid file leaking
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
2012-01-08 09:25:15 +00:00
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-08 09:25:15 +00:00
|
|
|
$this->doTestConcatenate( $op, $srcs, $srcsContent, $alreadyExists, $okStatus );
|
2012-02-24 20:30:55 +00:00
|
|
|
$this->filesToPrune[] = $op['dst']; # avoid file leaking
|
2012-01-08 09:25:15 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-08 08:40:00 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private 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-27 22:46:55 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $source ) ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
$ops[] = array(
|
2013-03-25 23:27:14 +00:00
|
|
|
'op' => 'create', // operation
|
|
|
|
|
'dst' => $source, // source
|
2011-12-20 03:52:06 +00:00
|
|
|
'content' => $srcsContent[$i]
|
|
|
|
|
);
|
|
|
|
|
$expContent .= $srcsContent[$i];
|
|
|
|
|
}
|
|
|
|
|
$status = $this->backend->doOperations( $ops );
|
|
|
|
|
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"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-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testConcatenate() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$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-10-08 10:56:20 +00:00
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file1.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file2.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file3.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file4.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file5.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file6.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file7.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file8.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/file9.txt',
|
|
|
|
|
self::baseStorePath() . '/unittest-cont1/e/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-02-06 05:26:36 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetFileStat
|
|
|
|
|
*/
|
|
|
|
|
public function testGetFileStat( $path, $content, $alreadyExists ) {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetFileStat( $path, $content, $alreadyExists );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetFileStat( $path, $content, $alreadyExists );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doTestGetFileStat( $path, $content, $alreadyExists ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
|
|
|
|
if ( $alreadyExists ) {
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $path ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$status = $this->create( array( 'dst' => $path, 'content' => $content ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-02-06 05:26:36 +00:00
|
|
|
"Creation of file at $path succeeded ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$size = $this->backend->getFileSize( array( 'src' => $path ) );
|
|
|
|
|
$time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
|
|
|
|
|
$stat = $this->backend->getFileStat( array( 'src' => $path ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( strlen( $content ), $size,
|
|
|
|
|
"Correct file size of '$path'" );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10,
|
2012-02-06 05:26:36 +00:00
|
|
|
"Correct file timestamp of '$path'" );
|
|
|
|
|
|
|
|
|
|
$size = $stat['size'];
|
|
|
|
|
$time = $stat['mtime'];
|
|
|
|
|
$this->assertEquals( strlen( $content ), $size,
|
|
|
|
|
"Correct file size of '$path'" );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->assertTrue( abs( time() - wfTimestamp( TS_UNIX, $time ) ) < 10,
|
2012-02-06 05:26:36 +00:00
|
|
|
"Correct file timestamp of '$path'" );
|
2012-08-24 06:17:16 +00:00
|
|
|
|
|
|
|
|
$this->backend->clearCache( array( $path ) );
|
|
|
|
|
|
|
|
|
|
$size = $this->backend->getFileSize( array( 'src' => $path ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( strlen( $content ), $size,
|
|
|
|
|
"Correct file size of '$path'" );
|
|
|
|
|
|
|
|
|
|
$this->backend->preloadCache( array( $path ) );
|
|
|
|
|
|
|
|
|
|
$size = $this->backend->getFileSize( array( 'src' => $path ) );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( strlen( $content ), $size,
|
|
|
|
|
"Correct file size of '$path'" );
|
2012-02-06 05:26:36 +00:00
|
|
|
} else {
|
|
|
|
|
$size = $this->backend->getFileSize( array( 'src' => $path ) );
|
|
|
|
|
$time = $this->backend->getFileTimestamp( array( 'src' => $path ) );
|
|
|
|
|
$stat = $this->backend->getFileStat( array( 'src' => $path ) );
|
2012-04-17 17:25:52 +00:00
|
|
|
|
2012-02-06 05:26:36 +00:00
|
|
|
$this->assertFalse( $size, "Correct file size of '$path'" );
|
|
|
|
|
$this->assertFalse( $time, "Correct file timestamp of '$path'" );
|
|
|
|
|
$this->assertFalse( $stat, "Correct file stat of '$path'" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testGetFileStat() {
|
2012-02-06 05:26:36 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-06-13 00:23:53 +00:00
|
|
|
$cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents", true );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "", true );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/b/some-diff_file.txt", null, false );
|
2012-02-06 05:26:36 +00:00
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-04 02:15:07 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetFileContents
|
|
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testGetFileContents( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestGetFileContents( $source, $content );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestGetFileContents( $source, $content );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private function doTestGetFileContents( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-09-22 18:01:58 +00:00
|
|
|
$srcs = (array)$source;
|
2012-09-22 18:46:48 +00:00
|
|
|
$content = (array)$content;
|
|
|
|
|
foreach ( $srcs as $i => $src ) {
|
2012-09-22 18:01:58 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $src ) ) );
|
|
|
|
|
$status = $this->backend->doOperation(
|
2012-09-22 18:46:48 +00:00
|
|
|
array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
|
2012-09-22 18:01:58 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Creation of file at $src succeeded ($backendName)." );
|
|
|
|
|
}
|
2012-01-04 02:15:07 +00:00
|
|
|
|
2012-09-22 18:01:58 +00:00
|
|
|
if ( is_array( $source ) ) {
|
|
|
|
|
$contents = $this->backend->getFileContentsMulti( array( 'srcs' => $source ) );
|
|
|
|
|
foreach ( $contents as $path => $data ) {
|
|
|
|
|
$this->assertNotEquals( false, $data, "Contents of $path exists ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( current( $content ), $data, "Contents of $path is correct ($backendName)." );
|
|
|
|
|
next( $content );
|
2012-09-22 18:01:58 +00:00
|
|
|
}
|
|
|
|
|
$this->assertEquals( $source, array_keys( $contents ), "Contents in right order ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( count( $source ), count( $contents ), "Contents array size correct ($backendName)." );
|
2012-09-22 18:01:58 +00:00
|
|
|
} else {
|
|
|
|
|
$data = $this->backend->getFileContents( array( 'src' => $source ) );
|
|
|
|
|
$this->assertNotEquals( false, $data, "Contents of $source exists ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( $content[0], $data, "Contents of $source is correct ($backendName)." );
|
2012-09-22 18:01:58 +00:00
|
|
|
}
|
2012-01-04 02:15:07 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testGetFileContents() {
|
2012-01-04 02:15:07 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-06-13 00:23:53 +00:00
|
|
|
$cases[] = array( "$base/unittest-cont1/e/b/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/b/some-other_file.txt", "more file contents" );
|
2012-09-22 18:01:58 +00:00
|
|
|
$cases[] = array(
|
|
|
|
|
array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
|
2013-02-19 21:00:09 +00:00
|
|
|
"$base/unittest-cont1/e/a/z.txt" ),
|
2012-09-22 18:46:48 +00:00
|
|
|
array( "contents xx", "contents xy", "contents xz" )
|
|
|
|
|
);
|
2012-01-04 02:15:07 +00:00
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetLocalCopy
|
|
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testGetLocalCopy( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestGetLocalCopy( $source, $content );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestGetLocalCopy( $source, $content );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private function doTestGetLocalCopy( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-09-18 18:21:30 +00:00
|
|
|
$srcs = (array)$source;
|
2012-09-22 18:46:48 +00:00
|
|
|
$content = (array)$content;
|
|
|
|
|
foreach ( $srcs as $i => $src ) {
|
2012-09-18 18:21:30 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $src ) ) );
|
|
|
|
|
$status = $this->backend->doOperation(
|
2012-09-22 18:46:48 +00:00
|
|
|
array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
|
2012-09-18 18:21:30 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Creation of file at $src succeeded ($backendName)." );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-09-18 18:21:30 +00:00
|
|
|
if ( is_array( $source ) ) {
|
|
|
|
|
$tmpFiles = $this->backend->getLocalCopyMulti( array( 'srcs' => $source ) );
|
|
|
|
|
foreach ( $tmpFiles as $path => $tmpFile ) {
|
|
|
|
|
$this->assertNotNull( $tmpFile,
|
|
|
|
|
"Creation of local copy of $path succeeded ($backendName)." );
|
|
|
|
|
$contents = file_get_contents( $tmpFile->getPath() );
|
|
|
|
|
$this->assertNotEquals( false, $contents, "Local copy of $path exists ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( current( $content ), $contents, "Local copy of $path is correct ($backendName)." );
|
|
|
|
|
next( $content );
|
2012-09-18 18:21:30 +00:00
|
|
|
}
|
|
|
|
|
$this->assertEquals( $source, array_keys( $tmpFiles ), "Local copies in right order ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( count( $source ), count( $tmpFiles ), "Local copies array size correct ($backendName)." );
|
2012-09-18 18:21:30 +00:00
|
|
|
} else {
|
|
|
|
|
$tmpFile = $this->backend->getLocalCopy( array( 'src' => $source ) );
|
|
|
|
|
$this->assertNotNull( $tmpFile,
|
|
|
|
|
"Creation of local copy of $source succeeded ($backendName)." );
|
|
|
|
|
$contents = file_get_contents( $tmpFile->getPath() );
|
|
|
|
|
$this->assertNotEquals( false, $contents, "Local copy of $source exists ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( $content[0], $contents, "Local copy of $source is correct ($backendName)." );
|
2012-09-18 18:21:30 +00:00
|
|
|
}
|
2012-10-05 19:56:32 +00:00
|
|
|
|
|
|
|
|
$obj = new stdClass();
|
|
|
|
|
$tmpFile->bind( $obj );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testGetLocalCopy() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-06-13 00:23:53 +00:00
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
|
2012-09-18 18:21:30 +00:00
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
|
2013-02-19 21:00:09 +00:00
|
|
|
"$base/unittest-cont1/e/a/z.txt" ),
|
2012-09-22 18:46:48 +00:00
|
|
|
array( "contents xx", "contents xy", "contents xz" )
|
|
|
|
|
);
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2012-01-04 02:15:07 +00:00
|
|
|
* @dataProvider provider_testGetLocalReference
|
2011-12-20 03:52:06 +00:00
|
|
|
*/
|
2012-01-27 22:46:55 +00:00
|
|
|
public function testGetLocalReference( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestGetLocalReference( $source, $content );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->doTestGetLocalReference( $source, $content );
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-22 00:34:04 +00:00
|
|
|
private function doTestGetLocalReference( $source, $content ) {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-09-18 18:21:30 +00:00
|
|
|
$srcs = (array)$source;
|
2012-09-22 18:46:48 +00:00
|
|
|
$content = (array)$content;
|
|
|
|
|
foreach ( $srcs as $i => $src ) {
|
2012-09-18 18:21:30 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $src ) ) );
|
|
|
|
|
$status = $this->backend->doOperation(
|
2012-09-22 18:46:48 +00:00
|
|
|
array( 'op' => 'create', 'content' => $content[$i], 'dst' => $src ) );
|
2012-09-18 18:21:30 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Creation of file at $src succeeded ($backendName)." );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-09-18 18:21:30 +00:00
|
|
|
if ( is_array( $source ) ) {
|
|
|
|
|
$tmpFiles = $this->backend->getLocalReferenceMulti( array( 'srcs' => $source ) );
|
|
|
|
|
foreach ( $tmpFiles as $path => $tmpFile ) {
|
|
|
|
|
$this->assertNotNull( $tmpFile,
|
|
|
|
|
"Creation of local copy of $path succeeded ($backendName)." );
|
|
|
|
|
$contents = file_get_contents( $tmpFile->getPath() );
|
|
|
|
|
$this->assertNotEquals( false, $contents, "Local ref of $path exists ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( current( $content ), $contents, "Local ref of $path is correct ($backendName)." );
|
|
|
|
|
next( $content );
|
2012-09-18 18:21:30 +00:00
|
|
|
}
|
|
|
|
|
$this->assertEquals( $source, array_keys( $tmpFiles ), "Local refs in right order ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( count( $source ), count( $tmpFiles ), "Local refs array size correct ($backendName)." );
|
2012-09-18 18:21:30 +00:00
|
|
|
} else {
|
|
|
|
|
$tmpFile = $this->backend->getLocalReference( array( 'src' => $source ) );
|
|
|
|
|
$this->assertNotNull( $tmpFile,
|
|
|
|
|
"Creation of local copy of $source succeeded ($backendName)." );
|
|
|
|
|
$contents = file_get_contents( $tmpFile->getPath() );
|
|
|
|
|
$this->assertNotEquals( false, $contents, "Local ref of $source exists ($backendName)." );
|
2012-09-22 18:46:48 +00:00
|
|
|
$this->assertEquals( $content[0], $contents, "Local ref of $source is correct ($backendName)." );
|
2012-09-18 18:21:30 +00:00
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testGetLocalReference() {
|
2011-12-20 03:52:06 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-06-13 00:23:53 +00:00
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
|
2012-09-18 18:21:30 +00:00
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test file contents" );
|
|
|
|
|
$cases[] = array(
|
|
|
|
|
array( "$base/unittest-cont1/e/a/x.txt", "$base/unittest-cont1/e/a/y.txt",
|
2013-02-19 21:00:09 +00:00
|
|
|
"$base/unittest-cont1/e/a/z.txt" ),
|
2012-09-22 18:46:48 +00:00
|
|
|
array( "contents xx", "contents xy", "contents xz" )
|
|
|
|
|
);
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
return $cases;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-17 20:15:36 +00:00
|
|
|
public function testGetLocalCopyAndReference404() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetLocalCopyAndReference404();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetLocalCopyAndReference404();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function doTestGetLocalCopyAndReference404() {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
|
|
|
|
$base = self::baseStorePath();
|
|
|
|
|
|
|
|
|
|
$tmpFile = $this->backend->getLocalCopy( array(
|
|
|
|
|
'src' => "$base/unittest-cont1/not-there" ) );
|
|
|
|
|
$this->assertEquals( null, $tmpFile, "Local copy of not existing file is null ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$tmpFile = $this->backend->getLocalReference( array(
|
|
|
|
|
'src' => "$base/unittest-cont1/not-there" ) );
|
|
|
|
|
$this->assertEquals( null, $tmpFile, "Local ref of not existing file is null ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-06 20:49:40 +00:00
|
|
|
/**
|
|
|
|
|
* @dataProvider provider_testGetFileHttpUrl
|
|
|
|
|
*/
|
|
|
|
|
public function testGetFileHttpUrl( $source, $content ) {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetFileHttpUrl( $source, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetFileHttpUrl( $source, $content );
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doTestGetFileHttpUrl( $source, $content ) {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $source ) ) );
|
|
|
|
|
$status = $this->backend->doOperation(
|
|
|
|
|
array( 'op' => 'create', 'content' => $content, 'dst' => $source ) );
|
|
|
|
|
$this->assertGoodStatus( $status,
|
|
|
|
|
"Creation of file at $source succeeded ($backendName)." );
|
|
|
|
|
|
|
|
|
|
$url = $this->backend->getFileHttpUrl( array( 'src' => $source ) );
|
|
|
|
|
|
|
|
|
|
if ( $url !== null ) { // supported
|
|
|
|
|
$data = Http::request( "GET", $url );
|
|
|
|
|
$this->assertEquals( $content, $data,
|
|
|
|
|
"HTTP GET of URL has right contents ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testGetFileHttpUrl() {
|
2012-11-06 20:49:40 +00:00
|
|
|
$cases = array();
|
|
|
|
|
|
|
|
|
|
$base = self::baseStorePath();
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/z/some_file.txt", "some file contents" );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/some-other_file.txt", "more file contents" );
|
|
|
|
|
$cases[] = array( "$base/unittest-cont1/e/a/\$odd&.txt", "test 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 );
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->tearDownFiles();
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-09 00:20:28 +00:00
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestPrepareAndClean( $path, $isOK );
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-09 00:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
2013-03-22 02:12:37 +00:00
|
|
|
public static function provider_testPrepareAndClean() {
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-01-09 00:20:28 +00:00
|
|
|
return array(
|
2012-06-13 00:23:53 +00:00
|
|
|
array( "$base/unittest-cont1/e/a/z/some_file1.txt", true ),
|
2012-01-22 00:34:04 +00:00
|
|
|
array( "$base/unittest-cont2/a/z/some_file2.txt", true ),
|
|
|
|
|
# Specific to FS backend with no basePath field set
|
|
|
|
|
#array( "$base/unittest-cont3/a/z/some_file3.txt", false ),
|
2012-01-09 00:20:28 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private function doTestPrepareAndClean( $path, $isOK ) {
|
2012-01-09 00:20:28 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
$status = $this->prepare( array( 'dir' => dirname( $path ) ) );
|
2012-01-09 00:20:28 +00:00
|
|
|
if ( $isOK ) {
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-09 00:20:28 +00:00
|
|
|
"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-27 22:46:55 +00:00
|
|
|
$status = $this->backend->clean( array( 'dir' => dirname( $path ) ) );
|
2012-01-09 00:20:28 +00:00
|
|
|
if ( $isOK ) {
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-09 00:20:28 +00:00
|
|
|
"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)." );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-26 18:40:47 +00:00
|
|
|
public function testRecursiveClean() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestRecursiveClean();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->doTestRecursiveClean();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 00:42:20 +00:00
|
|
|
private function doTestRecursiveClean() {
|
2012-04-26 18:40:47 +00:00
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-04-26 18:40:47 +00:00
|
|
|
$dirs = array(
|
2012-11-16 20:47:01 +00:00
|
|
|
"$base/unittest-cont1",
|
|
|
|
|
"$base/unittest-cont1/e",
|
2012-06-13 00:23:53 +00:00
|
|
|
"$base/unittest-cont1/e/a",
|
|
|
|
|
"$base/unittest-cont1/e/a/b",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d0",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d1",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d2",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d0/1",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d0/2",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d1/3",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d1/4",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d2/5",
|
|
|
|
|
"$base/unittest-cont1/e/a/b/c/d2/6"
|
2012-04-26 18:40:47 +00:00
|
|
|
);
|
|
|
|
|
foreach ( $dirs as $dir ) {
|
|
|
|
|
$status = $this->prepare( array( 'dir' => $dir ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-04-26 18:40:47 +00:00
|
|
|
"Preparing dir $dir succeeded without warnings ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( $this->backend instanceof FSFileBackend ) {
|
|
|
|
|
foreach ( $dirs as $dir ) {
|
|
|
|
|
$this->assertEquals( true, $this->backend->directoryExists( array( 'dir' => $dir ) ),
|
|
|
|
|
"Dir $dir exists ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->clean(
|
|
|
|
|
array( 'dir' => "$base/unittest-cont1", 'recursive' => 1 ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-04-26 18:40:47 +00:00
|
|
|
"Recursive cleaning of dir $dir succeeded without warnings ($backendName)." );
|
|
|
|
|
|
|
|
|
|
foreach ( $dirs as $dir ) {
|
|
|
|
|
$this->assertEquals( false, $this->backend->directoryExists( array( 'dir' => $dir ) ),
|
|
|
|
|
"Dir $dir no longer exists ($backendName)." );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-09 00:20:28 +00:00
|
|
|
// @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;
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-15 22:45:14 +00:00
|
|
|
$this->doTestDoOperations();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-15 22:45:14 +00:00
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-15 22:45:14 +00:00
|
|
|
$this->doTestDoOperations();
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-15 22:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
private function doTestDoOperations() {
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-01-15 22:45:14 +00:00
|
|
|
|
2012-06-13 00:23:53 +00:00
|
|
|
$fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
|
2012-01-15 22:45:14 +00:00
|
|
|
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
|
2012-06-13 00:23:53 +00:00
|
|
|
$fileB = "$base/unittest-cont1/e/a/b/fileB.txt";
|
2012-01-15 22:45:14 +00:00
|
|
|
$fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
|
2012-06-13 00:23:53 +00:00
|
|
|
$fileC = "$base/unittest-cont1/e/a/b/fileC.txt";
|
2012-01-15 22:45:14 +00:00
|
|
|
$fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
|
2012-06-13 00:23:53 +00:00
|
|
|
$fileD = "$base/unittest-cont1/e/a/b/fileD.txt";
|
2012-01-15 22:45:14 +00:00
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileA ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileB ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileC ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
|
2012-04-11 04:56:42 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileD ) ) );
|
2012-01-15 22:45:14 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->doOperations( array(
|
2012-10-24 08:18:29 +00:00
|
|
|
array( 'op' => 'describe', 'src' => $fileA,
|
|
|
|
|
'headers' => array( 'X-Content-Length' => '91.3' ), 'disposition' => 'inline' ),
|
2012-01-19 02:24:49 +00:00
|
|
|
array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
|
2012-03-08 22:31:04 +00:00
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
|
2012-01-15 22:45:14 +00:00
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
|
2012-03-08 22:31:04 +00:00
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty>
|
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
|
2012-01-24 05:54:47 +00:00
|
|
|
array( 'op' => 'null' ),
|
|
|
|
|
// Does nothing
|
2012-01-15 22:45:14 +00:00
|
|
|
) );
|
|
|
|
|
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status, "Operation batch succeeded" );
|
2012-01-15 22:45:14 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
|
2012-10-24 08:18:29 +00:00
|
|
|
$this->assertEquals( 14, count( $status->success ),
|
2012-01-15 22:45:14 +00:00
|
|
|
"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" );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-08-23 21:13:20 +00:00
|
|
|
public function testDoOperationsPipeline() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestDoOperationsPipeline();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestDoOperationsPipeline();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 17:51:02 +00:00
|
|
|
// concurrency orientated
|
2012-08-23 21:13:20 +00:00
|
|
|
private function doTestDoOperationsPipeline() {
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-04-11 17:51:02 +00:00
|
|
|
|
|
|
|
|
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
|
|
|
|
|
$fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
|
|
|
|
|
$fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
|
|
|
|
|
|
|
|
|
|
$tmpNameA = TempFSFile::factory( "unittests_", 'txt' )->getPath();
|
|
|
|
|
file_put_contents( $tmpNameA, $fileAContents );
|
|
|
|
|
$tmpNameB = TempFSFile::factory( "unittests_", 'txt' )->getPath();
|
|
|
|
|
file_put_contents( $tmpNameB, $fileBContents );
|
|
|
|
|
$tmpNameC = TempFSFile::factory( "unittests_", 'txt' )->getPath();
|
|
|
|
|
file_put_contents( $tmpNameC, $fileCContents );
|
|
|
|
|
|
|
|
|
|
$this->filesToPrune[] = $tmpNameA; # avoid file leaking
|
|
|
|
|
$this->filesToPrune[] = $tmpNameB; # avoid file leaking
|
|
|
|
|
$this->filesToPrune[] = $tmpNameC; # avoid file leaking
|
|
|
|
|
|
2012-06-13 00:23:53 +00:00
|
|
|
$fileA = "$base/unittest-cont1/e/a/b/fileA.txt";
|
|
|
|
|
$fileB = "$base/unittest-cont1/e/a/b/fileB.txt";
|
|
|
|
|
$fileC = "$base/unittest-cont1/e/a/b/fileC.txt";
|
|
|
|
|
$fileD = "$base/unittest-cont1/e/a/b/fileD.txt";
|
2012-04-11 17:51:02 +00:00
|
|
|
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $fileA ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileB ) ) );
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $fileC ) ) );
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $fileD ) ) );
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->doOperations( array(
|
|
|
|
|
array( 'op' => 'store', 'src' => $tmpNameA, 'dst' => $fileA, 'overwriteSame' => 1 ),
|
|
|
|
|
array( 'op' => 'store', 'src' => $tmpNameB, 'dst' => $fileB, 'overwrite' => 1 ),
|
|
|
|
|
array( 'op' => 'store', 'src' => $tmpNameC, 'dst' => $fileC, 'overwrite' => 1 ),
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty>
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
|
|
|
|
|
// 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>
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileA, 'overwrite' => 1 ),
|
|
|
|
|
// 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>
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwrite' => 1 ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileC, 'overwriteSame' => 1 ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
array( 'op' => 'null' ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
$this->assertGoodStatus( $status, "Operation batch succeeded" );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
|
|
|
|
|
$this->assertEquals( 16, 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" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-23 21:13:20 +00:00
|
|
|
public function testDoOperationsFailing() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestDoOperationsFailing();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestDoOperationsFailing();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-16 00:42:20 +00:00
|
|
|
private function doTestDoOperationsFailing() {
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-03-08 22:31:04 +00:00
|
|
|
|
|
|
|
|
$fileA = "$base/unittest-cont2/a/b/fileA.txt";
|
|
|
|
|
$fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
|
|
|
|
|
$fileB = "$base/unittest-cont2/a/b/fileB.txt";
|
|
|
|
|
$fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
|
|
|
|
|
$fileC = "$base/unittest-cont2/a/b/fileC.txt";
|
|
|
|
|
$fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
|
|
|
|
|
$fileD = "$base/unittest-cont2/a/b/fileD.txt";
|
|
|
|
|
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $fileA ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
|
2012-03-08 22:31:04 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileB ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
|
2012-03-08 22:31:04 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $fileC ) ) );
|
2012-05-20 03:10:23 +00:00
|
|
|
$this->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
|
2012-03-08 22:31:04 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->doOperations( array(
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty>
|
|
|
|
|
array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<B>
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
|
|
|
|
|
// Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
|
|
|
|
|
array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
|
|
|
|
|
// Now: A:<B>, B:<empty>, C:<A>, D:<empty>
|
|
|
|
|
array( 'op' => 'delete', 'src' => $fileD ),
|
|
|
|
|
// Now: A:<B>, B:<empty>, C:<A>, D:<empty>
|
|
|
|
|
array( 'op' => 'null' ),
|
|
|
|
|
// Does nothing
|
|
|
|
|
), array( 'force' => 1 ) );
|
|
|
|
|
|
|
|
|
|
$this->assertNotEquals( array(), $status->errors, "Operation had warnings" );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
|
|
|
|
|
$this->assertEquals( 8, count( $status->success ),
|
|
|
|
|
"Operation batch has correct success array" );
|
|
|
|
|
|
|
|
|
|
$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' => $fileA ) ),
|
|
|
|
|
"File does not exist at $fileA" );
|
|
|
|
|
$this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
|
|
|
|
|
"File exists at $fileC" );
|
|
|
|
|
$this->assertEquals( $fileBContents,
|
|
|
|
|
$this->backend->getFileContents( array( 'src' => $fileA ) ),
|
|
|
|
|
"Correct file contents of $fileA" );
|
|
|
|
|
$this->assertEquals( strlen( $fileBContents ),
|
|
|
|
|
$this->backend->getFileSize( array( 'src' => $fileA ) ),
|
|
|
|
|
"Correct file size of $fileA" );
|
|
|
|
|
$this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
|
|
|
|
|
$this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
|
|
|
|
|
"Correct file SHA-1 of $fileA" );
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
public function testGetFileList() {
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->backend = $this->singleBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->doTestGetFileList();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->tearDownFiles();
|
2012-01-08 08:40:00 +00:00
|
|
|
$this->doTestGetFileList();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-22 00:34:04 +00:00
|
|
|
private function doTestGetFileList() {
|
2012-01-08 08:40:00 +00:00
|
|
|
$backendName = $this->backendClass();
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-06-05 22:58:54 +00:00
|
|
|
|
|
|
|
|
// Should have no errors
|
|
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont-notexists" ) );
|
|
|
|
|
|
2011-12-20 03:52:06 +00:00
|
|
|
$files = array(
|
2012-06-13 00:23:53 +00:00
|
|
|
"$base/unittest-cont1/e/test1.txt",
|
|
|
|
|
"$base/unittest-cont1/e/test2.txt",
|
|
|
|
|
"$base/unittest-cont1/e/test3.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir1/test1.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir1/test2.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/test3.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/test4.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/test1.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/test2.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/test3.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/test4.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/test5.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/sub/test0.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/sub/120-px-file.txt",
|
2011-12-20 03:52:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add the files
|
|
|
|
|
$ops = array();
|
|
|
|
|
foreach ( $files as $file ) {
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->prepare( array( 'dir' => dirname( $file ) ) );
|
2012-01-28 01:20:42 +00:00
|
|
|
$ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
2012-05-20 03:10:23 +00:00
|
|
|
$status = $this->backend->doQuickOperations( $ops );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-01-08 08:40:00 +00:00
|
|
|
"Creation of files succeeded ($backendName)." );
|
2012-01-22 00:34:04 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of files succeeded with OK status ($backendName)." );
|
2011-12-20 03:52:06 +00:00
|
|
|
|
|
|
|
|
// Expected listing
|
|
|
|
|
$expected = array(
|
2012-06-13 00:23:53 +00:00
|
|
|
"e/test1.txt",
|
|
|
|
|
"e/test2.txt",
|
|
|
|
|
"e/test3.txt",
|
|
|
|
|
"e/subdir1/test1.txt",
|
|
|
|
|
"e/subdir1/test2.txt",
|
|
|
|
|
"e/subdir2/test3.txt",
|
|
|
|
|
"e/subdir2/test4.txt",
|
|
|
|
|
"e/subdir2/subdir/test1.txt",
|
|
|
|
|
"e/subdir2/subdir/test2.txt",
|
|
|
|
|
"e/subdir2/subdir/test3.txt",
|
|
|
|
|
"e/subdir2/subdir/test4.txt",
|
|
|
|
|
"e/subdir2/subdir/test5.txt",
|
|
|
|
|
"e/subdir2/subdir/sub/test0.txt",
|
|
|
|
|
"e/subdir2/subdir/sub/120-px-file.txt",
|
2011-12-20 03:52:06 +00:00
|
|
|
);
|
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();
|
2012-01-22 00:34:04 +00:00
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1" ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
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();
|
2012-01-22 00:34:04 +00:00
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/" ) );
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Expected listing
|
|
|
|
|
$expected = array(
|
|
|
|
|
"test1.txt",
|
|
|
|
|
"test2.txt",
|
|
|
|
|
"test3.txt",
|
|
|
|
|
"test4.txt",
|
|
|
|
|
"test5.txt",
|
|
|
|
|
"sub/test0.txt",
|
|
|
|
|
"sub/120-px-file.txt",
|
|
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (no trailing slash)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
|
2012-01-22 00:34:04 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct file listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Actual listing (with trailing slash)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir/" ) );
|
2011-12-20 03:52:06 +00:00
|
|
|
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
|
|
|
|
2012-02-08 22:13:03 +00:00
|
|
|
// Actual listing (using iterator second time)
|
|
|
|
|
$list = array();
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct file listing ($backendName), second iteration." );
|
|
|
|
|
|
2012-04-05 05:56:08 +00:00
|
|
|
// Expected listing (top files only)
|
|
|
|
|
$expected = array(
|
|
|
|
|
"test1.txt",
|
|
|
|
|
"test2.txt",
|
|
|
|
|
"test3.txt",
|
|
|
|
|
"test4.txt",
|
|
|
|
|
"test5.txt"
|
|
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (top files only)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getTopFileList( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) );
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top file listing ($backendName)." );
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
foreach ( $files as $file ) { // clean up
|
|
|
|
|
$this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
|
2012-01-22 00:34:04 +00:00
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
|
2013-03-25 23:27:14 +00:00
|
|
|
foreach ( $iter as $iter ) {
|
|
|
|
|
// no errors
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-05 05:56:08 +00:00
|
|
|
public function testGetDirectoryList() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetDirectoryList();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->multiBackend;
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
$this->doTestGetDirectoryList();
|
|
|
|
|
$this->tearDownFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doTestGetDirectoryList() {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-04-05 05:56:08 +00:00
|
|
|
$files = array(
|
2012-06-13 00:23:53 +00:00
|
|
|
"$base/unittest-cont1/e/test1.txt",
|
|
|
|
|
"$base/unittest-cont1/e/test2.txt",
|
|
|
|
|
"$base/unittest-cont1/e/test3.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir1/test1.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir1/test2.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/test3.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/test4.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir2/subdir/test1.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir3/subdir/test2.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir4/subdir/test3.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir4/subdir/test4.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir4/subdir/test5.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir4/subdir/sub/test0.txt",
|
|
|
|
|
"$base/unittest-cont1/e/subdir4/subdir/sub/120-px-file.txt",
|
2012-04-05 05:56:08 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Add the files
|
|
|
|
|
$ops = array();
|
|
|
|
|
foreach ( $files as $file ) {
|
|
|
|
|
$this->prepare( array( 'dir' => dirname( $file ) ) );
|
|
|
|
|
$ops[] = array( 'op' => 'create', 'content' => 'xxy', 'dst' => $file );
|
|
|
|
|
}
|
2012-05-20 03:10:23 +00:00
|
|
|
$status = $this->backend->doQuickOperations( $ops );
|
2012-04-11 17:51:02 +00:00
|
|
|
$this->assertGoodStatus( $status,
|
2012-04-05 05:56:08 +00:00
|
|
|
"Creation of files succeeded ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Creation of files succeeded with OK status ($backendName)." );
|
|
|
|
|
|
2012-06-13 00:23:53 +00:00
|
|
|
$this->assertEquals( true,
|
|
|
|
|
$this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) ),
|
|
|
|
|
"Directory exists in ($backendName)." );
|
|
|
|
|
$this->assertEquals( true,
|
|
|
|
|
$this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/subdir" ) ),
|
|
|
|
|
"Directory exists in ($backendName)." );
|
|
|
|
|
$this->assertEquals( false,
|
|
|
|
|
$this->backend->directoryExists( array( 'dir' => "$base/unittest-cont1/e/subdir2/test1.txt" ) ),
|
|
|
|
|
"Directory does not exists in ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Expected listing
|
|
|
|
|
$expected = array(
|
|
|
|
|
"e",
|
|
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (no trailing slash)
|
|
|
|
|
$list = array();
|
|
|
|
|
$iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1" ) );
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
|
|
|
|
|
|
2012-04-05 05:56:08 +00:00
|
|
|
// Expected listing
|
|
|
|
|
$expected = array(
|
|
|
|
|
"subdir1",
|
|
|
|
|
"subdir2",
|
|
|
|
|
"subdir3",
|
|
|
|
|
"subdir4",
|
|
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (no trailing slash)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e" ) );
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Actual listing (with trailing slash)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/" ) );
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Expected listing
|
|
|
|
|
$expected = array(
|
|
|
|
|
"subdir",
|
|
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (no trailing slash)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2" ) );
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Actual listing (with trailing slash)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getTopDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir2/" ) );
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top dir listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Actual listing (using iterator second time)
|
|
|
|
|
$list = array();
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct top dir listing ($backendName), second iteration." );
|
|
|
|
|
|
|
|
|
|
// Expected listing (recursive)
|
|
|
|
|
$expected = array(
|
2012-06-13 00:23:53 +00:00
|
|
|
"e",
|
|
|
|
|
"e/subdir1",
|
|
|
|
|
"e/subdir2",
|
|
|
|
|
"e/subdir3",
|
|
|
|
|
"e/subdir4",
|
|
|
|
|
"e/subdir2/subdir",
|
|
|
|
|
"e/subdir3/subdir",
|
|
|
|
|
"e/subdir4/subdir",
|
|
|
|
|
"e/subdir4/subdir/sub",
|
2012-04-05 05:56:08 +00:00
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (recursive)
|
|
|
|
|
$list = array();
|
|
|
|
|
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/" ) );
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Expected listing (recursive)
|
|
|
|
|
$expected = array(
|
|
|
|
|
"subdir",
|
|
|
|
|
"subdir/sub",
|
|
|
|
|
);
|
|
|
|
|
sort( $expected );
|
|
|
|
|
|
|
|
|
|
// Actual listing (recursive)
|
|
|
|
|
$list = array();
|
2012-06-13 00:23:53 +00:00
|
|
|
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir4" ) );
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
|
|
|
|
|
|
|
|
|
|
// Actual listing (recursive, second time)
|
|
|
|
|
$list = array();
|
|
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
$list[] = $file;
|
|
|
|
|
}
|
|
|
|
|
sort( $list );
|
|
|
|
|
|
|
|
|
|
$this->assertEquals( $expected, $list, "Correct dir listing ($backendName)." );
|
|
|
|
|
|
2013-01-23 20:50:17 +00:00
|
|
|
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/subdir1" ) );
|
|
|
|
|
$items = is_array( $iter ) ? $iter : iterator_to_array( $iter );
|
|
|
|
|
$this->assertEquals( array(), $items, "Directory listing is empty." );
|
|
|
|
|
|
2012-04-05 05:56:08 +00:00
|
|
|
foreach ( $files as $file ) { // clean up
|
|
|
|
|
$this->backend->doOperation( array( 'op' => 'delete', 'src' => $file ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/not/exists" ) );
|
2013-03-25 23:27:14 +00:00
|
|
|
foreach ( $iter as $file ) {
|
|
|
|
|
// no errors
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-23 20:50:17 +00:00
|
|
|
$items = is_array( $iter ) ? $iter : iterator_to_array( $iter );
|
|
|
|
|
$this->assertEquals( array(), $items, "Directory listing is empty." );
|
|
|
|
|
|
|
|
|
|
$iter = $this->backend->getDirectoryList( array( 'dir' => "$base/unittest-cont1/e/not/exists" ) );
|
|
|
|
|
$items = is_array( $iter ) ? $iter : iterator_to_array( $iter );
|
|
|
|
|
$this->assertEquals( array(), $items, "Directory listing is empty." );
|
2012-04-05 05:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-11 04:56:42 +00:00
|
|
|
public function testLockCalls() {
|
|
|
|
|
$this->backend = $this->singleBackend;
|
|
|
|
|
$this->doTestLockCalls();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function doTestLockCalls() {
|
|
|
|
|
$backendName = $this->backendClass();
|
|
|
|
|
|
2013-02-19 18:51:44 +00:00
|
|
|
$paths = array(
|
|
|
|
|
"test1.txt",
|
|
|
|
|
"test2.txt",
|
|
|
|
|
"test3.txt",
|
|
|
|
|
"subdir1",
|
|
|
|
|
"subdir1", // duplicate
|
|
|
|
|
"subdir1/test1.txt",
|
|
|
|
|
"subdir1/test2.txt",
|
|
|
|
|
"subdir2",
|
|
|
|
|
"subdir2", // duplicate
|
|
|
|
|
"subdir2/test3.txt",
|
|
|
|
|
"subdir2/test4.txt",
|
|
|
|
|
"subdir2/subdir",
|
|
|
|
|
"subdir2/subdir/test1.txt",
|
|
|
|
|
"subdir2/subdir/test2.txt",
|
|
|
|
|
"subdir2/subdir/test3.txt",
|
|
|
|
|
"subdir2/subdir/test4.txt",
|
|
|
|
|
"subdir2/subdir/test5.txt",
|
|
|
|
|
"subdir2/subdir/sub",
|
|
|
|
|
"subdir2/subdir/sub/test0.txt",
|
|
|
|
|
"subdir2/subdir/sub/120-px-file.txt",
|
|
|
|
|
);
|
2012-04-11 04:56:42 +00:00
|
|
|
|
2013-03-25 23:27:14 +00:00
|
|
|
for ( $i = 0; $i < 25; $i++ ) {
|
2012-04-11 04:56:42 +00:00
|
|
|
$status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
|
2013-02-19 18:51:44 +00:00
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2013-02-19 18:51:44 +00:00
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
|
2013-02-19 18:51:44 +00:00
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2013-02-19 18:51:44 +00:00
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
|
2013-02-19 18:51:44 +00:00
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName) ($i)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
|
|
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName). ($i)" );
|
2012-04-11 04:56:42 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2013-02-19 18:51:44 +00:00
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
|
|
|
|
|
|
|
|
|
## Flip the acquire/release ordering around ##
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH );
|
|
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName) ($i)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX );
|
|
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName) ($i)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
|
|
|
|
|
$status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX );
|
2013-02-19 18:51:44 +00:00
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName). ($i)" );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
|
|
|
|
|
|
|
|
|
$status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH );
|
|
|
|
|
$this->assertEquals( print_r( array(), true ), print_r( $status->errors, true ),
|
|
|
|
|
"Locking of files succeeded ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
$this->assertEquals( true, $status->isOK(),
|
2013-02-19 18:51:44 +00:00
|
|
|
"Locking of files succeeded with OK status ($backendName) ($i)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
}
|
2013-03-05 19:03:20 +00:00
|
|
|
|
|
|
|
|
$status = Status::newGood();
|
|
|
|
|
$sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status );
|
|
|
|
|
$this->assertType( 'ScopedLock', $sl,
|
|
|
|
|
"Scoped locking of files succeeded ($backendName)." );
|
|
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Scoped locking of files succeeded ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Scoped locking of files succeeded with OK status ($backendName)." );
|
|
|
|
|
|
|
|
|
|
ScopedLock::release( $sl );
|
|
|
|
|
$this->assertEquals( null, $sl,
|
|
|
|
|
"Scoped unlocking of files succeeded ($backendName)." );
|
|
|
|
|
$this->assertEquals( array(), $status->errors,
|
|
|
|
|
"Scoped unlocking of files succeeded ($backendName)." );
|
|
|
|
|
$this->assertEquals( true, $status->isOK(),
|
|
|
|
|
"Scoped unlocking of files succeeded with OK status ($backendName)." );
|
2012-04-11 04:56:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-29 21:28:31 +00:00
|
|
|
// test helper wrapper for backend prepare() function
|
2012-01-27 22:46:55 +00:00
|
|
|
private function prepare( array $params ) {
|
|
|
|
|
return $this->backend->prepare( $params );
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-20 03:10:23 +00:00
|
|
|
// test helper wrapper for backend prepare() function
|
|
|
|
|
private function create( array $params ) {
|
|
|
|
|
$params['op'] = 'create';
|
|
|
|
|
return $this->backend->doQuickOperations( array( $params ) );
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-08 08:40:00 +00:00
|
|
|
function tearDownFiles() {
|
2011-12-20 03:52:06 +00:00
|
|
|
foreach ( $this->filesToPrune as $file ) {
|
2013-04-17 18:20:50 +00:00
|
|
|
if ( is_file( $file ) ) {
|
|
|
|
|
unlink( $file );
|
|
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
2012-10-05 22:07:23 +00:00
|
|
|
$containers = array( 'unittest-cont1', 'unittest-cont2' );
|
2012-01-22 00:34:04 +00:00
|
|
|
foreach ( $containers as $container ) {
|
2012-01-27 22:46:55 +00:00
|
|
|
$this->deleteFiles( $container );
|
2012-01-22 00:34:04 +00:00
|
|
|
}
|
2012-05-16 00:42:20 +00:00
|
|
|
$this->filesToPrune = array();
|
2012-01-22 00:34:04 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-27 22:46:55 +00:00
|
|
|
private function deleteFiles( $container ) {
|
2012-10-08 10:56:20 +00:00
|
|
|
$base = self::baseStorePath();
|
2012-01-27 22:46:55 +00:00
|
|
|
$iter = $this->backend->getFileList( array( 'dir' => "$base/$container" ) );
|
2012-01-22 00:34:04 +00:00
|
|
|
if ( $iter ) {
|
2012-01-27 22:46:55 +00:00
|
|
|
foreach ( $iter as $file ) {
|
2012-10-05 22:07:23 +00:00
|
|
|
$this->backend->quickDelete( array( 'src' => "$base/$container/$file" ) );
|
2012-01-20 22:46:35 +00:00
|
|
|
}
|
2012-11-16 20:47:01 +00:00
|
|
|
// free the directory, to avoid Permission denied under windows on rmdir
|
|
|
|
|
unset( $iter );
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|
2012-05-16 00:42:20 +00:00
|
|
|
$this->backend->clean( array( 'dir' => "$base/$container", 'recursive' => 1 ) );
|
2012-04-11 17:51:02 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-17 23:34:52 +00:00
|
|
|
function assertBackendPathsConsistent( array $paths ) {
|
|
|
|
|
if ( $this->backend instanceof FileBackendMultiWrite ) {
|
|
|
|
|
$status = $this->backend->consistencyCheck( $paths );
|
|
|
|
|
$this->assertGoodStatus( $status, "Files synced: " . implode( ',', $paths ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-11 17:51:02 +00:00
|
|
|
function assertGoodStatus( $status, $msg ) {
|
|
|
|
|
$this->assertEquals( print_r( array(), 1 ), print_r( $status->errors, 1 ), $msg );
|
2012-01-27 22:46:55 +00:00
|
|
|
}
|
2011-12-20 03:52:06 +00:00
|
|
|
}
|