diff --git a/tests/unit/Service/ApiServiceTest.php b/tests/unit/Service/ApiServiceTest.php index 83a4b848c84..df3ae4e63be 100644 --- a/tests/unit/Service/ApiServiceTest.php +++ b/tests/unit/Service/ApiServiceTest.php @@ -3,6 +3,7 @@ namespace OCA\Text\Tests; use OCA\Text\Db\Document; +use OCA\Text\Db\Session; use OCA\Text\Service\ApiService; use OCA\Text\Service\ConfigService; use OCA\Text\Service\DocumentService; @@ -66,6 +67,29 @@ public function testCreateNewSessionWithoutOwner() { self::assertFalse($actual->getData()['hasOwner']); } + public function testSaveWithNotPermittedException() { + $session = new Session(); + $session->setDocumentId(123); + + $document = new Document(); + + $file = $this->mockFile(123, 'admin'); + + $this->documentService->method('getFileForSession')->willReturn($file); + $this->documentService->method('autosave')->willThrowException(new \OCP\Files\NotPermittedException()); + + $this->l10n->method('t') + ->with('Read-only permission cannot save document changes. Please reload the page.') + ->willReturn('Read-only permission cannot save document changes. Please reload the page.'); + + $response = $this->apiService->save($session, $document, 1, 'content', 'state'); + + self::assertEquals(\OCP\AppFramework\Http::STATUS_FORBIDDEN, $response->getStatus()); + self::assertEquals('Read-only permission cannot save document changes. Please reload the page.', + $response->getData()['error'] + ); + } + private function mockFile(int $id, ?string $owner) { $file = $this->createMock(\OCP\Files\File::class); $storage = $this->createMock(\OCP\Files\Storage\IStorage::class);