diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-27 21:51:23 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-06-06 09:56:00 +0200 |
commit | 844b1e3fc6aae56926cac27b2402fa16cda2c60a (patch) | |
tree | 1a2f9b49d3fceb420ee679689b1caf22761ff12a /apps/files_sharing/tests/sharedmount.php | |
parent | cf5eb0fef546de0523157e943a97abcc8f3d1186 (diff) | |
download | nextcloud-server-844b1e3fc6aae56926cac27b2402fa16cda2c60a.tar.gz nextcloud-server-844b1e3fc6aae56926cac27b2402fa16cda2c60a.zip |
add additional unit tests
Diffstat (limited to 'apps/files_sharing/tests/sharedmount.php')
-rw-r--r-- | apps/files_sharing/tests/sharedmount.php | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/apps/files_sharing/tests/sharedmount.php b/apps/files_sharing/tests/sharedmount.php new file mode 100644 index 00000000000..2bdaf0a72f5 --- /dev/null +++ b/apps/files_sharing/tests/sharedmount.php @@ -0,0 +1,139 @@ +<?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'; + +/** + * Class Test_Files_Sharing_Api + */ +class Test_Files_Sharing_Mount extends Test_Files_Sharing_Base { + + function setUp() { + parent::setUp(); + + $this->folder = '/folder_share_storage_test'; + + $this->filename = '/share-api-storage.txt'; + + + $this->view->mkdir($this->folder); + + // save file with content + $this->view->file_put_contents($this->filename, "root file"); + $this->view->file_put_contents($this->folder . $this->filename, "file in subfolder"); + } + + function tearDown() { + $this->view->unlink($this->folder); + $this->view->unlink($this->filename); + + parent::tearDown(); + } + + /** + * test if the mount point moves up if the parent folder no longer exists + */ + function testShareMountLoseParentFolder() { + + // 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); + + $statement = "UPDATE `*PREFIX*share` SET `file_target` = ? where `share_with` = ?"; + $query = \OC_DB::prepare($statement); + $arguments = array('/foo/bar' . $this->folder, self::TEST_FILES_SHARING_API_USER2); + $query->execute($arguments); + + $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); + $result = $query->execute(); + + $shares = $result->fetchAll(); + + $this->assertSame(1, count($shares)); + + $share = reset($shares); + $this->assertSame('/foo/bar' . $this->folder, $share['file_target']); + + self::loginHelper(self::TEST_FILES_SHARING_API_USER2); + + // share should have moved up + + $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share`'); + $result = $query->execute(); + + $shares = $result->fetchAll(); + + $this->assertSame(1, count($shares)); + + $share = reset($shares); + $this->assertSame($this->folder, $share['file_target']); + + //cleanup + self::loginHelper(self::TEST_FILES_SHARING_API_USER1); + \OCP\Share::unshare('folder', $fileinfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2); + $this->view->unlink($this->folder); + } + + /** + * @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); + } + +} |