Unverified Commit 50ebb80e authored by Alex Pott's avatar Alex Pott
Browse files

perf: #3590746 Speed up RevisionVersionHistoryTest

By: catch
parent 454adefc
Loading
Loading
Loading
Loading
Loading
+18 −56
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class RevisionVersionHistoryTest extends BrowserTestBase {
  /**
   * Test all revisions appear, in order of revision creation.
   */
  public function testOrder(): void {
  public function testOrderAndDescription(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    // Need label to be able to assert order.
@@ -65,47 +65,8 @@ public function testOrder(): void {
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', 'third revision');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(2)', 'second revision');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(3)', 'first revision');
  }

  /**
   * Test current revision is indicated.
   *
   * @legacy-covers \Drupal\Core\Entity\Controller\VersionHistoryController::revisionOverview
   */
  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');
  }

  /**
   * Test description with entity implementing revision log.
   *
   * @legacy-covers ::getRevisionDescription
   */
  public function testDescriptionRevLog(): void {
    /** @var \Drupal\entity_test_revlog\Entity\EntityTestWithRevisionLog $entity */
    $entity = EntityTestWithRevisionLog::create(['type' => 'entity_test_revlog']);
    $entity->setName('view all revisions');
    $user = $this->drupalCreateUser([], $this->randomMachineName());
    $user = $this->drupalCreateUser([], 'fourth revision');
    $entity->setRevisionUser($user);
    $entity->setRevisionCreationTime((new \DateTime('2 February 2013 4:00:00pm'))->getTimestamp());
    $entity->save();
@@ -135,11 +96,11 @@ public function testDescriptionRevLogNullValues(): void {
  }

  /**
   * Test description with entity, without revision log, no label access.
   * Test description with entity, without revision log, label access.
   *
   * @legacy-covers ::getRevisionDescription
   */
  public function testDescriptionNoRevLogNoLabelAccess(): void {
  public function testDescriptionNoRevLog(): void {
    /** @var \Drupal\entity_test\Entity\EntityTestRev $entity */
    $entity = EntityTestRev::create(['type' => 'entity_test_rev']);
    $entity->setName('view all revisions');
@@ -148,25 +109,26 @@ public function testDescriptionNoRevLogNoLabelAccess(): void {
    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', '- Restricted access -');
    $this->assertSession()->elementTextNotContains('css', 'table tbody tr:nth-child(1)', $entity->getName());
  }

  /**
   * Test description with entity, without revision log, with label access.
   *
   * @legacy-covers ::getRevisionDescription
   */
  public function testDescriptionNoRevLogWithLabelAccess(): void {
    // Permission grants 'view label' access.
    $this->drupalLogin($this->createUser(['view test entity']));
    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', $entity->getName());
    $this->assertSession()->elementTextNotContains('css', 'table tbody tr:nth-child(1)', '- Restricted access -');

    /** @var \Drupal\entity_test\Entity\EntityTestRev $entity */
    $entity = EntityTestRev::create(['type' => 'entity_test_rev']);
    $entity->setName('view all revisions');
    $entity->setNewRevision();
    $entity->save();

    $entity->setNewRevision();
    $entity->save();

    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', $entity->getName());
    $this->assertSession()->elementTextNotContains('css', 'table tbody tr:nth-child(1)', '- Restricted access -');
    $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');
  }

  /**