function EntityUrlTest::testToUrlLinkTemplateRevision
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateRevision()
- 8.9.x core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateRevision()
- 11.x core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php \Drupal\Tests\Core\Entity\EntityUrlTest::testToUrlLinkTemplateRevision()
Tests the toUrl() method with the 'revision' link template.
@dataProvider providerTestToUrlLinkTemplateRevision
@covers ::toUrl @covers ::linkTemplates @covers ::urlRouteParameters
Parameters
bool $is_default_revision: Whether or not the mock entity should be the default revision.
string $link_template: The link template to test.
string $expected_route_name: The expected route name of the generated URL.
array $expected_route_parameters: The expected route parameters of the generated URL.
File
-
core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityUrlTest.php, line 217
Class
- EntityUrlTest
- Tests URL handling of the \Drupal\Core\Entity\EntityBase class.
Namespace
Drupal\Tests\Core\EntityCode
public function testToUrlLinkTemplateRevision(bool $is_default_revision, string $link_template, string $expected_route_name, array $expected_route_parameters) : void {
$values = [
'id' => static::ENTITY_ID,
'langcode' => $this->langcode,
];
$entity = $this->getEntity(RevisionableEntity::class, $values);
$entity->method('getRevisionId')
->willReturn(static::REVISION_ID);
$entity->method('isDefaultRevision')
->willReturn($is_default_revision);
$this->registerLinkTemplate($link_template);
// Even though this is tested with both the 'canonical' and the 'revision'
// template registered with the entity, we ask for the 'revision' link
// template instead of 'canonical', to test that it falls back to the
// 'canonical' link template in case of the default revision.
$link_template = $link_template === 'canonical' ? 'revision' : $link_template;
/** @var \Drupal\Core\Url $url */
$url = $entity->toUrl($link_template);
$this->assertUrl($expected_route_name, $expected_route_parameters, $entity, TRUE, $url);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.