|
2 | 2 |
|
3 | 3 | namespace OCA\Text\Tests; |
4 | 4 |
|
| 5 | +use OCA\Text\Db\Session; |
5 | 6 | use OCA\Text\Db\Document; |
6 | 7 | use OCA\Text\Service\ApiService; |
7 | 8 | use OCA\Text\Service\ConfigService; |
@@ -66,6 +67,29 @@ public function testCreateNewSessionWithoutOwner() { |
66 | 67 | self::assertFalse($actual->getData()['hasOwner']); |
67 | 68 | } |
68 | 69 |
|
| 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 | + |
69 | 93 | private function mockFile(int $id, ?string $owner) { |
70 | 94 | $file = $this->createMock(\OCP\Files\File::class); |
71 | 95 | $storage = $this->createMock(\OCP\Files\Storage\IStorage::class); |
|
0 commit comments