コード例 #1
0
 /**
  * @test
  * it should return 200 response if comment consolidation succeeds
  */
 public function it_should_return_200_response_if_comment_consolidation_succeeds()
 {
     $this->auth_handler->verify_auth(Argument::any(), Argument::any())->willReturn(true);
     $this->comments_repository->consolidate_votes_for_post(Argument::any())->willReturn(true);
     $sut = $this->make_instance();
     /** @var \WP_REST_Response $out */
     $request = new \WP_REST_Request();
     $request->set_param('post_id', 123);
     $out = $sut->handle($request);
     $this->assertEquals(200, $out->status);
     $this->assertEquals(true, $out->data);
 }
コード例 #2
0
 /**
  * Handles a request.
  *
  * @return bool `true` if the request was successfully handled, `false` otherwise.
  */
 public function handle(WP_REST_Request $request)
 {
     $headers = array();
     if (!$this->auth_handler->verify_auth($request, 'consolidate-all')) {
         return new WP_REST_Response('Invalid auth', 403, $headers);
     }
     $post_id = $request->get_param('post_id');
     if (empty($post_id)) {
         return new WP_REST_Response('Missing post ID', 400, $headers);
     }
     $exit = $this->comments_repository->consolidate_votes_for_post($post_id);
     $status = empty($exit) ? 400 : 200;
     return new WP_REST_Response($exit, $status, $headers);
 }