You are here

public function RestfulHookMenuTestCase::testNotFoundDelivery in RESTful 7.2

Same name and namespace in other branches
  1. 7 tests/RestfulHookMenuTestCase.test \RestfulHookMenuTestCase::testNotFoundDelivery()

Test hijacking of api/* pages and showing proper error messages.

File

tests/RestfulHookMenuTestCase.test, line 111
Contains \RestfulHookMenuTestCase.

Class

RestfulHookMenuTestCase

Code

public function testNotFoundDelivery() {

  // Invalid URLs.
  $urls = array(
    'api/invalid',
  );
  foreach ($urls as $url) {
    $result = $this
      ->httpRequest($url);
    $body = drupal_json_decode($result['body']);
    $this
      ->assertEqual($result['code'], '404', format_string('404 status code sent for @url url.', array(
      '@url' => $url,
    )));
    $this
      ->assertTrue(strpos($result['headers'], 'application/problem+json;') !== FALSE, '"application/problem+json" found in invalid request.');
    $this
      ->assertEqual($body['title'], 'Invalid URL path.', 'Correct error message.');
  }

  // Non-related url.
  $result = $this
    ->httpRequest('api-api');
  $this
    ->assertEqual($result['code'], '404', format_string('404 status code sent for @url url.', array(
    '@url' => $url,
  )));
  $this
    ->assertFalse(strpos($result['headers'], 'application/problem+json;'), 'Only correct URL is hijacked.');
}