6 class CommentTest extends BrowserKitTest
9 public function test_add_comment()
12 $page = $this->getPage();
14 $this->addComment($page);
17 public function test_comment_reply()
20 $page = $this->getPage();
22 // add a normal comment
23 $createdComment = $this->addComment($page);
25 // reply to the added comment
26 $this->addComment($page, $createdComment['id']);
29 public function test_comment_edit()
32 $page = $this->getPage();
34 $createdComment = $this->addComment($page);
36 'id' => $createdComment['id'],
37 'page_id' => $createdComment['page_id']
39 $this->updateComment($comment);
42 public function test_comment_delete()
45 $page = $this->getPage();
47 $createdComment = $this->addComment($page);
49 $this->deleteComment($createdComment['id']);
52 private function getPage() {
53 $page = Page::first();
58 private function addComment($page, $parentCommentId = null) {
59 $comment = factory(Comment::class)->make();
60 $url = "/ajax/page/$page->id/comment/";
62 'text' => $comment->text,
63 'html' => $comment->html
65 if (!empty($parentCommentId)) {
66 $request['parent_id'] = $parentCommentId;
68 $this->call('POST', $url, $request);
70 $createdComment = $this->checkResponse();
71 return $createdComment;
74 private function updateComment($comment) {
75 $tmpComment = factory(Comment::class)->make();
76 $url = '/ajax/page/' . $comment['page_id'] . '/comment/ ' . $comment['id'];
78 'text' => $tmpComment->text,
79 'html' => $tmpComment->html
82 $this->call('PUT', $url, $request);
84 $updatedComment = $this->checkResponse();
85 return $updatedComment;
88 private function deleteComment($commentId) {
89 // Route::delete('/ajax/comment/{id}', 'CommentController@destroy');
90 $url = '/ajax/comment/' . $commentId;
91 $this->call('DELETE', $url);
93 $deletedComment = $this->checkResponse();
94 return $deletedComment;
97 private function checkResponse() {
102 $this->assertResponseOk();
103 $this->seeJsonContains($expectedResp);
105 $resp = $this->decodeResponseJson();
106 $createdComment = $resp['comment'];
107 $this->assertArrayHasKey('id', $createdComment);
109 return $createdComment;