function EntityUrlTest::testToUrlLinkTemplates

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplates()
  2. 10 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplates()
  3. 11.x 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 125

Class

EntityUrlTest
Tests URL handling of the \Drupal\Core\Entity\Entity 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);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.