Skip to content

Commit

Permalink
Cleanup OC_Group usage a bit
Browse files Browse the repository at this point in the history
This is deprecated internal stuff. Should not be used anymore.

Signed-off-by: Roeland Jago Douma <[email protected]>
  • Loading branch information
rullzer committed Nov 4, 2016
1 parent 27304e5 commit 211ede2
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 91 deletions.
12 changes: 8 additions & 4 deletions apps/files_sharing/tests/ShareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ protected function tearDown() {
}

public function testUnshareFromSelf() {

\OC_Group::createGroup('testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$groupManager = \OC::$server->getGroupManager();
$userManager = \OC::$server->getUserManager();

$testGroup = $groupManager->createGroup('testGroup');
$user1 = $userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user2 = $userManager->get(self::TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);

$share1 = $this->share(
\OCP\Share::SHARE_TYPE_USER,
Expand Down
62 changes: 41 additions & 21 deletions apps/files_sharing/tests/SharedMountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*/

namespace OCA\Files_Sharing\Tests;
use OCP\IGroupManager;
use OCP\IUserManager;

/**
* Class SharedMountTest
Expand All @@ -35,6 +37,12 @@
*/
class SharedMountTest extends TestCase {

/** @var IGroupManager */
private $groupManager;

/** @var IUserManager */
private $userManager;

protected function setUp() {
parent::setUp();

Expand All @@ -48,6 +56,9 @@ protected function setUp() {
// save file with content
$this->view->file_put_contents($this->filename, "root file");
$this->view->file_put_contents($this->folder . $this->filename, "file in subfolder");

$this->groupManager = \OC::$server->getGroupManager();
$this->userManager = \OC::$server->getUserManager();
}

protected function tearDown() {
Expand Down Expand Up @@ -172,10 +183,13 @@ public function testMoveSharedFile() {
* for the other users
*/
public function testMoveGroupShare () {
\OC_Group::createGroup('testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);
$testGroup->addUser($user3);

$fileinfo = $this->view->getFileInfo($this->filename);
$share = $this->share(
Expand Down Expand Up @@ -206,9 +220,9 @@ public function testMoveGroupShare () {
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$testGroup->removeUser($user1);
$testGroup->removeUser($user2);
$testGroup->removeUser($user3);
}

/**
Expand Down Expand Up @@ -317,10 +331,13 @@ function testPermissionMovedGroupShare($type, $beforePerm, $afterPerm) {
$path = $this->folder;
}

\OC_Group::createGroup('testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);
$testGroup->addUser($user3);

// Share item with group
$share = $this->share(
Expand Down Expand Up @@ -362,20 +379,23 @@ function testPermissionMovedGroupShare($type, $beforePerm, $afterPerm) {
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$testGroup->removeUser($user1);
$testGroup->removeUser($user2);
$testGroup->removeUser($user3);
}

/**
* If the permissions on a group share are upgraded be sure to still respect
* removed shares by a member of that group
*/
function testPermissionUpgradeOnUserDeletedGroupShare() {
\OC_Group::createGroup('testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::addToGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);
$testGroup->addUser($user3);

$connection = \OC::$server->getDatabaseConnection();

Expand Down Expand Up @@ -419,9 +439,9 @@ function testPermissionUpgradeOnUserDeletedGroupShare() {

//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER1, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER2, 'testGroup');
\OC_Group::removeFromGroup(self::TEST_FILES_SHARING_API_USER3, 'testGroup');
$testGroup->removeUser($user1);
$testGroup->removeUser($user2);
$testGroup->removeUser($user3);
}

}
Expand Down
Loading

0 comments on commit 211ede2

Please sign in to comment.