function EntityRevisionsTest::testEntityRevisionParamConverter

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php \Drupal\Tests\system\Functional\Entity\EntityRevisionsTest::testEntityRevisionParamConverter()
  2. 10 core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php \Drupal\Tests\system\Functional\Entity\EntityRevisionsTest::testEntityRevisionParamConverter()
  3. 11.x core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php \Drupal\Tests\system\Functional\Entity\EntityRevisionsTest::testEntityRevisionParamConverter()

Tests that an entity revision is upcasted in the correct language.

File

core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php, line 187

Class

EntityRevisionsTest
Create a entity with revisions and test viewing, saving, reverting, and deleting revisions.

Namespace

Drupal\Tests\system\Functional\Entity

Code

public function testEntityRevisionParamConverter() {
    // Create a test entity with multiple revisions and translations for them.
    $entity = EntityTestMulRev::create([
        'name' => 'default revision - en',
        'user_id' => $this->webUser,
        'language' => 'en',
    ]);
    $entity->addTranslation('de', [
        'name' => 'default revision - de',
    ]);
    $entity->save();
    $pending_revision = \Drupal::entityTypeManager()->getStorage('entity_test_mulrev')
        ->loadUnchanged($entity->id());
    $pending_revision->setNewRevision();
    $pending_revision->isDefaultRevision(FALSE);
    $pending_revision->name = 'pending revision - en';
    $pending_revision->save();
    $pending_revision_translation = $pending_revision->getTranslation('de');
    $pending_revision_translation->name = 'pending revision - de';
    $pending_revision_translation->save();
    // Check that the entity revision is upcasted in the correct language.
    $revision_url = 'entity_test_mulrev/' . $entity->id() . '/revision/' . $pending_revision->getRevisionId() . '/view';
    $this->drupalGet($revision_url);
    $this->assertText('pending revision - en');
    $this->assertNoText('pending revision - de');
    $this->drupalGet('de/' . $revision_url);
    $this->assertText('pending revision - de');
    $this->assertNoText('pending revision - en');
}

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