Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and rullzer committed Dec 11, 2019
1 parent ba390f6 commit 48cd26a
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions apps/files_versions/tests/VersioningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

use OC\Files\Storage\Temporary;
use OCP\IConfig;
use OCP\IUser;
use OCP\Share\IShare;

/**
* Class Test_Files_versions
Expand All @@ -54,6 +56,8 @@ class VersioningTest extends \Test\TestCase {
* @var \OC\Files\View
*/
private $rootView;
private $user1;
private $user2;

public static function setUpBeforeClass() {
parent::setUpBeforeClass();
Expand Down Expand Up @@ -102,6 +106,13 @@ protected function setUp() {
if (!$this->rootView->file_exists(self::USERS_VERSIONS_ROOT)) {
$this->rootView->mkdir(self::USERS_VERSIONS_ROOT);
}

$this->user1 = $this->createMock(IUser::class);
$this->user1->method('getUID')
->willReturn(self::TEST_VERSIONS_USER);
$this->user2 = $this->createMock(IUser::class);
$this->user2->method('getUID')
->willReturn(self::TEST_VERSIONS_USER2);
}

protected function tearDown() {
Expand Down Expand Up @@ -130,7 +141,7 @@ public function testGetExpireList($versions, $sizeOfAllDeletedFiles) {
$startTime = 5000000;

$testClass = new VersionStorageToTest();
list($deleted, $size) = $testClass->callProtectedGetExpireList($startTime, $versions);
[$deleted, $size] = $testClass->callProtectedGetExpireList($startTime, $versions);

// we should have deleted 16 files each of the size 1
$this->assertEquals($sizeOfAllDeletedFiles, $size);
Expand Down Expand Up @@ -665,14 +676,55 @@ public function testRestoreNoPermission() {

$firstVersion = current($versions);

$this->assertFalse(\OCA\Files_Versions\Storage::rollback('folder/test.txt', $firstVersion['version']), 'Revert did not happen');
$this->assertFalse(\OCA\Files_Versions\Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user2), 'Revert did not happen');

$this->loginAsUser(self::TEST_VERSIONS_USER);

\OC::$server->getShareManager()->deleteShare($share);
$this->assertEquals('test file', $file->getContent(), 'File content has not changed');
}

public function testRestoreMovedShare() {
$this->loginAsUser(self::TEST_VERSIONS_USER);

$userHome = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER);
$node = $userHome->newFolder('folder');
$file = $node->newFile('test.txt');

$userHome2 = \OC::$server->getUserFolder(self::TEST_VERSIONS_USER2);
$userHome2->newFolder('subfolder');

$share = \OC::$server->getShareManager()->newShare();
$share->setNode($node)
->setShareType(\OCP\Share::SHARE_TYPE_USER)
->setSharedBy(self::TEST_VERSIONS_USER)
->setSharedWith(self::TEST_VERSIONS_USER2)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = \OC::$server->getShareManager()->createShare($share);
$shareManager = \OC::$server->getShareManager();

$share->setTarget("subfolder/folder");
$shareManager->moveShare($share, self::TEST_VERSIONS_USER2);

$versions = $this->createAndCheckVersions(
\OC\Files\Filesystem::getView(),
'folder/test.txt'
);

$file->putContent('test file');

$this->loginAsUser(self::TEST_VERSIONS_USER2);

$firstVersion = current($versions);

$this->assertTrue(\OCA\Files_Versions\Storage::rollback('folder/test.txt', $firstVersion['version'], $this->user1));

$this->loginAsUser(self::TEST_VERSIONS_USER);

\OC::$server->getShareManager()->deleteShare($share);
$this->assertEquals('version 2', $file->getContent(), 'File content has not changed');
}

/**
* @param string $hookName name of hook called
* @param string $params variable to receive parameters provided by hook
Expand Down Expand Up @@ -733,7 +785,7 @@ private function doTestRestore() {
$params = array();
$this->connectMockHooks('rollback', $params);

$this->assertTrue(\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2));
$this->assertTrue(\OCA\Files_Versions\Storage::rollback('sub/test.txt', $t2, $this->user1));
$expectedParams = array(
'path' => '/sub/test.txt',
);
Expand Down Expand Up @@ -867,7 +919,7 @@ private function createAndCheckVersions(\OC\Files\View $view, $path) {
$this->loginAsUser(self::TEST_VERSIONS_USER);

// need to scan for the versions
list($rootStorage,) = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions');
[$rootStorage,] = $this->rootView->resolvePath(self::TEST_VERSIONS_USER . '/files_versions');
$rootStorage->getScanner()->scan('files_versions');

$versions = \OCA\Files_Versions\Storage::getVersions(
Expand Down

0 comments on commit 48cd26a

Please sign in to comment.