summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2015-05-15 12:24:34 +0200
committerVincent Petry <pvince81@owncloud.com>2015-05-15 12:24:34 +0200
commitf8a4cc0284bc7883a4fcc78c327146cdbc89be28 (patch)
tree1dc685689de1ba174c7c00eb387362fa0b4ecdb4 /apps/files_versions
parent033b3dac9268276a49d025a9dc1e32614473847a (diff)
downloadnextcloud-server-f8a4cc0284bc7883a4fcc78c327146cdbc89be28.tar.gz
nextcloud-server-f8a4cc0284bc7883a4fcc78c327146cdbc89be28.zip
Added unit tests for versions storing
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/tests/versions.php90
1 files changed, 86 insertions, 4 deletions
diff --git a/apps/files_versions/tests/versions.php b/apps/files_versions/tests/versions.php
index 2d3e2b66e06..97afcf715cb 100644
--- a/apps/files_versions/tests/versions.php
+++ b/apps/files_versions/tests/versions.php
@@ -45,10 +45,6 @@ class Test_Files_Versioning extends \Test\TestCase {
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
- // clear share hooks
- \OC_Hook::clear('OCP\\Share');
- \OC::registerShareHooks();
- \OCA\Files_Versions\Hooks::connectHooks();
$application = new \OCA\Files_Sharing\AppInfo\Application();
$application->registerMountProviders();
$application->setupPropagation();
@@ -69,6 +65,11 @@ class Test_Files_Versioning extends \Test\TestCase {
protected function setUp() {
parent::setUp();
+ // clear hooks
+ \OC_Hook::clear();
+ \OC::registerShareHooks();
+ \OCA\Files_Versions\Hooks::connectHooks();
+
self::loginHelper(self::TEST_VERSIONS_USER);
$this->rootView = new \OC\Files\View();
if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) {
@@ -82,6 +83,8 @@ class Test_Files_Versioning extends \Test\TestCase {
$this->rootView->deleteAll(self::TEST_VERSIONS_USER . '/files_versions/');
$this->rootView->deleteAll(self::TEST_VERSIONS_USER2 . '/files_versions/');
+ \OC_Hook::clear();
+
parent::tearDown();
}
@@ -648,6 +651,85 @@ class Test_Files_Versioning extends \Test\TestCase {
}
/**
+ * Test whether versions are created when overwriting as owner
+ */
+ public function testStoreVersionAsOwner() {
+ $this->loginAsUser(self::TEST_VERSIONS_USER);
+
+ $this->createAndCheckVersions(
+ \OC\Files\Filesystem::getView(),
+ 'test.txt'
+ );
+ }
+
+ /**
+ * Test whether versions are created when overwriting as share recipient
+ */
+ public function testStoreVersionAsRecipient() {
+ $this->loginAsUser(self::TEST_VERSIONS_USER);
+
+ \OC\Files\Filesystem::mkdir('folder');
+ \OC\Files\Filesystem::file_put_contents('folder/test.txt', 'test file');
+ $fileInfo = \OC\Files\Filesystem::getFileInfo('folder');
+
+ \OCP\Share::shareItem(
+ 'folder',
+ $fileInfo['fileid'],
+ \OCP\Share::SHARE_TYPE_USER,
+ self::TEST_VERSIONS_USER2,
+ \OCP\Constants::PERMISSION_ALL
+ );
+
+ $this->loginAsUser(self::TEST_VERSIONS_USER2);
+
+ $this->createAndCheckVersions(
+ \OC\Files\Filesystem::getView(),
+ 'folder/test.txt'
+ );
+ }
+
+ /**
+ * Test whether versions are created when overwriting anonymously.
+ *
+ * When uploading through a public link or publicwebdav, no user
+ * is logged in. File modification must still be able to find
+ * the owner and create versions.
+ */
+ public function testStoreVersionAsAnonymous() {
+ $this->logout();
+
+ // note: public link upload does this,
+ // needed to make the hooks fire
+ \OC_Util::setupFS(self::TEST_VERSIONS_USER);
+
+ $userView = new \OC\Files\View('/' . self::TEST_VERSIONS_USER . '/files');
+ $this->createAndCheckVersions(
+ $userView,
+ 'test.txt'
+ );
+ }
+
+ private function createAndCheckVersions($view, $path) {
+ $view->file_put_contents($path, 'test file');
+ $view->file_put_contents($path, 'version 1');
+ $view->file_put_contents($path, 'version 2');
+
+ $this->loginAsUser(self::TEST_VERSIONS_USER);
+
+ // need to scan for the versions
+ list($rootStorage,) = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions');
+ $rootStorage->getScanner()->scan('files_versions');
+
+ $versions = \OCA\Files_Versions\Storage::getVersions(
+ self::TEST_VERSIONS_USER, '/' . $path
+ );
+
+ // note: we cannot predict how many versions are created due to
+ // test run timing
+ $this->assertGreaterThan(0, count($versions));
+ }
+
+ /**
* @param string $user
* @param bool $create
* @param bool $password