|
|
|
|
@ -11,9 +11,11 @@ namespace Test\SystemTag;
|
|
|
|
|
use OC\SystemTag\SystemTagManager;
|
|
|
|
|
use OC\SystemTag\SystemTagObjectMapper;
|
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
|
|
|
use OCP\IAppConfig;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
|
use OCP\IUser;
|
|
|
|
|
use OCP\IUserSession;
|
|
|
|
|
use OCP\SystemTag\ISystemTag;
|
|
|
|
|
use OCP\SystemTag\ISystemTagManager;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
@ -25,25 +27,12 @@ use Test\TestCase;
|
|
|
|
|
* @package Test\SystemTag
|
|
|
|
|
*/
|
|
|
|
|
class SystemTagManagerTest extends TestCase {
|
|
|
|
|
/**
|
|
|
|
|
* @var ISystemTagManager
|
|
|
|
|
**/
|
|
|
|
|
private $tagManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var IDBConnection
|
|
|
|
|
*/
|
|
|
|
|
private $connection;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var IGroupManager
|
|
|
|
|
*/
|
|
|
|
|
private $groupManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var IEventDispatcher
|
|
|
|
|
*/
|
|
|
|
|
private $dispatcher;
|
|
|
|
|
private ISystemTagManager $tagManager;
|
|
|
|
|
private IDBConnection $connection;
|
|
|
|
|
private IGroupManager $groupManager;
|
|
|
|
|
private IUserSession $userSession;
|
|
|
|
|
private IAppConfig $appConfig;
|
|
|
|
|
private IEventDispatcher $dispatcher;
|
|
|
|
|
|
|
|
|
|
protected function setUp(): void {
|
|
|
|
|
parent::setUp();
|
|
|
|
|
@ -52,17 +41,22 @@ class SystemTagManagerTest extends TestCase {
|
|
|
|
|
|
|
|
|
|
$this->dispatcher = $this->createMock(IEventDispatcher::class);
|
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
|
$this->appConfig = $this->createMock(IAppConfig::class);
|
|
|
|
|
|
|
|
|
|
$this->tagManager = new SystemTagManager(
|
|
|
|
|
$this->connection,
|
|
|
|
|
$this->groupManager,
|
|
|
|
|
$this->dispatcher
|
|
|
|
|
$this->dispatcher,
|
|
|
|
|
$this->userSession,
|
|
|
|
|
$this->appConfig,
|
|
|
|
|
);
|
|
|
|
|
$this->pruneTagsTables();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function tearDown(): void {
|
|
|
|
|
$this->pruneTagsTables();
|
|
|
|
|
\OC::$CLI = true;
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -535,6 +529,84 @@ class SystemTagManagerTest extends TestCase {
|
|
|
|
|
$this->assertEquals([], $this->tagManager->getTagGroups($tag1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function allowedToCreateProvider(): array {
|
|
|
|
|
return [
|
|
|
|
|
[true, null, true],
|
|
|
|
|
[true, null, false],
|
|
|
|
|
[false, true, true],
|
|
|
|
|
[false, true, false],
|
|
|
|
|
[false, false, false],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider allowedToCreateProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testAllowedToCreateTag(bool $isCli, ?bool $isAdmin, bool $isRestricted): void {
|
|
|
|
|
$oldCli = \OC::$CLI;
|
|
|
|
|
\OC::$CLI = $isCli;
|
|
|
|
|
|
|
|
|
|
$user = $this->getMockBuilder(IUser::class)->getMock();
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUID')
|
|
|
|
|
->willReturn('test');
|
|
|
|
|
$this->userSession->expects($this->any())
|
|
|
|
|
->method('getUser')
|
|
|
|
|
->willReturn($isAdmin === null ? null : $user);
|
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
|
->method('isAdmin')
|
|
|
|
|
->with('test')
|
|
|
|
|
->willReturn($isAdmin);
|
|
|
|
|
$this->appConfig->expects($this->any())
|
|
|
|
|
->method('getValueBool')
|
|
|
|
|
->with('systemtags', 'restrict_creation_to_admin')
|
|
|
|
|
->willReturn($isRestricted);
|
|
|
|
|
|
|
|
|
|
$name = uniqid('tag_', true);
|
|
|
|
|
$tag = $this->tagManager->createTag($name, true, true);
|
|
|
|
|
$this->assertEquals($tag->getName(), $name);
|
|
|
|
|
$this->tagManager->deleteTags($tag->getId());
|
|
|
|
|
|
|
|
|
|
\OC::$CLI = $oldCli;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function disallowedToCreateProvider(): array {
|
|
|
|
|
return [
|
|
|
|
|
[false],
|
|
|
|
|
[null],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider disallowedToCreateProvider
|
|
|
|
|
*/
|
|
|
|
|
public function testDisallowedToCreateTag(?bool $isAdmin): void {
|
|
|
|
|
$oldCli = \OC::$CLI;
|
|
|
|
|
\OC::$CLI = false;
|
|
|
|
|
|
|
|
|
|
$user = $this->getMockBuilder(IUser::class)->getMock();
|
|
|
|
|
$user->expects($this->any())
|
|
|
|
|
->method('getUID')
|
|
|
|
|
->willReturn('test');
|
|
|
|
|
$this->userSession->expects($this->any())
|
|
|
|
|
->method('getUser')
|
|
|
|
|
->willReturn($isAdmin === null ? null : $user);
|
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
|
->method('isAdmin')
|
|
|
|
|
->with('test')
|
|
|
|
|
->willReturn($isAdmin);
|
|
|
|
|
$this->appConfig->expects($this->any())
|
|
|
|
|
->method('getValueBool')
|
|
|
|
|
->with('systemtags', 'restrict_creation_to_admin')
|
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
|
$tag = $this->tagManager->createTag(uniqid('tag_', true), true, true);
|
|
|
|
|
|
|
|
|
|
\OC::$CLI = $oldCli;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ISystemTag $tag1
|
|
|
|
|
* @param ISystemTag $tag2
|
|
|
|
|
|