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