summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/SystemTag/SystemTagManagerTest.php82
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