Example #1
0
 public function testIndexFail()
 {
     PostRepository::shouldReceive('find')->once()->with(1, ['id']);
     $content = $this->call('GET', 'blog/posts/1/comments', [], [], [], ['HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest'])->getContent();
     $this->assertResponseStatus(404);
     $this->assertEquals('{"success":false,"code":404,"msg":"The post you were viewing has been deleted.","url":"http:\\/\\/localhost\\/blog\\/posts"}', $content);
 }
Example #2
0
 /**
  * Display a listing of the comments.
  *
  * @param int $postId
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function index($postId)
 {
     $post = PostRepository::find($postId, ['id']);
     if (!$post) {
         Session::flash('error', 'The post you were viewing has been deleted.');
         return Response::json(['success' => false, 'code' => 404, 'msg' => 'The post you were viewing has been deleted.', 'url' => URL::route('blog.posts.index')], 404);
     }
     $comments = $post->comments()->get(['id', 'version']);
     $data = [];
     foreach ($comments as $comment) {
         $data[] = ['comment_id' => $comment->id, 'comment_ver' => $comment->version];
     }
     return Response::json(array_reverse($data));
 }
Example #3
0
 /**
  * Delete an existing post.
  *
  * @param int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $post = PostRepository::find($id);
     $this->checkPost($post);
     $post->delete();
     return Redirect::route('blog.posts.index')->with('success', 'Your post has been deleted successfully.');
 }
Example #4
0
 public function testIndexFail()
 {
     PostRepository::shouldReceive('find')->once()->with(1, ['id']);
     $this->get('blog/posts/1/comments');
     $this->assertEquals(404, $this->response->status());
 }