diff options
author | Björn Schießle <bjoern@schiessle.org> | 2014-11-03 12:53:14 +0100 |
---|---|---|
committer | Björn Schießle <bjoern@schiessle.org> | 2014-11-03 12:53:14 +0100 |
commit | 79b650a0238089a935073c1ebe7e33fd7a0c52a4 (patch) | |
tree | b7cb251c83a319a9f041f1d3148cf2ceef9bb671 /apps/files_versions/tests/versions.php | |
parent | 1a5d860be81837e598bbf0eb8039b271504fced0 (diff) | |
parent | ebe1d3df0a51f3517ea14ea4d3ba9c770f4f85c1 (diff) | |
download | nextcloud-server-79b650a0238089a935073c1ebe7e33fd7a0c52a4.tar.gz nextcloud-server-79b650a0238089a935073c1ebe7e33fd7a0c52a4.zip |
Merge pull request #11825 from owncloud/fix_rename_files_in_shared_folder
move versions if a file was renamed in a shared folder
Diffstat (limited to 'apps/files_versions/tests/versions.php')
-rw-r--r-- | apps/files_versions/tests/versions.php | 101 |
1 files changed, 99 insertions, 2 deletions
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php index 4909d0606b1..a3b8595a34b 100644 --- a/apps/files_versions/tests/versions.php +++ b/apps/files_versions/tests/versions.php @@ -30,6 +30,7 @@ require_once __DIR__ . '/../lib/versions.php'; class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { const TEST_VERSIONS_USER = 'test-versions-user'; + const TEST_VERSIONS_USER2 = 'test-versions-user2'; const USERS_VERSIONS_ROOT = '/test-versions-user/files_versions'; /** @@ -38,13 +39,22 @@ class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { private $rootView; public static function setUpBeforeClass() { + + // clear share hooks + \OC_Hook::clear('OCP\\Share'); + \OC::registerShareHooks(); + \OCA\Files_Versions\Hooks::connectHooks(); + \OCP\Util::connectHook('OC_Filesystem', 'setup', '\OC\Files\Storage\Shared', 'setup'); + // create test user + self::loginHelper(self::TEST_VERSIONS_USER2, true); self::loginHelper(self::TEST_VERSIONS_USER, true); } public static function tearDownAfterClass() { // cleanup test user \OC_User::deleteUser(self::TEST_VERSIONS_USER); + \OC_User::deleteUser(self::TEST_VERSIONS_USER2); } function setUp() { @@ -225,7 +235,7 @@ class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { $this->rootView->file_put_contents($v2, 'version2'); // execute rename hook of versions app - \OCA\Files_Versions\Storage::renameOrCopy("test.txt", "test2.txt", 'rename'); + \OC\Files\Filesystem::rename("test.txt", "test2.txt"); $this->assertFalse($this->rootView->file_exists($v1)); $this->assertFalse($this->rootView->file_exists($v2)); @@ -237,6 +247,93 @@ class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { \OC\Files\Filesystem::unlink('test2.txt'); } + function testRenameInSharedFolder() { + + \OC\Files\Filesystem::mkdir('folder1'); + \OC\Files\Filesystem::mkdir('folder1/folder2'); + \OC\Files\Filesystem::file_put_contents("folder1/test.txt", "test file"); + + $fileInfo = \OC\Files\Filesystem::getFileInfo('folder1'); + + $t1 = time(); + // second version is two weeks older, this way we make sure that no + // version will be expired + $t2 = $t1 - 60 * 60 * 24 * 14; + + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/folder1'); + // create some versions + $v1 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t1; + $v2 = self::USERS_VERSIONS_ROOT . '/folder1/test.txt.v' . $t2; + $v1Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t1; + $v2Renamed = self::USERS_VERSIONS_ROOT . '/folder1/folder2/test.txt.v' . $t2; + + $this->rootView->file_put_contents($v1, 'version1'); + $this->rootView->file_put_contents($v2, 'version2'); + + \OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, OCP\PERMISSION_ALL); + + self::loginHelper(self::TEST_VERSIONS_USER2); + + $this->assertTrue(\OC\Files\Filesystem::file_exists('folder1/test.txt')); + + // execute rename hook of versions app + \OC\Files\Filesystem::rename('/folder1/test.txt', '/folder1/folder2/test.txt'); + + self::loginHelper(self::TEST_VERSIONS_USER2); + + $this->assertFalse($this->rootView->file_exists($v1)); + $this->assertFalse($this->rootView->file_exists($v2)); + + $this->assertTrue($this->rootView->file_exists($v1Renamed)); + $this->assertTrue($this->rootView->file_exists($v2Renamed)); + + //cleanup + \OC\Files\Filesystem::unlink('/folder1/folder2/test.txt'); + } + + function testRenameSharedFile() { + + \OC\Files\Filesystem::file_put_contents("test.txt", "test file"); + + $fileInfo = \OC\Files\Filesystem::getFileInfo('test.txt'); + + $t1 = time(); + // second version is two weeks older, this way we make sure that no + // version will be expired + $t2 = $t1 - 60 * 60 * 24 * 14; + + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); + // create some versions + $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; + $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; + // the renamed versions should not exist! Because we only moved the mount point! + $v1Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; + $v2Renamed = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; + + $this->rootView->file_put_contents($v1, 'version1'); + $this->rootView->file_put_contents($v2, 'version2'); + + \OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, OCP\PERMISSION_ALL); + + self::loginHelper(self::TEST_VERSIONS_USER2); + + $this->assertTrue(\OC\Files\Filesystem::file_exists('test.txt')); + + // execute rename hook of versions app + \OC\Files\Filesystem::rename('test.txt', 'test2.txt'); + + self::loginHelper(self::TEST_VERSIONS_USER); + + $this->assertTrue($this->rootView->file_exists($v1)); + $this->assertTrue($this->rootView->file_exists($v2)); + + $this->assertFalse($this->rootView->file_exists($v1Renamed)); + $this->assertFalse($this->rootView->file_exists($v2Renamed)); + + //cleanup + \OC\Files\Filesystem::unlink('/test.txt'); + } + function testCopy() { \OC\Files\Filesystem::file_put_contents("test.txt", "test file"); @@ -256,7 +353,7 @@ class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { $this->rootView->file_put_contents($v2, 'version2'); // execute copy hook of versions app - \OCA\Files_Versions\Storage::renameOrCopy("test.txt", "test2.txt", 'copy'); + \OC\Files\Filesystem::copy("test.txt", "test2.txt"); $this->assertTrue($this->rootView->file_exists($v1)); $this->assertTrue($this->rootView->file_exists($v2)); |