Skip to content

Commit d2df64d

Browse files
silverkszlobackportbot[bot]
authored andcommitted
test(ApiService): test save with NotPermittedException
Signed-off-by: silver <s.szmajduch@posteo.de>
1 parent e01e990 commit d2df64d

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/unit/Service/ApiServiceTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OCA\Text\Tests;
44

5+
use OCA\Text\Db\Session;
56
use OCA\Text\Db\Document;
67
use OCA\Text\Service\ApiService;
78
use OCA\Text\Service\ConfigService;
@@ -66,6 +67,29 @@ public function testCreateNewSessionWithoutOwner() {
6667
self::assertFalse($actual->getData()['hasOwner']);
6768
}
6869

70+
public function testSaveWithNotPermittedException() {
71+
$session = new Session();
72+
$session->setDocumentId(123);
73+
74+
$document = new Document();
75+
76+
$file = $this->mockFile(123, 'admin');
77+
78+
$this->documentService->method('getFileForSession')->willReturn($file);
79+
$this->documentService->method('autosave')->willThrowException(new \OCP\Files\NotPermittedException());
80+
81+
$this->l10n->method('t')
82+
->with('Read-only permission cannot save document changes. Please reload the page.')
83+
->willReturn('Read-only permission cannot save document changes. Please reload the page.');
84+
85+
$response = $this->apiService->save($session, $document, 1, 'content', 'state');
86+
87+
self::assertEquals(\OCP\AppFramework\Http::STATUS_FORBIDDEN, $response->getStatus());
88+
self::assertEquals('Read-only permission cannot save document changes. Please reload the page.',
89+
$response->getData()['error']
90+
);
91+
}
92+
6993
private function mockFile(int $id, ?string $owner) {
7094
$file = $this->createMock(\OCP\Files\File::class);
7195
$storage = $this->createMock(\OCP\Files\Storage\IStorage::class);

0 commit comments

Comments
 (0)