Esempio n. 1
0
 /**
  * @depends testFormatJson
  */
 public function testSet_error_message()
 {
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, 'detaillage');
     $this->assertErrorMessage($api_result, 400, API_V1_result::ERROR_BAD_REQUEST, API_V1_exception_badrequest::get_details(), 'detaillage');
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(API_V1_result::ERROR_UNAUTHORIZED, 'detaillage');
     $this->assertErrorMessage($api_result, 401, API_V1_result::ERROR_UNAUTHORIZED, API_V1_exception_unauthorized::get_details(), 'detaillage');
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(API_V1_result::ERROR_FORBIDDEN, 'detaillage');
     $this->assertErrorMessage($api_result, 403, API_V1_result::ERROR_FORBIDDEN, API_V1_exception_forbidden::get_details(), 'detaillage');
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(API_V1_result::ERROR_NOTFOUND, 'detaillage');
     $this->assertErrorMessage($api_result, 404, API_V1_result::ERROR_NOTFOUND, API_V1_exception_notfound::get_details(), 'detaillage');
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(API_V1_result::ERROR_METHODNOTALLOWED, 'detaillage');
     $this->assertErrorMessage($api_result, 405, API_V1_result::ERROR_METHODNOTALLOWED, API_V1_exception_methodnotallowed::get_details(), 'detaillage');
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(API_V1_result::ERROR_INTERNALSERVERERROR, 'detaillage');
     $this->assertErrorMessage($api_result, 500, API_V1_result::ERROR_INTERNALSERVERERROR, API_V1_exception_internalservererror::get_details(), 'detaillage');
     $api_result = new API_V1_result(self::$DI['app'], new Request(), $this->api);
     $api_result->set_error_message(OAUTH2_ERROR_INVALID_REQUEST, 'detaillage');
     $this->assertErrorMessage($api_result, 200, OAUTH2_ERROR_INVALID_REQUEST, NULL, 'detaillage');
 }
Esempio n. 2
0
 /**
  * Return detailed informations about one story
  *
  * @param  Request       $request
  * @param  int           $databox_id
  * @param  int           $story_id
  * @return API_V1_result
  */
 public function get_story(Request $request, $databox_id, $story_id)
 {
     $result = new API_V1_result($this->app, $request, $this);
     $databox = $this->app['phraseanet.appbox']->get_databox($databox_id);
     try {
         $story = $databox->get_record($story_id);
         $result->set_datas(['story' => $this->list_story($story)]);
     } catch (NotFoundHttpException $e) {
         $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, $this->app->trans('Story Not Found'));
     } catch (\Exception $e) {
         $result->set_error_message(API_V1_result::ERROR_BAD_REQUEST, $this->app->trans('An error occured'));
     }
     return $result;
 }