function RevisionVersionHistoryTest::testDescriptionLinkWithAccess

Same name in other branches
  1. 10 core/tests/Drupal/FunctionalTests/Entity/RevisionVersionHistoryTest.php \Drupal\FunctionalTests\Entity\RevisionVersionHistoryTest::testDescriptionLinkWithAccess()

Test revision link, with access to revision page.

Test two revisions. Usually the latest revision only checks canonical route access, whereas all others will check individual revision access.

@covers ::getRevisionDescription

File

core/tests/Drupal/FunctionalTests/Entity/RevisionVersionHistoryTest.php, line 192

Class

RevisionVersionHistoryTest
Tests version history page.

Namespace

Drupal\FunctionalTests\Entity

Code

public function testDescriptionLinkWithAccess() : void {
    
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create([
        'type' => 'entity_test_revlog',
    ]);
    // Revision has access to individual revision.
    $entity->setName('view all revisions, view revision');
    $entity->save();
    $firstRevisionId = $entity->getRevisionId();
    // Revision has access to canonical route.
    $entity->setName('view all revisions, view');
    $entity->setNewRevision();
    $entity->save();
    $this->drupalGet($entity->toUrl('version-history'));
    $row1Link = $this->assertSession()
        ->elementExists('css', 'table tbody tr:nth-child(1) a');
    $this->assertEquals($entity->toUrl()
        ->toString(), $row1Link->getAttribute('href'));
    // Reload revision so object has the properties to build a revision link.
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
    $storage = \Drupal::entityTypeManager()->getStorage('entity_test_revlog');
    $firstRevision = $storage->loadRevision($firstRevisionId);
    $row2Link = $this->assertSession()
        ->elementExists('css', 'table tbody tr:nth-child(2) a');
    $this->assertEquals($firstRevision->toUrl('revision')
        ->toString(), $row2Link->getAttribute('href'));
}

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