function RevisionVersionHistoryTest::testCurrentRevision

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

Test current revision is indicated.

@covers \Drupal\Core\Entity\Controller\VersionHistoryController::revisionOverview

File

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

Class

RevisionVersionHistoryTest
Tests version history page.

Namespace

Drupal\FunctionalTests\Entity

Code

public function testCurrentRevision() : void {
  /** @var \Drupal\entity_test\Entity\EntityTestRev $entity */
  $entity = EntityTestRev::create([
    'type' => 'entity_test_rev',
  ]);
  // Need label to be able to assert order.
  $entity->setName('view all revisions');
  $entity->setNewRevision();
  $entity->save();
  $entity->setNewRevision();
  $entity->save();
  $entity->setNewRevision();
  $entity->save();
  $this->drupalGet($entity->toUrl('version-history'));
  $this->assertSession()
    ->elementsCount('css', 'table tbody tr', 3);
  // Current revision text is found on the latest revision row.
  $this->assertSession()
    ->elementTextContains('css', 'table tbody tr:nth-child(1)', 'Current revision');
  $this->assertSession()
    ->elementTextNotContains('css', 'table tbody tr:nth-child(2)', 'Current revision');
  $this->assertSession()
    ->elementTextNotContains('css', 'table tbody tr:nth-child(3)', 'Current revision');
  // Current revision row has 'revision-current' class.
  $this->assertSession()
    ->elementAttributeContains('css', 'table tbody tr:nth-child(1)', 'class', 'revision-current');
}

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