diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-04-27 12:47:04 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-05-20 17:56:02 +0200 |
commit | 8343cfb64b8297035987bc4980ec72015c8e1a04 (patch) | |
tree | 812f44ba113313e7537779bcce4c04cf736e4cad /tests | |
parent | 59a85a4c76b80658d9373e3acf4f71b872b244a0 (diff) | |
download | nextcloud-server-8343cfb64b8297035987bc4980ec72015c8e1a04.tar.gz nextcloud-server-8343cfb64b8297035987bc4980ec72015c8e1a04.zip |
Add interface methods for permission check
Instead of checking for admin perm, use interface method
canUserAssignTag and canUserSeeTag to check for permissions.
Allows for more flexible implementation.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/SystemTag/SystemTagManagerTest.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/lib/SystemTag/SystemTagManagerTest.php b/tests/lib/SystemTag/SystemTagManagerTest.php index 1afb147f08a..9bd4622c2be 100644 --- a/tests/lib/SystemTag/SystemTagManagerTest.php +++ b/tests/lib/SystemTag/SystemTagManagerTest.php @@ -17,6 +17,8 @@ use OCP\SystemTag\ISystemTag; use OCP\SystemTag\ISystemTagManager; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; +use OCP\IUserManager; +use OCP\IGroupManager; /** * Class TestSystemTagManager @@ -37,6 +39,16 @@ class SystemTagManagerTest extends TestCase { private $connection; /** + * @var IGroupManager + */ + private $groupManager; + + /** + * @var IUserManager + */ + private $userManager; + + /** * @var EventDispatcherInterface */ private $dispatcher; @@ -49,8 +61,16 @@ class SystemTagManagerTest extends TestCase { $this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface') ->getMock(); + $this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock(); + $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager')->getMock(); + $this->groupManager->expects($this->any()) + ->method('isAdmin') + ->will($this->returnValue(false)); + $this->tagManager = new SystemTagManager( $this->connection, + $this->userManager, + $this->groupManager, $this->dispatcher ); $this->pruneTagsTables(); @@ -410,6 +430,68 @@ class SystemTagManagerTest extends TestCase { ], $tagIdMapping); } + public function visibilityCheckProvider() { + return [ + [false, false, false, false], + [true, false, false, true], + [false, false, true, true], + [true, false, true, true], + ]; + } + + /** + * @dataProvider visibilityCheckProvider + */ + public function testVisibilityCheck($userVisible, $userAssignable, $isAdmin, $expectedResult) { + $userId = 'test'; + $tag1 = $this->tagManager->createTag('one', $userVisible, $userAssignable); + + $this->userManager->expects($this->once()) + ->method('get') + ->with($userId) + ->will($this->returnValue([])); + $this->groupManager->expects($this->once()) + ->method('isAdmin') + ->with($userId) + ->will($this->returnValue($isAdmin)); + + $this->assertEquals($expectedResult, $this->tagManager->canUserSeeTag($tag1, $userID)); + $this->assertEquals($expectedResult, $this->tagManager->canUserSeeTag($tag1->getId(), $userID)); + } + + public function assignabilityCheckProvider() { + return [ + [false, false, false, false], + [true, false, false, false], + [true, true, false, true], + [false, true, false, false], + [false, false, true, true], + [false, true, true, true], + [true, false, true, true], + [true, true, true, true], + ]; + } + + /** + * @dataProvider assignabilityCheckProvider + */ + public function testVisibilityCheck($userVisible, $userAssignable, $isAdmin, $expectedResult) { + $userId = 'test'; + $tag1 = $this->tagManager->createTag('one', $userVisible, $userAssignable); + + $this->userManager->expects($this->once()) + ->method('get') + ->with($userId) + ->will($this->returnValue([])); + $this->groupManager->expects($this->once()) + ->method('isAdmin') + ->with($userId) + ->will($this->returnValue($isAdmin)); + + $this->assertEquals($expectedResult, $this->tagManager->canUserAssignTag($tag1, $userID)); + $this->assertEquals($expectedResult, $this->tagManager->canUserAssignTag($tag1->getId(), $userID)); + } + /** * @param ISystemTag $tag1 * @param ISystemTag $tag2 |