diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-04-14 14:35:08 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-04-14 14:35:08 +0200 |
commit | 82cab257622759d1b64582f27de33a982c79c158 (patch) | |
tree | bcacfc55a044830e1a5529b9bece572bb6f180e8 /tests | |
parent | ffa115b51725c4774b49c2419f88cb91d726386b (diff) | |
parent | 0f21303b751291188733e24b5f213053ea96a368 (diff) | |
download | nextcloud-server-82cab257622759d1b64582f27de33a982c79c158.tar.gz nextcloud-server-82cab257622759d1b64582f27de33a982c79c158.zip |
Merge pull request #13360 from owncloud/cross-storage-move
Proper copy/move between multiple local storages
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/view.php | 88 |
1 files changed, 81 insertions, 7 deletions
diff --git a/tests/lib/files/view.php b/tests/lib/files/view.php index 2ea9e8de78f..269b8b23e7d 100644 --- a/tests/lib/files/view.php +++ b/tests/lib/files/view.php @@ -8,6 +8,7 @@ namespace Test\Files; use OC\Files\Cache\Watcher; +use OC\Files\Storage\Common; use OC\Files\Mount\MountPoint; use OC\Files\Storage\Temporary; @@ -17,6 +18,26 @@ class TemporaryNoTouch extends \OC\Files\Storage\Temporary { } } +class TemporaryNoCross extends \OC\Files\Storage\Temporary { + public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } + + public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); + } +} + +class TemporaryNoLocal extends \OC\Files\Storage\Temporary { + public function instanceOfStorage($className) { + if($className === '\OC\Files\Storage\Local') { + return false; + } else { + return parent::instanceOfStorage($className); + } + } +} + class View extends \Test\TestCase { /** * @var \OC\Files\Storage\Storage[] $storages @@ -291,9 +312,31 @@ class View extends \Test\TestCase { /** * @medium */ - function testCopyBetweenStorages() { + function testCopyBetweenStorageNoCross() { + $storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross'); + $storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross'); + $this->copyBetweenStorages($storage1, $storage2); + } + + /** + * @medium + */ + function testCopyBetweenStorageCross() { $storage1 = $this->getTestStorage(); $storage2 = $this->getTestStorage(); + $this->copyBetweenStorages($storage1, $storage2); + } + + /** + * @medium + */ + function testCopyBetweenStorageCrossNonLocal() { + $storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal'); + $storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal'); + $this->copyBetweenStorages($storage1, $storage2); + } + + function copyBetweenStorages($storage1, $storage2) { \OC\Files\Filesystem::mount($storage1, array(), '/'); \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); @@ -315,9 +358,31 @@ class View extends \Test\TestCase { /** * @medium */ - function testMoveBetweenStorages() { + function testMoveBetweenStorageNoCross() { + $storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross'); + $storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoCross'); + $this->moveBetweenStorages($storage1, $storage2); + } + + /** + * @medium + */ + function testMoveBetweenStorageCross() { $storage1 = $this->getTestStorage(); $storage2 = $this->getTestStorage(); + $this->moveBetweenStorages($storage1, $storage2); + } + + /** + * @medium + */ + function testMoveBetweenStorageCrossNonLocal() { + $storage1 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal'); + $storage2 = $this->getTestStorage(true, '\Test\Files\TemporaryNoLocal'); + $this->moveBetweenStorages($storage1, $storage2); + } + + function moveBetweenStorages($storage1, $storage2) { \OC\Files\Filesystem::mount($storage1, array(), '/'); \OC\Files\Filesystem::mount($storage2, array(), '/substorage'); @@ -879,8 +944,19 @@ class View extends \Test\TestCase { private function doTestCopyRenameFail($operation) { $storage1 = new Temporary(array()); - $storage2 = new Temporary(array()); - $storage2 = new \OC\Files\Storage\Wrapper\Quota(array('storage' => $storage2, 'quota' => 9)); + /** @var \PHPUnit_Framework_MockObject_MockObject | \OC\Files\Storage\Temporary $storage2 */ + $storage2 = $this->getMockBuilder('\Test\Files\TemporaryNoCross') + ->setConstructorArgs([[]]) + ->setMethods(['fopen']) + ->getMock(); + + $storage2->expects($this->any()) + ->method('fopen') + ->will($this->returnCallback(function($path, $mode) use($storage2) { + $source = fopen($storage2->getSourcePath($path), $mode); + return \OC\Files\Stream\Quota::wrap($source, 9); + })); + $storage1->mkdir('sub'); $storage1->file_put_contents('foo.txt', '0123456789ABCDEFGH'); $storage1->mkdir('dirtomove'); @@ -911,10 +987,8 @@ class View extends \Test\TestCase { $this->assertFalse($view->$operation('/test/dirtomove/', '/test/sub/storage/dirtomove/')); // since the move failed, the full source tree is kept $this->assertTrue($storage1->file_exists('dirtomove/indir1.txt')); - // but the target file stays - $this->assertTrue($storage2->file_exists('dirtomove/indir1.txt')); - // second file not moved/copied $this->assertTrue($storage1->file_exists('dirtomove/indir2.txt')); + // second file not moved/copied $this->assertFalse($storage2->file_exists('dirtomove/indir2.txt')); $this->assertFalse($storage2->getCache()->get('dirtomove/indir2.txt')); |