6 class CommentTest extends TestCase
9 public function test_add_comment()
12 $page = Page::first();
14 $comment = factory(Comment::class)->make(['parent_id' => 2]);
15 $resp = $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
17 $resp->assertStatus(200);
18 $resp->assertSee($comment->text);
20 $pageResp = $this->get($page->getUrl());
21 $pageResp->assertSee($comment->text);
23 $this->assertDatabaseHas('comments', [
25 'entity_id' => $page->id,
26 'entity_type' => 'BookStack\\Page',
27 'text' => $comment->text,
32 public function test_comment_edit()
35 $page = Page::first();
37 $comment = factory(Comment::class)->make();
38 $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
40 $comment = $page->comments()->first();
41 $newText = 'updated text content';
42 $resp = $this->putJson("/ajax/comment/$comment->id", [
44 'html' => '<p>'.$newText.'</p>',
47 $resp->assertStatus(200);
48 $resp->assertSee($newText);
49 $resp->assertDontSee($comment->text);
51 $this->assertDatabaseHas('comments', [
53 'entity_id' => $page->id
57 public function test_comment_delete()
60 $page = Page::first();
62 $comment = factory(Comment::class)->make();
63 $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
65 $comment = $page->comments()->first();
67 $resp = $this->delete("/ajax/comment/$comment->id");
68 $resp->assertStatus(200);
70 $this->assertDatabaseMissing('comments', [