ExceptionControllerTest.php 1.32 KB
Newer Older
1 2 3
<?php

/**
4 5
 * @file
 * Contains \Drupal\Tests\Core\Controller\ExceptionControllerTest
6 7
 */

8
namespace Drupal\Tests\Core\Controller;
9

10 11 12 13 14
use Drupal\Core\ContentNegotiation;
use Drupal\Core\Controller\ExceptionController;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\FlattenException;
15 16 17

/**
 * Tests exception controller.
18 19 20 21
 *
 * @see \Drupal\Core\Controller\ExceptionController
 *
 * @group Drupal
22
 */
23
class ExceptionControllerTest extends UnitTestCase {
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

  public static function getInfo() {
    return array(
      'name' => 'Exception controller',
      'description' => 'Performs tests on the exception handler controller class.',
      'group' => 'System',
    );
  }

  /**
   * Ensure the execute() method returns a valid response on 405 exceptions.
   */
  public function test405HTML() {
    $exception = new \Exception('Test exception');
    $flat_exception = FlattenException::create($exception, 405);
    $exception_controller = new ExceptionController(new ContentNegotiation());
    $response = $exception_controller->execute($flat_exception, new Request());
41 42
    $this->assertEquals($response->getStatusCode(), 405, 'HTTP status of response is correct.');
    $this->assertEquals($response->getContent(), 'Method Not Allowed', 'HTTP response body is correct.');
43
  }
44

45
}