|
|
|
|
@ -161,26 +161,89 @@ abstract class Storage extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
$this->assertEquals('image/svg+xml', $this->instance->getMimeType('/logo-wide.svg'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testCopyAndMove() {
|
|
|
|
|
|
|
|
|
|
public function copyAndMoveProvider() {
|
|
|
|
|
return array(
|
|
|
|
|
array('/source.txt', '/target.txt'),
|
|
|
|
|
array('/source.txt', '/target with space.txt'),
|
|
|
|
|
array('/source with space.txt', '/target.txt'),
|
|
|
|
|
array('/source with space.txt', '/target with space.txt'),
|
|
|
|
|
array('/source.txt', '/tärgét.txt'),
|
|
|
|
|
array('/sòurcē.txt', '/target.txt'),
|
|
|
|
|
array('/sòurcē.txt', '/tärgét.txt'),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function initSourceAndTarget ($source, $target = null) {
|
|
|
|
|
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
|
|
|
|
|
$this->instance->file_put_contents($source, file_get_contents($textFile));
|
|
|
|
|
if ($target) {
|
|
|
|
|
$testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
|
$this->instance->file_put_contents($target, $testContents);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function assertSameAsLorem ($file) {
|
|
|
|
|
$textFile = \OC::$SERVERROOT . '/tests/data/lorem.txt';
|
|
|
|
|
$this->instance->file_put_contents('/source.txt', file_get_contents($textFile));
|
|
|
|
|
$this->instance->copy('/source.txt', '/target.txt');
|
|
|
|
|
$this->assertTrue($this->instance->file_exists('/target.txt'));
|
|
|
|
|
$this->assertEquals($this->instance->file_get_contents('/source.txt'), $this->instance->file_get_contents('/target.txt'));
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
file_get_contents($textFile),
|
|
|
|
|
$this->instance->file_get_contents($file),
|
|
|
|
|
'Expected '.$file.' to be a copy of '.$textFile
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider copyAndMoveProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testCopy($source, $target) {
|
|
|
|
|
$this->initSourceAndTarget($source);
|
|
|
|
|
|
|
|
|
|
$this->instance->copy($source, $target);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($target), $target.' was not created');
|
|
|
|
|
$this->assertSameAsLorem($target);
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($source), $source.' was deleted');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider copyAndMoveProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testMove($source, $target) {
|
|
|
|
|
$this->initSourceAndTarget($source);
|
|
|
|
|
|
|
|
|
|
$this->instance->rename($source, $target);
|
|
|
|
|
|
|
|
|
|
$this->instance->rename('/source.txt', '/target2.txt');
|
|
|
|
|
$this->wait();
|
|
|
|
|
$this->assertTrue($this->instance->file_exists('/target2.txt'));
|
|
|
|
|
$this->assertFalse($this->instance->file_exists('/source.txt'));
|
|
|
|
|
$this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target2.txt'));
|
|
|
|
|
|
|
|
|
|
// move to overwrite
|
|
|
|
|
$testContents = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
|
$this->instance->file_put_contents('/target3.txt', $testContents);
|
|
|
|
|
$this->instance->rename('/target2.txt', '/target3.txt');
|
|
|
|
|
$this->assertTrue($this->instance->file_exists('/target3.txt'));
|
|
|
|
|
$this->assertFalse($this->instance->file_exists('/target2.txt'));
|
|
|
|
|
$this->assertEquals(file_get_contents($textFile), $this->instance->file_get_contents('/target3.txt'));
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($target), $target.' was not created');
|
|
|
|
|
$this->assertFalse($this->instance->file_exists($source), $source.' still exists');
|
|
|
|
|
$this->assertSameAsLorem($target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider copyAndMoveProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testCopyOverwrite($source, $target) {
|
|
|
|
|
$this->initSourceAndTarget($source,$target);
|
|
|
|
|
|
|
|
|
|
$this->instance->copy($source, $target);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($target), $target.' was not created');
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($source), $source.' was deleted');
|
|
|
|
|
$this->assertSameAsLorem($target);
|
|
|
|
|
$this->assertSameAsLorem($source);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider copyAndMoveProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testMoveOverwrite($source, $target) {
|
|
|
|
|
$this->initSourceAndTarget($source, $target);
|
|
|
|
|
|
|
|
|
|
$this->instance->rename($source, $target);
|
|
|
|
|
|
|
|
|
|
$this->assertTrue($this->instance->file_exists($target), $target.' was not created');
|
|
|
|
|
$this->assertFalse($this->instance->file_exists($source), $source.' still exists');
|
|
|
|
|
$this->assertSameAsLorem($target);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testLocal() {
|
|
|
|
|
|