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. 8.9.x 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 169

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) : void {
    $values = [
        'id' => static::ENTITY_ID,
        'langcode' => $this->langcode,
    ];
    $entity = $this->getEntity(UrlTestEntity::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' => static::ENTITY_ID,
    ], $entity, TRUE, $url);
}

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