You are here

function RestfulExceptionHandleTestCase::testExceptionHandle in RESTful 7

Same name and namespace in other branches
  1. 7.2 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 28
Contains RestfulExceptionHandleTestCase

Class

RestfulExceptionHandleTestCase
@file Contains RestfulExceptionHandleTestCase

Code

function testExceptionHandle() {
  $options['query'] = array(
    'sort' => 'wrong_key',
  );
  $this
    ->drupalGet('api/v1.0/articles', $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
    ->assertText(drupal_json_encode($expected_result), 'Exception was converted to JSON.');
  $this
    ->assertResponse('400', 'Correct HTTP code.');
}