public function RestfulExceptionHandleTestCase::testExceptionHandle in RESTful 7.2
Same name and namespace in other branches
- 7 tests/RestfulExceptionHandleTestCase.test \RestfulExceptionHandleTestCase::testExceptionHandle()
Test converting exceptions into JSON with code, message and description.
When calling the API via hook_menu(), exceptions should be converted to a valid JSON.
File
- tests/
RestfulExceptionHandleTestCase.test, line 37 - Contains RestfulExceptionHandleTestCase.
Class
- RestfulExceptionHandleTestCase
- Class RestfulExceptionHandleTestCase.
Code
public function testExceptionHandle() {
$options = array(
'sort' => 'wrong_key',
);
$result = $this
->httpRequest('api/v1.0/articles', \Drupal\restful\Http\RequestInterface::METHOD_GET, $options);
$expected_result = array(
'type' => 'http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.1',
'title' => 'The sort wrong_key is not allowed for this path.',
'status' => 400,
'detail' => 'Bad Request',
);
$this
->assertEqual(drupal_json_decode($result['body']), $expected_result);
$this
->assertEqual($result['code'], 400, 'Correct HTTP code.');
}