public function HttpKernelTest::testSetupSubrequest

Tests the forward method.

See also

\Drupal\Core\HttpKernel::setupSubrequest()

File

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

Class

HttpKernelTest
Tests the custom http kernel of drupal.

Namespace

Drupal\Tests\Core

Code

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.');
}