function RevisionDeleteFormTest::testPageTitle

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

Tests title by whether entity supports revision creation dates.

@covers ::getQuestion
@dataProvider providerPageTitle

Parameters

string $entityTypeId: The entity type to test.

string $expectedQuestion: The expected question/page title.

File

core/tests/Drupal/FunctionalTests/Entity/RevisionDeleteFormTest.php, line 56

Class

RevisionDeleteFormTest
Tests deleting a revision with revision delete form.

Namespace

Drupal\FunctionalTests\Entity

Code

public function testPageTitle(string $entityTypeId, string $expectedQuestion) : void {
  /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
  $storage = \Drupal::entityTypeManager()->getStorage($entityTypeId);
  $entity = $storage->create([
    'type' => $entityTypeId,
    'name' => 'delete revision',
  ]);
  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-delete-form'));
  $this->assertSession()
    ->pageTextContains($expectedQuestion);
  $this->assertSession()
    ->buttonExists('Delete');
  $this->assertSession()
    ->linkExists('Cancel');
}

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