class HttpKernelTest

Same name in this branch

Tests the custom http kernel of drupal.

Hierarchy

Expanded class hierarchy of HttpKernelTest

See also

\Drupal\Core\HttpKernel

File

drupal/core/tests/Drupal/Tests/Core/HttpKernelTest.php, line 25
Contains \Drupal\Tests\Core\HttpKernelTest.

Namespace

Drupal\Tests\Core
View source
class HttpKernelTest extends UnitTestCase {
  public static function getInfo() {
    return array(
      'name' => 'HttpKernel (Unit)',
      'description' => 'Tests the HttpKernel.',
      'group' => 'Routing',
    );
  }

  /**
   * Tests the forward method.
   *
   * @see \Drupal\Core\HttpKernel::setupSubrequest()
   */
  public function testSetupSubrequest() {
    $container = new ContainerBuilder();
    $request = new Request();
    $container
      ->addScope(new Scope('request'));
    $container
      ->enterScope('request');
    $container
      ->set('request', $request, 'request');
    $dispatcher = new EventDispatcher();
    $controller_resolver = new ControllerResolver($container);
    $http_kernel = new HttpKernel($dispatcher, $container, $controller_resolver);
    $test_controller = '\\Drupal\\Tests\\Core\\Controller\\TestController';
    $random_attribute = $this
      ->randomName();
    $subrequest = $http_kernel
      ->setupSubrequest($test_controller, array(
      'custom_attribute' => $random_attribute,
    ), array(
      'custom_query' => $random_attribute,
    ));
    $this
      ->assertNotSame($subrequest, $request, 'The subrequest is not the same as the main request.');
    $this
      ->assertEquals($subrequest->attributes
      ->get('custom_attribute'), $random_attribute, 'Attributes are set from the subrequest.');
    $this
      ->assertEquals($subrequest->query
      ->get('custom_query'), $random_attribute, 'Query attributes are set from the subrequest.');
    $this
      ->assertEquals($subrequest->attributes
      ->get('_controller'), $test_controller, 'Controller attribute got set.');
    $subrequest = $http_kernel
      ->setupSubrequest(NULL, array(), array());
    $this
      ->assertFalse($subrequest->attributes
      ->has('_controller'), 'Ensure that _controller is not copied when no controller was set before.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
HttpKernelTest::getInfo public static function This method exists to support the simpletest UI runner. Overrides UnitTestCase::getInfo
HttpKernelTest::testSetupSubrequest public function Tests the forward method.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::randomName public static function Generates a random string containing letters and numbers.