public function test_set_post_date()
 {
     $r = self::factory()->response->create();
     $response = new \WeBWorK\Server\Response($r);
     $new_date = '2015-05-05 05:05:05';
     $response->set_post_date($new_date);
     $this->assertTrue($response->save());
     $response2 = new \WeBWorK\Server\Response($r);
     $this->assertSame($new_date, $response2->get_post_date());
 }
 public function create_object($args)
 {
     $args['post_type'] = 'webwork_response';
     $post_id = parent::create_object($args);
     if (!$post_id || is_wp_error($post_id)) {
         return $post_id;
     }
     $response = new \WeBWorK\Server\Response($post_id);
     $is_answer = isset($args['is_answer']) ? (bool) $args['is_answer'] : false;
     $response->set_is_answer($is_answer);
     $question_id = isset($args['question_id']) ? (int) $args['question_id'] : false;
     if ($question_id) {
         $response->set_question_id($question_id);
     }
     if (isset($args['post_date'])) {
         $response->set_post_date($args['post_date']);
     }
     $response->save();
     return $post_id;
 }
 public function update_item($request)
 {
     $retval = false;
     $params = $request->get_params();
     if (isset($params['id']) && isset($params['is_answer'])) {
         $response = new \WeBWorK\Server\Response($params['id']);
         if ($response->exists()) {
             $response->set_is_answer($params['is_answer']);
             $response->save();
             $q = new \WeBWork\Server\Question\Query(array('question_id' => $response->get_question_id()));
             $retval = $q->get_for_endpoint();
         }
     }
     $response = rest_ensure_response($retval);
     if ($retval) {
         $response->set_status(200);
     } else {
         $response->set_status(500);
     }
     return $response;
 }
 public function update_item($request)
 {
     $retval = false;
     $params = $request->get_params();
     if (isset($params['id']) && isset($params['is_answer'])) {
         $response = new \WeBWorK\Server\Response($params['id']);
         if ($response->exists()) {
             $response->set_is_answer($params['is_answer']);
             $retval = $response->save();
         }
     }
     $response = rest_ensure_response($retval);
     if ($retval) {
         $response->set_status(200);
     } else {
         $response->set_status(500);
     }
     return $response;
 }
 public function test_get_has_answer_cache_should_be_busted_after_response_save()
 {
     $q = self::factory()->question->create_and_get();
     $r = new \WeBWorK\Server\Response();
     $r->set_question_id($q->get_id());
     $r->save();
     $this->assertFalse($q->get_has_answer());
     $r->set_is_answer(true);
     $r->save();
     $this->assertTrue($q->get_has_answer());
 }