You are here

public function EntityRevisionsTest::testEntityRevisionParamConverter in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Entity/EntityRevisionsTest.php \Drupal\Tests\system\Functional\Entity\EntityRevisionsTest::testEntityRevisionParamConverter()
  2. 9 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 188

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
    ->assertSession()
    ->pageTextContains('pending revision - en');
  $this
    ->assertSession()
    ->pageTextNotContains('pending revision - de');
  $this
    ->drupalGet('de/' . $revision_url);
  $this
    ->assertSession()
    ->pageTextContains('pending revision - de');
  $this
    ->assertSession()
    ->pageTextNotContains('pending revision - en');
}