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

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLuka Trovic <luka@nextcloud.com>2022-10-03 15:39:51 +0300
committerJonas <jonas@nextcloud.com>2022-10-11 10:19:38 +0300
commit6b43389357a2f45517a27fcd4ec6d06d96594073 (patch)
tree1995bcd18e0ee239dcadc9d8b77ad75e150c7b0c /tests
parent20718bc23a886182c7bae1e79d1fd01a92ff251d (diff)
fix: feedback
Signed-off-by: Luka Trovic <luka@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/Controller/UserApiControllerTest.php115
1 files changed, 115 insertions, 0 deletions
diff --git a/tests/unit/Controller/UserApiControllerTest.php b/tests/unit/Controller/UserApiControllerTest.php
new file mode 100644
index 000000000..3ef2fa32f
--- /dev/null
+++ b/tests/unit/Controller/UserApiControllerTest.php
@@ -0,0 +1,115 @@
+<?php
+
+namespace OCA\Text\Controller;
+
+use OCA\Text\Service\SessionService;
+use OCP\Collaboration\Collaborators\ISearch;
+use OCP\AppFramework\Http\DataResponse;
+use \OCP\IRequest;
+use OCP\IUserManager;
+use OCP\IUserSession;
+use OCA\Text\Db\Session;
+use Test\TestCase;
+
+class UserApiControllerTest extends TestCase {
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ private $collaboratorSearch;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ private $userSession;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ private $userManager;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject
+ */
+ private $sessionService;
+ /**
+ * @var UserApiController
+ */
+ private $userApiController;
+ /**
+ * @var IRequest|\PHPUnit\Framework\MockObject\MockObject
+ */
+ private $request;
+
+ protected function setUp(): void {
+ parent::setUp();
+ $this->request = $this->createMock(IRequest::class);
+ $this->collaboratorSearch = $this->createMock(ISearch::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->userManager = $this->createMock(IUserManager::class);
+ $this->sessionService = $this->createMock(SessionService::class);
+ $this->userApiController = new UserApiController(
+ 'text',
+ $this->request,
+ $this->sessionService,
+ $this->collaboratorSearch,
+ $this->userManager,
+ $this->userSession
+ );
+ }
+
+ /**
+ * @dataProvider dataTestUsersIndex
+ */
+ public function testUsersIndex(int $documentId, int $sessionId, string $sessionToken, string $filter)
+ {
+ $session = new Session();
+ $session->setUserId('admin');
+ $this->sessionService
+ ->expects($this->once())
+ ->method('isValidSession')->willReturn(true);
+ $this->sessionService
+ ->expects($this->once())
+ ->method('getAllSessions')->willReturn([[
+ 'userId' => 'admin',
+ 'displayName' => 'admin',
+ ]]);
+ $this->sessionService
+ ->expects($this->once())
+ ->method('getSession')->willReturn($session);
+ $this->collaboratorSearch
+ ->expects($this->once())
+ ->method('search')->willReturn([
+ [
+ 'exact' => [
+ 'users' => []
+ ],
+ 'users' => [
+ [
+ 'label' => 'admin',
+ 'subline' => '',
+ 'icon' => 'icon-user',
+ 'value' => [
+ 'shareType' => 0,
+ 'shareWith' => 'admin'
+ ],
+ 'shareWithDisplayNameUnique' => 'admin',
+ 'status' => []
+ ],
+ ]
+ ]
+ ]);
+
+ $users = $this->userApiController->index(
+ $documentId,
+ $sessionId,
+ $sessionToken,
+ $filter
+ );
+ $this->assertInstanceOf(DataResponse::class, $users);
+ }
+
+ public function dataTestUsersIndex() {
+ return [
+ [103, 44, 'token1', 'admin'],
+ [103, 44, 'token2', 'admin'],
+ [103, 44, 'token3', 'admin'],
+ ];
+ }
+}