diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-07-24 16:49:38 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-07-30 15:14:01 +0200 |
commit | 1a797f90bbf55f9602f26f3853f7459076ff6291 (patch) | |
tree | 8bbdfc8e704900032b4aba19f75be7365069aa77 /apps/files_versions/tests | |
parent | dba2574c528b959f35ae47eeb5e6f0fbfdcb3b08 (diff) | |
download | nextcloud-server-1a797f90bbf55f9602f26f3853f7459076ff6291.tar.gz nextcloud-server-1a797f90bbf55f9602f26f3853f7459076ff6291.zip |
add unit test for rename and copy operation
Diffstat (limited to 'apps/files_versions/tests')
-rw-r--r-- | apps/files_versions/tests/versions.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php index aa66faffcbf..03432276358 100644 --- a/apps/files_versions/tests/versions.php +++ b/apps/files_versions/tests/versions.php @@ -20,6 +20,7 @@ * */ +require_once __DIR__ . '/../appinfo/app.php'; require_once __DIR__ . '/../lib/versions.php'; /** @@ -28,6 +29,32 @@ require_once __DIR__ . '/../lib/versions.php'; */ class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { + const TEST_VERSIONS_USER = 'test-versions-user'; + const USERS_VERSIONS_ROOT = '/test-versions-user/files_versions'; + + private $rootView; + + public static function setUpBeforeClass() { + // create test user + self::loginHelper(self::TEST_VERSIONS_USER, true); + } + + public static function tearDownAfterClass() { + // cleanup test user + \OC_User::deleteUser(self::TEST_VERSIONS_USER); + } + + function setUp() { + self::loginHelper(self::TEST_VERSIONS_USER); + $this->rootView = new \OC\Files\View(); + if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) { + $this->rootView->mkdir(self::USERS_VERSIONS_ROOT); + } + } + + function tearDown() { + $this->rootView->deleteAll(self::USERS_VERSIONS_ROOT); + } /** * @medium @@ -176,6 +203,87 @@ class Test_Files_Versioning extends \PHPUnit_Framework_TestCase { ); } + function testRename() { + + \OC\Files\Filesystem::file_put_contents("test.txt", "test file"); + + $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; + + // create some versions + $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; + $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; + $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'); + + // execute rename hook of versions app + \OCA\Files_Versions\Storage::renameOrCopy("test.txt", "test2.txt", 'rename'); + + $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('test2.txt'); + } + + function testCopy() { + + \OC\Files\Filesystem::file_put_contents("test.txt", "test file"); + + $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; + + // create some versions + $v1 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t1; + $v2 = self::USERS_VERSIONS_ROOT . '/test.txt.v' . $t2; + $v1Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t1; + $v2Copied = self::USERS_VERSIONS_ROOT . '/test2.txt.v' . $t2; + + $this->rootView->file_put_contents($v1, 'version1'); + $this->rootView->file_put_contents($v2, 'version2'); + + // execute copy hook of versions app + \OCA\Files_Versions\Storage::renameOrCopy("test.txt", "test2.txt", 'copy'); + + $this->assertTrue($this->rootView->file_exists($v1)); + $this->assertTrue($this->rootView->file_exists($v2)); + + $this->assertTrue($this->rootView->file_exists($v1Copied)); + $this->assertTrue($this->rootView->file_exists($v2Copied)); + + //cleanup + \OC\Files\Filesystem::unlink('test.txt'); + \OC\Files\Filesystem::unlink('test2.txt'); + } + + /** + * @param string $user + * @param bool $create + * @param bool $password + */ + public static function loginHelper($user, $create = false) { + + if ($create) { + \OC_User::createUser($user, $user); + } + + \OC_Util::tearDownFS(); + \OC_User::setUserId(''); + \OC\Files\Filesystem::tearDown(); + \OC_User::setUserId($user); + \OC_Util::setupFS($user); + } + } // extend the original class to make it possible to test protected methods |