diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-04-30 16:56:09 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-21 13:19:17 +0200 |
commit | 5f403f3e920ea8f6ed5d0441762b3e4f4a9bd38e (patch) | |
tree | 1390f388645003b9d4e5ee3ff5adc63e3dd48b62 /apps/files_sharing/tests | |
parent | 319942bccb0f08abd694219b1c7bcf1e71d589c4 (diff) | |
download | nextcloud-server-5f403f3e920ea8f6ed5d0441762b3e4f4a9bd38e.tar.gz nextcloud-server-5f403f3e920ea8f6ed5d0441762b3e4f4a9bd38e.zip |
move the mount point up if a share is mounted to a subfolder and the subfolder no longer exists
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r-- | apps/files_sharing/tests/proxy.php | 98 | ||||
-rw-r--r-- | apps/files_sharing/tests/sharedstorage.php | 46 | ||||
-rw-r--r-- | apps/files_sharing/tests/updater.php | 128 |
3 files changed, 252 insertions, 20 deletions
diff --git a/apps/files_sharing/tests/proxy.php b/apps/files_sharing/tests/proxy.php new file mode 100644 index 00000000000..402402082df --- /dev/null +++ b/apps/files_sharing/tests/proxy.php @@ -0,0 +1,98 @@ +<?php +/** + * ownCloud + * + * @author Bjoern Schiessle + * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +require_once __DIR__ . '/base.php'; + +use OCA\Files\Share; + +/** + * Class Test_Files_Sharing_Api + */ +class Test_Files_Sharing_Api extends Test_Files_Sharing_Base { + + const TEST_FOLDER_NAME = '/folder_share_api_test'; + + private static $tempStorage; + + function setUp() { + parent::setUp(); + + // load proxies + OC::$CLASSPATH['OCA\Files\Share\Proxy'] = 'files_sharing/lib/proxy.php'; + OC_FileProxy::register(new OCA\Files\Share\Proxy()); + + $this->folder = self::TEST_FOLDER_NAME; + $this->subfolder = '/subfolder_share_api_test'; + $this->subsubfolder = '/subsubfolder_share_api_test'; + + $this->filename = '/share-api-test'; + + // save file with content + $this->view->file_put_contents($this->filename, $this->data); + $this->view->mkdir($this->folder); + $this->view->mkdir($this->folder . $this->subfolder); + $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder); + $this->view->file_put_contents($this->folder.$this->filename, $this->data); + $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data); + } + + function tearDown() { + $this->view->unlink($this->filename); + $this->view->deleteAll($this->folder); + + self::$tempStorage = null; + + parent::tearDown(); + } + + /** + * @medium + */ + function testpreUnlink() { + + $fileInfo1 = \OC\Files\Filesystem::getFileInfo($this->filename); + $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder); + + $result = \OCP\Share::shareItem('file', $fileInfo1->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + $result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + $this->assertTrue($result); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + // move shared folder to 'localDir' and rename it, so that it uses the same + // name as the shared file + \OC\Files\Filesystem::mkdir('localDir'); + $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->filename); + $this->assertTrue($result); + + \OC\Files\Filesystem::unlink('localDir'); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + // after we deleted 'localDir' the share should be moved up to the root and be + // renamed to "filename (2)" + $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); + $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename . ' (2)' )); + } +} diff --git a/apps/files_sharing/tests/sharedstorage.php b/apps/files_sharing/tests/sharedstorage.php index 66518a2633f..258a2a9841b 100644 --- a/apps/files_sharing/tests/sharedstorage.php +++ b/apps/files_sharing/tests/sharedstorage.php @@ -49,6 +49,48 @@ class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base { /** * @medium */ + function testDeleteParentOfMountPoint() { + + // share to user + $fileinfo = $this->view->getFileInfo($this->folder); + $result = \OCP\Share::shareItem('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, + self::TEST_FILES_SHARING_API_USER2, 31); + + $this->assertTrue($result); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + $this->assertTrue($user2View->file_exists($this->folder)); + + // create a local folder + $result = $user2View->mkdir('localfolder'); + $this->assertTrue($result); + + // move mount point to local folder + $result = $user2View->rename($this->folder, '/localfolder/' . $this->folder); + $this->assertTrue($result); + + // mount point in the root folder should no longer exist + $this->assertFalse($user2View->is_dir($this->folder)); + + // delete the local folder + $result = $user2View->unlink('/localfolder'); + $this->assertTrue($result); + + //enforce reload of the mount points + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + //mount point should be back at the root + $this->assertTrue($user2View->is_dir($this->folder)); + + //cleanup + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + $this->view->unlink($this->folder); + } + + /** + * @medium + */ function testRenamePartFile() { // share to user @@ -79,5 +121,9 @@ class Test_Files_Sharing_Storage extends Test_Files_Sharing_Base { self::loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->assertTrue($this->view->file_exists( $this->folder. '/foo.txt')); + + //cleanup + $this->view->unlink($this->folder); } + } diff --git a/apps/files_sharing/tests/updater.php b/apps/files_sharing/tests/updater.php index 3427cfe388c..1b851cccf6c 100644 --- a/apps/files_sharing/tests/updater.php +++ b/apps/files_sharing/tests/updater.php @@ -21,47 +21,103 @@ */ require_once __DIR__ . '/../appinfo/update.php'; +require_once __DIR__ . '/base.php'; /** * Class Test_Files_Sharing_Updater */ -class Test_Files_Sharing_Updater extends \PHPUnit_Framework_TestCase { +class Test_Files_Sharing_Updater extends Test_Files_Sharing_Base { + + const TEST_FOLDER_NAME = '/folder_share_api_test'; function setUp() { - // some previous tests didn't clean up and therefore this has to be done here - // FIXME: DIRTY HACK - TODO: find tests, that don't clean up and fix it there - $this->tearDown(); + parent::setUp(); - // add items except one - because this is the test case for the broken share table - $addItems = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache` (`storage`, `path_hash`, ' . - '`parent`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`) ' . - 'VALUES (1, ?, 1, 1, 1, 1, 1, 1)'); - $items = array(1, 3); - $fileIds = array(); - foreach($items as $item) { - // the number is used as path_hash - $addItems->execute(array($item)); - $fileIds[] = \OC_DB::insertId('*PREFIX*filecache'); - } + $this->folder = self::TEST_FOLDER_NAME; - $addShares = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`file_source`, `item_type`, `uid_owner`) VALUES (?, \'file\', 1)'); - // the number is used as item_source - $addShares->execute(array($fileIds[0])); - $addShares->execute(array(200)); // id of "deleted" file - $addShares->execute(array($fileIds[1])); + $this->filename = '/share-api-test.txt'; + + // save file with content + $this->view->file_put_contents($this->filename, $this->data); + $this->view->mkdir($this->folder); + $this->view->file_put_contents($this->folder . '/' . $this->filename, $this->data); } function tearDown() { + $this->view->unlink($this->filename); + $this->view->deleteAll($this->folder); + $removeShares = \OC_DB::prepare('DELETE FROM `*PREFIX*share`'); $removeShares->execute(); $removeItems = \OC_DB::prepare('DELETE FROM `*PREFIX*filecache`'); $removeItems->execute(); + + parent::tearDown(); + } + + /** + * test deletion of a folder which contains share mount points. Share mount + * points should move up to the parent before the folder gets deleted so + * that the mount point doesn't end up at the trash bin + */ + function testDeleteParentFolder() { + $status = \OC_App::isEnabled('files_trashbin'); + \OC_App::enable('files_trashbin'); + + \OCA\Files_Trashbin\Trashbin::registerHooks(); + OC_FileProxy::register(new OCA\Files\Share\Proxy()); + + $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder); + $this->assertTrue($fileinfo instanceof \OC\Files\FileInfo); + + \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + + // check if user2 can see the shared folder + $this->assertTrue($view->file_exists($this->folder)); + + $view->mkdir("localFolder"); + $view->file_put_contents("localFolder/localFile.txt", "local file"); + + $view->rename($this->folder, 'localFolder/' . $this->folder); + + // share mount point should now be moved to the subfolder + $this->assertFalse($view->file_exists($this->folder)); + $this->assertTrue($view->file_exists('localFolder/' .$this->folder)); + + $view->unlink('localFolder'); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + + // mount point should move up again + $this->assertTrue($view->file_exists($this->folder)); + + // trashbin should contain the local file but not the mount point + $rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2); + $dirContent = $rootView->getDirectoryContent('files_trashbin/files'); + $this->assertSame(1, count($dirContent)); + $firstElement = reset($dirContent); + $ext = pathinfo($firstElement['path'], PATHINFO_EXTENSION); + $this->assertTrue($rootView->file_exists('files_trashbin/files/localFolder.' . $ext . '/localFile.txt')); + $this->assertFalse($rootView->file_exists('files_trashbin/files/localFolder.' . $ext . '/' . $this->folder)); + + //cleanup + $rootView->deleteAll('files_trashin'); + + if ($status === false) { + \OC_App::disable('files_trashbin'); + } } /** * @medium */ function testRemoveBrokenShares() { + + $this->prepareFileCache(); + // check if there are just 3 shares (see setUp - precondition: empty table) $countShares = \OC_DB::prepare('SELECT COUNT(`id`) FROM `*PREFIX*share`'); $result = $countShares->execute()->fetchOne(); @@ -114,6 +170,7 @@ class Test_Files_Sharing_Updater extends \PHPUnit_Framework_TestCase { } } + // cleanup $this->cleanupSharedTable(); } @@ -123,6 +180,9 @@ class Test_Files_Sharing_Updater extends \PHPUnit_Framework_TestCase { $query->execute(); } + /** + * prepare sharing table for testRemoveSharedFolder() + */ private function prepareDB() { $this->cleanupSharedTable(); // add items except one - because this is the test case for the broken share table @@ -143,4 +203,32 @@ class Test_Files_Sharing_Updater extends \PHPUnit_Framework_TestCase { $addItems->execute($item); } } + + /** + * prepare file cache for testRemoveBrokenShares() + */ + private function prepareFileCache() { + // some previous tests didn't clean up and therefore this has to be done here + // FIXME: DIRTY HACK - TODO: find tests, that don't clean up and fix it there + $this->tearDown(); + + // add items except one - because this is the test case for the broken share table + $addItems = \OC_DB::prepare('INSERT INTO `*PREFIX*filecache` (`storage`, `path_hash`, ' . + '`parent`, `mimetype`, `mimepart`, `size`, `mtime`, `storage_mtime`) ' . + 'VALUES (1, ?, 1, 1, 1, 1, 1, 1)'); + $items = array(1, 3); + $fileIds = array(); + foreach($items as $item) { + // the number is used as path_hash + $addItems->execute(array($item)); + $fileIds[] = \OC_DB::insertId('*PREFIX*filecache'); + } + + $addShares = \OC_DB::prepare('INSERT INTO `*PREFIX*share` (`file_source`, `item_type`, `uid_owner`) VALUES (?, \'file\', 1)'); + // the number is used as item_source + $addShares->execute(array($fileIds[0])); + $addShares->execute(array(200)); // id of "deleted" file + $addShares->execute(array($fileIds[1])); + } + } |