]> BookStack Code Mirror - bookstack/blob - tests/Entity/CommentTest.php
Updated test files to be PSR-4 compliant
[bookstack] / tests / Entity / CommentTest.php
1 <?php namespace Tests\Entity;
2
3 use BookStack\Entities\Page;
4 use BookStack\Actions\Comment;
5 use Tests\TestCase;
6
7 class CommentTest extends TestCase
8 {
9
10     public function test_add_comment()
11     {
12         $this->asAdmin();
13         $page = Page::first();
14
15         $comment = factory(Comment::class)->make(['parent_id' => 2]);
16         $resp = $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
17
18         $resp->assertStatus(200);
19         $resp->assertSee($comment->text);
20
21         $pageResp = $this->get($page->getUrl());
22         $pageResp->assertSee($comment->text);
23
24         $this->assertDatabaseHas('comments', [
25             'local_id' => 1,
26             'entity_id' => $page->id,
27             'entity_type' => Page::newModelInstance()->getMorphClass(),
28             'text' => $comment->text,
29             'parent_id' => 2
30         ]);
31     }
32
33     public function test_comment_edit()
34     {
35         $this->asAdmin();
36         $page = Page::first();
37
38         $comment = factory(Comment::class)->make();
39         $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
40
41         $comment = $page->comments()->first();
42         $newText = 'updated text content';
43         $resp = $this->putJson("/ajax/comment/$comment->id", [
44             'text' => $newText,
45             'html' => '<p>'.$newText.'</p>',
46         ]);
47
48         $resp->assertStatus(200);
49         $resp->assertSee($newText);
50         $resp->assertDontSee($comment->text);
51
52         $this->assertDatabaseHas('comments', [
53             'text' => $newText,
54             'entity_id' => $page->id
55         ]);
56     }
57
58     public function test_comment_delete()
59     {
60         $this->asAdmin();
61         $page = Page::first();
62
63         $comment = factory(Comment::class)->make();
64         $this->postJson("/ajax/page/$page->id/comment", $comment->getAttributes());
65
66         $comment = $page->comments()->first();
67
68         $resp = $this->delete("/ajax/comment/$comment->id");
69         $resp->assertStatus(200);
70
71         $this->assertDatabaseMissing('comments', [
72             'id' => $comment->id
73         ]);
74     }
75 }