function RevisionVersionHistoryTest::testOperationRevertRevision

Same name in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/Entity/RevisionVersionHistoryTest.php \Drupal\FunctionalTests\Entity\RevisionVersionHistoryTest::testOperationRevertRevision()

Test revert operation.

@covers ::buildRevertRevisionLink

File

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

Class

RevisionVersionHistoryTest
Tests version history page.

Namespace

Drupal\FunctionalTests\Entity

Code

public function testOperationRevertRevision() : void {
    
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create([
        'type' => 'entity_test_revlog',
    ]);
    $entity->setName('view all revisions');
    $entity->save();
    $entity->setName('view all revisions, revert');
    $entity->setNewRevision();
    $entity->save();
    $entity->setName('view all revisions, revert');
    $entity->setNewRevision();
    $entity->save();
    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()
        ->elementsCount('css', 'table tbody tr', 3);
    // Latest revision does not have revert revision operation: reverting latest
    // revision is not permitted.
    $row1 = $this->assertSession()
        ->elementExists('css', 'table tbody tr:nth-child(1)');
    $this->assertSession()
        ->elementTextContains('css', 'table tbody tr:nth-child(1)', 'Current revision');
    $this->assertSession()
        ->elementNotExists('named', [
        'link',
        'Revert',
    ], $row1);
    // Revision 2 has revert revision operation: granted access.
    $row2 = $this->assertSession()
        ->elementExists('css', 'table tbody tr:nth-child(2)');
    $this->assertSession()
        ->elementExists('named', [
        'link',
        'Revert',
    ], $row2);
    // Revision 3 does not have revert revision operation: no access.
    $row3 = $this->assertSession()
        ->elementExists('css', 'table tbody tr:nth-child(3)');
    $this->assertSession()
        ->elementNotExists('named', [
        'link',
        'Revert',
    ], $row3);
    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()
        ->elementsCount('css', 'table tbody tr', 3);
}

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