1 <?php namespace Tests\Entity;
3 use BookStack\Entities\Page;
4 use BookStack\Actions\Comment;
7 class CommentTest extends TestCase
10 public function test_add_comment()
13 $page = Page::first();
15 $comment = factory(Comment::class)->make(['parent_id' => 2]);
16 $resp = $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
18 $resp->assertStatus(200);
19 $resp->assertSee($comment->text);
21 $pageResp = $this->get($page->getUrl());
22 $pageResp->assertSee($comment->text);
24 $this->assertDatabaseHas('comments', [
26 'entity_id' => $page->id,
27 'entity_type' => Page::newModelInstance()->getMorphClass(),
28 'text' => $comment->text,
33 public function test_comment_edit()
36 $page = Page::first();
38 $comment = factory(Comment::class)->make();
39 $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
41 $comment = $page->comments()->first();
42 $newText = 'updated text content';
43 $resp = $this->putJson("/ajax/comment/$comment->id", [
45 'html' => '<p>'.$newText.'</p>',
48 $resp->assertStatus(200);
49 $resp->assertSee($newText);
50 $resp->assertDontSee($comment->text);
52 $this->assertDatabaseHas('comments', [
54 'entity_id' => $page->id
58 public function test_comment_delete()
61 $page = Page::first();
63 $comment = factory(Comment::class)->make();
64 $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
66 $comment = $page->comments()->first();
68 $resp = $this->delete("/ajax/comment/$comment->id");
69 $resp->assertStatus(200);
71 $this->assertDatabaseMissing('comments', [