2014-01-21 15:10:24 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-01-21 15:10:24 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-01-21 15:10:24 +04:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
require_once __DIR__ . '/../appinfo/app.php';
|
2014-01-21 15:10:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Test_Files_versions
|
2014-05-19 19:50:53 +04:00
|
|
|
* this class provide basic files versions test
|
2014-01-21 15:10:24 +04:00
|
|
|
*/
|
2014-11-11 00:28:12 +03:00
|
|
|
class Test_Files_Versioning extends \Test\TestCase {
|
2014-01-21 15:10:24 +04:00
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
const TEST_VERSIONS_USER = 'test-versions-user';
|
2014-10-28 17:57:08 +03:00
|
|
|
const TEST_VERSIONS_USER2 = 'test-versions-user2';
|
2014-07-24 18:49:38 +04:00
|
|
|
const USERS_VERSIONS_ROOT = '/test-versions-user/files_versions';
|
|
|
|
|
2014-10-30 19:20:40 +03:00
|
|
|
/**
|
|
|
|
* @var \OC\Files\View
|
|
|
|
*/
|
2014-07-24 18:49:38 +04:00
|
|
|
private $rootView;
|
|
|
|
|
|
|
|
public static function setUpBeforeClass() {
|
2014-11-07 17:23:15 +03:00
|
|
|
parent::setUpBeforeClass();
|
2014-10-28 17:57:08 +03:00
|
|
|
|
|
|
|
// clear share hooks
|
|
|
|
\OC_Hook::clear('OCP\\Share');
|
|
|
|
\OC::registerShareHooks();
|
|
|
|
\OCA\Files_Versions\Hooks::connectHooks();
|
2015-03-27 15:44:40 +03:00
|
|
|
$application = new \OCA\Files_Sharing\AppInfo\Application();
|
|
|
|
$application->registerMountProviders();
|
|
|
|
$application->setupPropagation();
|
2014-10-28 17:57:08 +03:00
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
// create test user
|
2014-10-28 17:57:08 +03:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2, true);
|
2014-07-24 18:49:38 +04:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function tearDownAfterClass() {
|
|
|
|
// cleanup test user
|
|
|
|
\OC_User::deleteUser(self::TEST_VERSIONS_USER);
|
2014-10-28 17:57:08 +03:00
|
|
|
\OC_User::deleteUser(self::TEST_VERSIONS_USER2);
|
2014-11-07 17:23:15 +03:00
|
|
|
|
|
|
|
parent::tearDownAfterClass();
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
protected function tearDown() {
|
2014-07-24 18:49:38 +04:00
|
|
|
$this->rootView->deleteAll(self::USERS_VERSIONS_ROOT);
|
2014-11-07 17:23:15 +03:00
|
|
|
|
|
|
|
parent::tearDown();
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
2014-01-21 15:10:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
2014-05-19 19:50:53 +04:00
|
|
|
* test expire logic
|
2014-01-21 15:10:24 +04:00
|
|
|
* @dataProvider versionsProvider
|
|
|
|
*/
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testGetExpireList($versions, $sizeOfAllDeletedFiles) {
|
2014-01-21 15:10:24 +04:00
|
|
|
|
2014-10-30 19:20:40 +03:00
|
|
|
// last interval end at 2592000
|
2014-01-21 15:10:24 +04:00
|
|
|
$startTime = 5000000;
|
|
|
|
|
|
|
|
$testClass = new VersionStorageToTest();
|
2014-01-22 14:13:15 +04:00
|
|
|
list($deleted, $size) = $testClass->callProtectedGetExpireList($startTime, $versions);
|
2014-01-21 15:10:24 +04:00
|
|
|
|
|
|
|
// we should have deleted 16 files each of the size 1
|
|
|
|
$this->assertEquals($sizeOfAllDeletedFiles, $size);
|
|
|
|
|
|
|
|
// the deleted array should only contain versions which should be deleted
|
|
|
|
foreach($deleted as $key => $path) {
|
|
|
|
unset($versions[$key]);
|
|
|
|
$this->assertEquals("delete", substr($path, 0, strlen("delete")));
|
|
|
|
}
|
|
|
|
|
|
|
|
// the versions array should only contain versions which should be kept
|
|
|
|
foreach ($versions as $version) {
|
|
|
|
$this->assertEquals("keep", $version['path']);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function versionsProvider() {
|
|
|
|
return array(
|
|
|
|
// first set of versions uniformly distributed versions
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
// first slice (10sec) keep one version every 2 seconds
|
|
|
|
array("version" => 4999999, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999998, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4999997, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999995, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999994, "path" => "delete", "size" => 1),
|
|
|
|
//next slice (60sec) starts at 4999990 keep one version every 10 secons
|
|
|
|
array("version" => 4999988, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999978, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999975, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4999972, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4999967, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999958, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4999957, "path" => "keep", "size" => 1),
|
|
|
|
//next slice (3600sec) start at 4999940 keep one version every 60 seconds
|
|
|
|
array("version" => 4999900, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999841, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4999840, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999780, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4996401, "path" => "keep", "size" => 1),
|
|
|
|
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
|
|
|
|
array("version" => 4996350, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4992800, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4989800, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4989700, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4989200, "path" => "keep", "size" => 1),
|
|
|
|
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
|
|
|
|
array("version" => 4913600, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4852800, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4827201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4827200, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4777201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4777501, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4740000, "path" => "keep", "size" => 1),
|
|
|
|
// final slice starts at 2408000 keep one version every 604800 secons
|
|
|
|
array("version" => 2408000, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 1803201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1803200, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 1800199, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1800100, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1198300, "path" => "keep", "size" => 1),
|
|
|
|
),
|
|
|
|
16 // size of all deleted files (every file has the size 1)
|
|
|
|
),
|
|
|
|
// second set of versions, here we have only really old versions
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
// first slice (10sec) keep one version every 2 seconds
|
|
|
|
// next slice (60sec) starts at 4999990 keep one version every 10 secons
|
|
|
|
// next slice (3600sec) start at 4999940 keep one version every 60 seconds
|
|
|
|
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
|
|
|
|
array("version" => 4996400, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4996350, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4996350, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4992800, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4989800, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4989700, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4989200, "path" => "keep", "size" => 1),
|
|
|
|
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
|
|
|
|
array("version" => 4913600, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4852800, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4827201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4827200, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4777201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4777501, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4740000, "path" => "keep", "size" => 1),
|
|
|
|
// final slice starts at 2408000 keep one version every 604800 secons
|
|
|
|
array("version" => 2408000, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 1803201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1803200, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 1800199, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1800100, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1198300, "path" => "keep", "size" => 1),
|
|
|
|
),
|
|
|
|
11 // size of all deleted files (every file has the size 1)
|
|
|
|
),
|
|
|
|
// third set of versions, with some gaps inbetween
|
|
|
|
array(
|
|
|
|
array(
|
|
|
|
// first slice (10sec) keep one version every 2 seconds
|
|
|
|
array("version" => 4999999, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999998, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4999997, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999995, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999994, "path" => "delete", "size" => 1),
|
|
|
|
//next slice (60sec) starts at 4999990 keep one version every 10 secons
|
|
|
|
array("version" => 4999988, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4999978, "path" => "keep", "size" => 1),
|
|
|
|
//next slice (3600sec) start at 4999940 keep one version every 60 seconds
|
|
|
|
// next slice (86400sec) start at 4996400 keep one version every 3600 seconds
|
|
|
|
array("version" => 4989200, "path" => "keep", "size" => 1),
|
|
|
|
// next slice (2592000sec) start at 4913600 keep one version every 86400 seconds
|
|
|
|
array("version" => 4913600, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4852800, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4827201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4827200, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 4777201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4777501, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 4740000, "path" => "keep", "size" => 1),
|
|
|
|
// final slice starts at 2408000 keep one version every 604800 secons
|
|
|
|
array("version" => 2408000, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 1803201, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1803200, "path" => "keep", "size" => 1),
|
|
|
|
array("version" => 1800199, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1800100, "path" => "delete", "size" => 1),
|
|
|
|
array("version" => 1198300, "path" => "keep", "size" => 1),
|
|
|
|
),
|
|
|
|
9 // size of all deleted files (every file has the size 1)
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testRename() {
|
2014-07-24 18:49:38 +04:00
|
|
|
|
|
|
|
\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
|
2014-10-28 17:57:08 +03:00
|
|
|
\OC\Files\Filesystem::rename("test.txt", "test2.txt");
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testRenameInSharedFolder() {
|
2014-10-28 17:57:08 +03:00
|
|
|
|
|
|
|
\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');
|
|
|
|
|
2014-11-25 18:28:41 +03:00
|
|
|
\OCP\Share::shareItem('folder', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
|
2014-10-28 17:57:08 +03:00
|
|
|
|
|
|
|
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');
|
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
|
2014-10-28 17:57:08 +03:00
|
|
|
self::loginHelper(self::TEST_VERSIONS_USER2);
|
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2014-10-28 17:57:08 +03:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testRenameSharedFile() {
|
2014-10-31 18:42:54 +03:00
|
|
|
|
|
|
|
\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');
|
|
|
|
|
2014-11-25 18:28:41 +03:00
|
|
|
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_VERSIONS_USER2, \OCP\Constants::PERMISSION_ALL);
|
2014-10-31 18:42:54 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2014-10-31 18:42:54 +03:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2014-11-07 17:23:15 +03:00
|
|
|
public function testCopy() {
|
2014-07-24 18:49:38 +04:00
|
|
|
|
|
|
|
\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
|
2014-10-28 17:57:08 +03:00
|
|
|
\OC\Files\Filesystem::copy("test.txt", "test2.txt");
|
2014-07-24 18:49:38 +04:00
|
|
|
|
2015-03-24 12:19:54 +03:00
|
|
|
$this->runCommands();
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
$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');
|
|
|
|
}
|
|
|
|
|
2014-08-05 19:26:23 +04:00
|
|
|
/**
|
|
|
|
* test if we find all versions and if the versions array contain
|
|
|
|
* the correct 'path' and 'name'
|
|
|
|
*/
|
|
|
|
public function testGetVersions() {
|
|
|
|
|
|
|
|
$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 . '/subfolder/test.txt.v' . $t1;
|
|
|
|
$v2 = self::USERS_VERSIONS_ROOT . '/subfolder/test.txt.v' . $t2;
|
|
|
|
|
|
|
|
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT . '/subfolder/');
|
|
|
|
|
|
|
|
$this->rootView->file_put_contents($v1, 'version1');
|
|
|
|
$this->rootView->file_put_contents($v2, 'version2');
|
|
|
|
|
|
|
|
// execute copy hook of versions app
|
|
|
|
$versions = \OCA\Files_Versions\Storage::getVersions(self::TEST_VERSIONS_USER, '/subfolder/test.txt');
|
|
|
|
|
|
|
|
$this->assertSame(2, count($versions));
|
|
|
|
|
|
|
|
foreach ($versions as $version) {
|
|
|
|
$this->assertSame('/subfolder/test.txt', $version['path']);
|
|
|
|
$this->assertSame('test.txt', $version['name']);
|
|
|
|
}
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
$this->rootView->deleteAll(self::USERS_VERSIONS_ROOT . '/subfolder');
|
|
|
|
}
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
/**
|
|
|
|
* @param string $user
|
|
|
|
* @param bool $create
|
|
|
|
* @param bool $password
|
|
|
|
*/
|
|
|
|
public static function loginHelper($user, $create = false) {
|
|
|
|
|
|
|
|
if ($create) {
|
2015-03-24 12:19:54 +03:00
|
|
|
$backend = new \OC_User_Dummy();
|
|
|
|
$backend->createUser($user, $user);
|
|
|
|
\OC::$server->getUserManager()->registerBackend($backend);
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2015-04-02 17:53:38 +03:00
|
|
|
$storage = new \ReflectionClass('\OC\Files\Storage\Shared');
|
|
|
|
$isInitialized = $storage->getProperty('isInitialized');
|
|
|
|
$isInitialized->setAccessible(true);
|
|
|
|
$isInitialized->setValue(array());
|
|
|
|
$isInitialized->setAccessible(false);
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
\OC_Util::tearDownFS();
|
|
|
|
\OC_User::setUserId('');
|
|
|
|
\OC\Files\Filesystem::tearDown();
|
|
|
|
\OC_User::setUserId($user);
|
|
|
|
\OC_Util::setupFS($user);
|
|
|
|
}
|
|
|
|
|
2014-01-21 15:10:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// extend the original class to make it possible to test protected methods
|
|
|
|
class VersionStorageToTest extends \OCA\Files_Versions\Storage {
|
|
|
|
|
2014-02-06 19:30:58 +04:00
|
|
|
/**
|
|
|
|
* @param integer $time
|
|
|
|
*/
|
2014-01-21 15:10:24 +04:00
|
|
|
public function callProtectedGetExpireList($time, $versions) {
|
|
|
|
return self::getExpireList($time, $versions);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|