function RevisionVersionHistoryTranslatableTest::testVersionHistoryTranslations

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

Tests the version history page for translations.

File

core/tests/Drupal/FunctionalTests/Entity/RevisionVersionHistoryTranslatableTest.php, line 49

Class

RevisionVersionHistoryTranslatableTest
Tests version history page with translations.

Namespace

Drupal\FunctionalTests\Entity

Code

public function testVersionHistoryTranslations() : void {
    $label = 'view all revisions,revert,delete revision';
    $entity = EntityTestMulWithRevisionLog::create([
        'name' => $label,
        'type' => 'entity_test_mul_revlog',
    ]);
    $entity->addTranslation('es', [
        'label' => 'version history test translations es',
    ]);
    $entity->save();
    $firstRevisionId = $entity->getRevisionId();
    $entity->setNewRevision();
    $entity->setName($label . ',2')
        ->save();
    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->elementsCount('css', 'table tbody tr', 2);
    
    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
    $storage = $this->container
        ->get('entity_type.manager')
        ->getStorage($entity->getEntityTypeId());
    $firstRevision = $storage->loadRevision($firstRevisionId);
    $this->assertSession()
        ->linkByHrefExists($firstRevision->toUrl('revision-revert-form')
        ->toString());
    $this->assertSession()
        ->linkByHrefExists($firstRevision->toUrl('revision-delete-form')
        ->toString());
    $this->assertSession()
        ->linkByHrefNotExists($firstRevision->getTranslation('es')
        ->toUrl('revision-revert-form')
        ->toString());
    $this->assertSession()
        ->linkByHrefNotExists($firstRevision->getTranslation('es')
        ->toUrl('revision-delete-form')
        ->toString());
    $this->drupalGet($entity->getTranslation('es')
        ->toUrl('version-history'));
    $this->assertSession()
        ->linkByHrefNotExistsExact($firstRevision->toUrl('revision-revert-form')
        ->toString());
    $this->assertSession()
        ->linkByHrefNotExistsExact($firstRevision->toUrl('revision-delete-form')
        ->toString());
    $this->assertSession()
        ->linkByHrefExists($firstRevision->getTranslation('es')
        ->toUrl('revision-revert-form')
        ->toString());
    $this->assertSession()
        ->linkByHrefExists($firstRevision->getTranslation('es')
        ->toUrl('revision-delete-form')
        ->toString());
}

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