function EntityUrlTest::testToUrlLinkTemplateRevision

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

Class

EntityUrlTest
Tests URL handling of the \Drupal\Core\Entity\Entity 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 always ask for the 'revision'
    // link template, to test that it falls back to the 'canonical' link
    // template in case of the default revision.
    
    /** @var \Drupal\Core\Url $url */
    $url = $entity->toUrl('revision');
    $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.