You are here

public function EntityUrlTest::testToUrlLinkTemplateNoId in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateNoId()

Tests the toUrl() method with link templates without an entity ID.

@dataProvider providerTestToUrlLinkTemplateNoId

@covers ::toUrl @covers ::linkTemplates @covers ::urlRouteParameters

Parameters

string $link_template: The link template to test.

string $expected_route_name: The expected route name of the generated URL.

File

core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php, line 222

Class

EntityUrlTest
Tests URL handling of the \Drupal\Core\Entity\EntityBase class.

Namespace

Drupal\Tests\Core\Entity

Code

public function testToUrlLinkTemplateNoId($link_template, $expected_route_name) {
  $entity = $this
    ->getEntity(EntityBase::class, [
    'id' => $this->entityId,
  ]);
  $this
    ->registerLinkTemplate($link_template);

  /** @var \Drupal\Core\Url $url */
  $url = $entity
    ->toUrl($link_template);
  $this
    ->assertUrl($expected_route_name, [], $entity, FALSE, $url);
}