You are here

public function ControllerResolverTest::testGetArguments in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/http-kernel/Tests/Controller/ControllerResolverTest.php \Symfony\Component\HttpKernel\Tests\Controller\ControllerResolverTest::testGetArguments()
  2. 8 core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php \Drupal\Tests\Core\Controller\ControllerResolverTest::testGetArguments()
Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php \Drupal\Tests\Core\Controller\ControllerResolverTest::testGetArguments()

Tests getArguments().

Ensure that doGetArguments uses converted arguments if available.

See also

\Drupal\Core\Controller\ControllerResolver::getArguments()

\Drupal\Core\Controller\ControllerResolver::doGetArguments()

File

core/tests/Drupal/Tests/Core/Controller/ControllerResolverTest.php, line 73
Contains \Drupal\Tests\Core\Controller\ControllerResolverTest.

Class

ControllerResolverTest
@coversDefaultClass \Drupal\Core\Controller\ControllerResolver @group Controller

Namespace

Drupal\Tests\Core\Controller

Code

public function testGetArguments() {
  $controller = function (EntityInterface $entity, $user, RouteMatchInterface $route_match, ServerRequestInterface $psr_7) {
  };
  $mock_entity = $this
    ->getMockBuilder('Drupal\\Core\\Entity\\Entity')
    ->disableOriginalConstructor()
    ->getMock();
  $mock_account = $this
    ->getMock('Drupal\\Core\\Session\\AccountInterface');
  $request = new Request(array(), array(), array(
    'entity' => $mock_entity,
    'user' => $mock_account,
    '_raw_variables' => new ParameterBag(array(
      'entity' => 1,
      'user' => 1,
    )),
  ), array(), array(), array(
    'HTTP_HOST' => 'drupal.org',
  ));
  $arguments = $this->controllerResolver
    ->getArguments($request, $controller);
  $this
    ->assertEquals($mock_entity, $arguments[0]);
  $this
    ->assertEquals($mock_account, $arguments[1]);
  $this
    ->assertEquals(RouteMatch::createFromRequest($request), $arguments[2], 'Ensure that the route match object is passed along as well');
  $this
    ->assertInstanceOf(ServerRequestInterface::class, $arguments[3], 'Ensure that the PSR-7 object is passed along as well');
}