Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Leuker <j.leuker@hosting.de>2021-04-15 19:02:39 +0300
committerJohannes Leuker <j.leuker@hosting.de>2021-05-25 12:29:32 +0300
commitd606799ee2b3a6e11e616cd5606901754aa70c93 (patch)
tree5dd771f5f6991a7296b0e8dc60d2745ed0a7549f /tests/Core
parentf031dd61c14a093effeb5773323f578abd65d54f (diff)
Add commands to manage tags via OCC
list, add, delete, edit Signed-off-by: Johannes Leuker <j.leuker@hosting.de>
Diffstat (limited to 'tests/Core')
-rw-r--r--tests/Core/Command/SystemTag/AddTest.php138
-rw-r--r--tests/Core/Command/SystemTag/DeleteTest.php100
-rw-r--r--tests/Core/Command/SystemTag/EditTest.php201
-rw-r--r--tests/Core/Command/SystemTag/ListCommandTest.php113
4 files changed, 552 insertions, 0 deletions
diff --git a/tests/Core/Command/SystemTag/AddTest.php b/tests/Core/Command/SystemTag/AddTest.php
new file mode 100644
index 00000000000..c875c8f3ec3
--- /dev/null
+++ b/tests/Core/Command/SystemTag/AddTest.php
@@ -0,0 +1,138 @@
+<?php
+/**
+ * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de>
+ *
+ * @author Johannes Leuker <developers@hosting.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Core\Command\SystemTag;
+
+use OC\Core\Command\SystemTag\Add;
+use OCP\SystemTag\ISystemTag;
+use OCP\SystemTag\ISystemTagManager;
+use OCP\SystemTag\TagAlreadyExistsException;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+class AddTest extends TestCase {
+
+ /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */
+ private $systemTagManager;
+
+ /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */
+ private $command;
+
+ /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $input;
+
+ /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $output;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->systemTagManager = $this->createMock(ISystemTagManager::class);
+ $this->command = $this->getMockBuilder(Add::class)
+ ->setConstructorArgs([$this->systemTagManager])
+ ->setMethods(['writeArrayInOutputFormat'])
+ ->getMock();
+
+ $this->input = $this->createMock(InputInterface::class);
+ $this->output = $this->createMock(OutputInterface::class);
+ }
+
+ public function testExecute() {
+ $tagId = '42';
+ $tagName = 'wichtig';
+ $tagAccess = 'public';
+
+ $tag = $this->createMock(ISystemTag::class);
+ $tag->method('getId')->willReturn($tagId);
+ $tag->method('getName')->willReturn($tagName);
+ $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC);
+
+ $this->systemTagManager->method('createTag')
+ ->with(
+ $tagName,
+ true,
+ true
+ )->willReturn($tag);
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) {
+ if ($arg === 'name') {
+ return $tagName;
+ } elseif ($arg === 'access') {
+ return $tagAccess;
+ }
+ throw new \Exception();
+ });
+
+ $this->command->expects($this->once())
+ ->method('writeArrayInOutputFormat')
+ ->with(
+ $this->equalTo($this->input),
+ $this->equalTo($this->output),
+ [
+ 'id' => $tagId,
+ 'name' => $tagName,
+ 'access' => $tagAccess,
+ ]
+ );
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+
+ public function testAlreadyExists() {
+ $tagId = '42';
+ $tagName = 'wichtig';
+ $tagAccess = 'public';
+
+ $tag = $this->createMock(ISystemTag::class);
+ $tag->method('getId')->willReturn($tagId);
+ $tag->method('getName')->willReturn($tagName);
+ $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC);
+
+ $this->systemTagManager->method('createTag')
+ ->willReturnCallback(function ($tagName, $userVisible, $userAssignable) {
+ throw new TagAlreadyExistsException(
+ 'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists'
+ );
+ });
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagName, $tagAccess) {
+ if ($arg === 'name') {
+ return $tagName;
+ } elseif ($arg === 'access') {
+ return $tagAccess;
+ }
+ throw new \Exception();
+ });
+
+ $this->output->expects($this->once())
+ ->method('writeln')
+ ->with(
+ '<error>Tag ("wichtig", 1, 1) already exists</error>'
+ );
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+}
diff --git a/tests/Core/Command/SystemTag/DeleteTest.php b/tests/Core/Command/SystemTag/DeleteTest.php
new file mode 100644
index 00000000000..138606049ee
--- /dev/null
+++ b/tests/Core/Command/SystemTag/DeleteTest.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de>
+ *
+ * @author Johannes Leuker <developers@hosting.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Core\Command\SystemTag;
+
+use OC\Core\Command\SystemTag\Delete;
+use OCP\SystemTag\ISystemTagManager;
+use OCP\SystemTag\TagNotFoundException;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+class DeleteTest extends TestCase {
+
+ /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */
+ private $systemTagManager;
+
+ /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */
+ private $command;
+
+ /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $input;
+
+ /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $output;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->systemTagManager = $this->createMock(ISystemTagManager::class);
+ $this->command = $this->getMockBuilder(Delete::class)
+ ->setConstructorArgs([$this->systemTagManager])
+ ->setMethods(['writeArrayInOutputFormat'])
+ ->getMock();
+
+ $this->input = $this->createMock(InputInterface::class);
+ $this->output = $this->createMock(OutputInterface::class);
+ }
+
+ public function testExecute() {
+ $tagId = 69;
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagId) {
+ if ($arg === 'id') {
+ return $tagId;
+ }
+ throw new \Exception();
+ });
+
+ $this->output->expects($this->once())
+ ->method('writeln')
+ ->with('<info>The specified tag was deleted</info>');
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+
+ public function testNotFound() {
+ $tagId = 69;
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagId) {
+ if ($arg === 'id') {
+ return $tagId;
+ }
+ throw new \Exception();
+ });
+
+ $this->systemTagManager->method('deleteTags')
+ ->willReturnCallback(function ($tagId) {
+ throw new TagNotFoundException();
+ });
+
+ $this->output->expects($this->once())
+ ->method('writeln')
+ ->with('<error>Tag not found</error>');
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+}
diff --git a/tests/Core/Command/SystemTag/EditTest.php b/tests/Core/Command/SystemTag/EditTest.php
new file mode 100644
index 00000000000..7794ac5aefd
--- /dev/null
+++ b/tests/Core/Command/SystemTag/EditTest.php
@@ -0,0 +1,201 @@
+<?php
+/**
+ * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de>
+ *
+ * @author Johannes Leuker <developers@hosting.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Core\Command\SystemTag;
+
+use OC\Core\Command\SystemTag\Edit;
+use OCP\SystemTag\ISystemTag;
+use OCP\SystemTag\ISystemTagManager;
+use OCP\SystemTag\TagAlreadyExistsException;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+class EditTest extends TestCase {
+
+ /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */
+ private $systemTagManager;
+
+ /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */
+ private $command;
+
+ /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $input;
+
+ /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $output;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->systemTagManager = $this->createMock(ISystemTagManager::class);
+ $this->command = $this->getMockBuilder(Edit::class)
+ ->setConstructorArgs([$this->systemTagManager])
+ ->setMethods(['writeArrayInOutputFormat'])
+ ->getMock();
+
+ $this->input = $this->createMock(InputInterface::class);
+ $this->output = $this->createMock(OutputInterface::class);
+ }
+
+ public function testExecute() {
+ $tagId = '5';
+ $tagName = 'unwichtige Dateien';
+ $newTagName = 'moderat wichtige Dateien';
+ $newTagAccess = 'restricted';
+ $newTagUserVisible = true;
+ $newTagUserAssignable = false;
+
+ $tag = $this->createMock(ISystemTag::class);
+ $tag->method('getId')->willReturn($tagId);
+ $tag->method('getName')->willReturn($tagName);
+ $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE);
+
+ $this->systemTagManager->method('getTagsByIds')
+ ->with($tagId)
+ ->willReturn([$tag]);
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagId) {
+ if ($arg === 'id') {
+ return $tagId;
+ }
+ throw new \Exception();
+ });
+
+ $this->input->method('getOption')
+ ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) {
+ if ($arg === 'name') {
+ return $newTagName;
+ } elseif ($arg === 'access') {
+ return $newTagAccess;
+ }
+ throw new \Exception();
+ });
+
+ $this->systemTagManager->expects($this->once())
+ ->method('updateTag')
+ ->with(
+ $tagId,
+ $newTagName,
+ $newTagUserVisible,
+ $newTagUserAssignable
+ );
+
+ $this->output->expects($this->once())
+ ->method('writeln')
+ ->with(
+ '<info>Tag updated ("'.$newTagName.'", '.$newTagUserVisible.', '.$newTagUserAssignable.')</info>'
+ );
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+
+ public function testAlreadyExists() {
+ $tagId = '5';
+ $tagName = 'unwichtige Dateien';
+ $tagUserVisible = false;
+ $tagUserAssignable = false;
+ $newTagName = 'moderat wichtige Dateien';
+ $newTagAccess = 'restricted';
+ $newTagUserVisible = true;
+ $newTagUserAssignable = false;
+
+ $tag = $this->createMock(ISystemTag::class);
+ $tag->method('getId')->willReturn($tagId);
+ $tag->method('getName')->willReturn($tagName);
+ $tag->method('isUserVisible')->willReturn($tagUserVisible);
+ $tag->method('isUserAssignable')->willReturn($tagUserAssignable);
+ $tag->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE);
+
+ $this->systemTagManager->method('getTagsByIds')
+ ->with($tagId)
+ ->willReturn([$tag]);
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagId) {
+ if ($arg === 'id') {
+ return $tagId;
+ }
+ throw new \Exception();
+ });
+
+ $this->input->method('getOption')
+ ->willReturnCallback(function ($arg) use ($newTagName, $newTagAccess) {
+ if ($arg === 'name') {
+ return $newTagName;
+ } elseif ($arg === 'access') {
+ return $newTagAccess;
+ }
+ throw new \Exception();
+ });
+
+ $this->systemTagManager->method('updateTag')
+ ->willReturnCallback(function ($tagId, $tagName, $userVisible, $userAssignable) {
+ throw new TagAlreadyExistsException(
+ 'Tag ("' . $tagName . '", '. $userVisible . ', ' . $userAssignable . ') already exists'
+ );
+ });
+
+ $this->systemTagManager->expects($this->once())
+ ->method('updateTag')
+ ->with(
+ $tagId,
+ $newTagName,
+ $newTagUserVisible,
+ $newTagUserAssignable
+ );
+
+ $this->output->expects($this->once())
+ ->method('writeln')
+ ->with(
+ '<error>Tag ("' . $newTagName . '", '. $newTagUserVisible . ', ' . $newTagUserAssignable . ') already exists</error>'
+ );
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+
+ public function testNotFound() {
+ $tagId = '404';
+
+ $this->input->method('getArgument')
+ ->willReturnCallback(function ($arg) use ($tagId) {
+ if ($arg === 'id') {
+ return $tagId;
+ }
+ throw new \Exception();
+ });
+
+ $this->systemTagManager->method('getTagsByIds')
+ ->with($tagId)
+ ->willReturn([]);
+
+ $this->output->expects($this->once())
+ ->method('writeln')
+ ->with(
+ '<error>Tag not found</error>'
+ );
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+}
diff --git a/tests/Core/Command/SystemTag/ListCommandTest.php b/tests/Core/Command/SystemTag/ListCommandTest.php
new file mode 100644
index 00000000000..2e2fba1017f
--- /dev/null
+++ b/tests/Core/Command/SystemTag/ListCommandTest.php
@@ -0,0 +1,113 @@
+<?php
+/**
+ * @copyright Copyright (c) 2021, hosting.de, Johannes Leuker <developers@hosting.de>
+ *
+ * @author Johannes Leuker <developers@hosting.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Test\Core\Command\SystemTag;
+
+use OC\Core\Command\SystemTag\ListCommand;
+use OCP\SystemTag\ISystemTag;
+use OCP\SystemTag\ISystemTagManager;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Test\TestCase;
+
+class ListCommandTest extends TestCase {
+
+ /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */
+ private $systemTagManager;
+
+ /** @var ListCommand|\PHPUnit\Framework\MockObject\MockObject */
+ private $command;
+
+ /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $input;
+
+ /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
+ private $output;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->systemTagManager = $this->createMock(ISystemTagManager::class);
+ $this->command = $this->getMockBuilder(ListCommand::class)
+ ->setConstructorArgs([$this->systemTagManager])
+ ->setMethods(['writeArrayInOutputFormat'])
+ ->getMock();
+
+ $this->input = $this->createMock(InputInterface::class);
+ $this->output = $this->createMock(OutputInterface::class);
+ }
+
+ public function testExecute() {
+ $tag1 = $this->createMock(ISystemTag::class);
+ $tag1->method('getId')->willReturn('1');
+ $tag1->method('getName')->willReturn('public_tag');
+ $tag1->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_PUBLIC);
+ $tag2 = $this->createMock(ISystemTag::class);
+ $tag2->method('getId')->willReturn('2');
+ $tag2->method('getName')->willReturn('restricted_tag');
+ $tag2->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_RESTRICTED);
+ $tag3 = $this->createMock(ISystemTag::class);
+ $tag3->method('getId')->willReturn('3');
+ $tag3->method('getName')->willReturn('invisible_tag');
+ $tag3->method('getAccessLevel')->willReturn(ISystemTag::ACCESS_LEVEL_INVISIBLE);
+
+ $this->systemTagManager->method('getAllTags')
+ ->with(
+ null,
+ null
+ )->willReturn([$tag1, $tag2, $tag3]);
+
+ $this->input->method('getOption')
+ ->willReturnCallback(function ($arg) {
+ if ($arg === 'visibilityFilter') {
+ return null;
+ } elseif ($arg === 'nameSearchPattern') {
+ return null;
+ }
+ throw new \Exception();
+ });
+
+ $this->command->expects($this->once())
+ ->method('writeArrayInOutputFormat')
+ ->with(
+ $this->equalTo($this->input),
+ $this->equalTo($this->output),
+ [
+ '1' => [
+ 'name' => 'public_tag',
+ 'access' => 'public',
+ ],
+ '2' => [
+ 'name' => 'restricted_tag',
+ 'access' => 'restricted',
+ ],
+ '3' => [
+ 'name' => 'invisible_tag',
+ 'access' => 'invisible',
+ ]
+ ]
+ );
+
+ $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
+ }
+}