You are here

public function EntityUrlTest::testToUrlLinkTemplateRevision 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::testToUrlLinkTemplateRevision()
  2. 9 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 172

Class

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

Namespace

Drupal\Tests\Core\Entity

Code

public function testToUrlLinkTemplateRevision($is_default_revision, $link_template, $expected_route_name, array $expected_route_parameters) {
  $values = [
    'id' => $this->entityId,
    'langcode' => $this->langcode,
  ];
  $entity = $this
    ->getEntity(RevisionableEntity::class, $values);
  $entity
    ->method('getRevisionId')
    ->willReturn($this->revisionId);
  $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);
}