function RevisionRevertFormTest::testPageTitle

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

Tests title by whether entity supports revision creation dates.

Parameters

string $entityTypeId: The entity type to test.

string $expectedQuestion: The expected question/page title.

1 call to RevisionRevertFormTest::testPageTitle()
RevisionRevertFormTest::testFormRevisionRevert in core/tests/Drupal/FunctionalTests/Entity/RevisionRevertFormTest.php
Test form revision revert.

File

core/tests/Drupal/FunctionalTests/Entity/RevisionRevertFormTest.php, line 67

Class

RevisionRevertFormTest
Tests reverting a revision with revision revert form.

Namespace

Drupal\FunctionalTests\Entity

Code

protected function testPageTitle(string $entityTypeId, string $expectedQuestion) : void {
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
    $storage = \Drupal::entityTypeManager()->getStorage($entityTypeId);
    $entity = $storage->create([
        'type' => $entityTypeId,
        'name' => 'revert',
    ]);
    if ($entity instanceof RevisionLogInterface) {
        $date = new \DateTime('11 January 2009 4:00:00pm');
        $entity->setRevisionCreationTime($date->getTimestamp());
    }
    $entity->setNewRevision();
    $entity->save();
    $revisionId = $entity->getRevisionId();
    // Create a new latest revision.
    if ($entity instanceof RevisionLogInterface) {
        $entity->setRevisionCreationTime($date->modify('+1 hour')
            ->getTimestamp());
    }
    $entity->setNewRevision();
    $entity->save();
    // Reload the entity.
    $revision = $storage->loadRevision($revisionId);
    $this->drupalGet($revision->toUrl('revision-revert-form'));
    $this->assertSession()
        ->pageTextContains($expectedQuestion);
    $this->assertSession()
        ->buttonExists('Revert');
    $this->assertSession()
        ->linkExists('Cancel');
}

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