You are here

public function EntityUrlTest::testToUrlLinkTemplates in Drupal 10

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

Tests the toUrl() method with simple link templates.

@dataProvider providerTestToUrlLinkTemplates

@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 124

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

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

  /** @var \Drupal\Core\Url $url */
  $url = $entity
    ->toUrl($link_template);

  // The entity ID is the sole route parameter for the link templates tested
  // here.
  $this
    ->assertUrl($expected_route_name, [
    'test_entity' => $this->entityId,
  ], $entity, TRUE, $url);
}