+ public function test_empty_state_actions_not_visible_without_permission()
+ {
+ $admin = $this->getAdmin();
+ // Book links
+ $book = factory(Book::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id]);
+ $this->regenEntityPermissions($book);
+ $this->actingAs($this->getViewer())->get($book->getUrl())
+ ->assertDontSee('Create a new page')
+ ->assertDontSee('Add a chapter');
+
+ // Chapter links
+ $chapter = factory(Chapter::class)->create(['created_by' => $admin->id, 'updated_by' => $admin->id, 'book_id' => $book->id]);
+ $this->regenEntityPermissions($chapter);
+ $this->actingAs($this->getViewer())->get($chapter->getUrl())
+ ->assertDontSee('Create a new page')
+ ->assertDontSee('Sort the current book');
+ }
+
+ public function test_comment_create_permission()
+ {
+ $ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
+
+ $this->actingAs($this->user)
+ ->addComment($ownPage)
+ ->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['comment-create-all']);
+
+ $this->actingAs($this->user)
+ ->addComment($ownPage)
+ ->assertOk();
+ }
+
+ public function test_comment_update_own_permission()
+ {
+ $ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
+ $this->giveUserPermissions($this->user, ['comment-create-all']);
+ $this->actingAs($this->user)->addComment($ownPage);
+ /** @var Comment $comment */
+ $comment = $ownPage->comments()->latest()->first();
+
+ // no comment-update-own
+ $this->actingAs($this->user)->updateComment($comment)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['comment-update-own']);
+
+ // now has comment-update-own
+ $this->actingAs($this->user)->updateComment($comment)->assertOk();
+ }
+
+ public function test_comment_update_all_permission()
+ {
+ /** @var Page $ownPage */
+ $ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
+ $this->asAdmin()->addComment($ownPage);
+ /** @var Comment $comment */
+ $comment = $ownPage->comments()->latest()->first();
+
+ // no comment-update-all
+ $this->actingAs($this->user)->updateComment($comment)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['comment-update-all']);
+
+ // now has comment-update-all
+ $this->actingAs($this->user)->updateComment($comment)->assertOk();
+ }
+
+ public function test_comment_delete_own_permission()
+ {
+ /** @var Page $ownPage */
+ $ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
+ $this->giveUserPermissions($this->user, ['comment-create-all']);
+ $this->actingAs($this->user)->addComment($ownPage);
+
+ /** @var Comment $comment */
+ $comment = $ownPage->comments()->latest()->first();
+
+ // no comment-delete-own
+ $this->actingAs($this->user)->deleteComment($comment)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['comment-delete-own']);
+
+ // now has comment-update-own
+ $this->actingAs($this->user)->deleteComment($comment)->assertOk();
+ }
+
+ public function test_comment_delete_all_permission()
+ {
+ /** @var Page $ownPage */
+ $ownPage = $this->createEntityChainBelongingToUser($this->user)['page'];
+ $this->asAdmin()->addComment($ownPage);
+ /** @var Comment $comment */
+ $comment = $ownPage->comments()->latest()->first();
+
+ // no comment-delete-all
+ $this->actingAs($this->user)->deleteComment($comment)->assertStatus(403);
+
+ $this->giveUserPermissions($this->user, ['comment-delete-all']);
+
+ // now has comment-delete-all
+ $this->actingAs($this->user)->deleteComment($comment)->assertOk();
+ }
+
+ private function addComment(Page $page): TestResponse
+ {
+ $comment = factory(Comment::class)->make();
+
+ return $this->postJson("/comment/$page->id", $comment->only('text', 'html'));
+ }
+
+ private function updateComment(Comment $comment): TestResponse
+ {
+ $commentData = factory(Comment::class)->make();
+
+ return $this->putJson("/comment/{$comment->id}", $commentData->only('text', 'html'));
+ }
+
+ private function deleteComment(Comment $comment): TestResponse
+ {
+ return $this->json('DELETE', '/comment/' . $comment->id);
+ }