public function UpcastingTest::testUpcasting

Confirms that all parameters are converted as expected.

All of these requests end up being proccessed by a controller with this the signature: f($user, $node, $foo) returning either values or labels like "user: Dries, node: First post, foo: bar"

The tests shuffle the parameters around an checks if the right thing is happening.

File

drupal/core/modules/system/lib/Drupal/system/Tests/ParamConverter/UpcastingTest.php, line 43
Contains Drupal\system\Tests\ParamConverter\UpcastingTest.

Class

UpcastingTest
Web tests for the upcasting.

Namespace

Drupal\system\Tests\ParamConverter

Code

public function testUpcasting() {
  $node = $this
    ->drupalCreateNode(array(
    'title' => $this
      ->randomName(8),
  ));
  $user = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $foo = 'bar';

  // paramconverter_test/test_user_node_foo/{user}/{node}/{foo}
  $this
    ->drupalGet("paramconverter_test/test_user_node_foo/{$user->uid}/{$node->nid}/{$foo}");
  $this
    ->assertRaw("user: {$user->label()}, node: {$node->label()}, foo: {$foo}", 'user and node upcast by entity name');

  // paramconverter_test/test_node_user_user/{node}/{foo}/{user}
  // converters:
  //   foo: 'user'
  $this
    ->drupalGet("paramconverter_test/test_node_user_user/{$node->nid}/{$user->uid}/{$user->uid}");
  $this
    ->assertRaw("user: {$user->label()}, node: {$node->label()}, foo: {$user->label()}", 'foo converted to user as well');

  // paramconverter_test/test_node_node_foo/{user}/{node}/{foo}
  // converters:
  //   user: 'node'
  $this
    ->drupalGet("paramconverter_test/test_node_node_foo/{$node->nid}/{$node->nid}/{$foo}");
  $this
    ->assertRaw("user: {$node->label()}, node: {$node->label()}, foo: {$foo}", 'user is upcast to node (rather than to user)');
}