function NodeTranslationUITest::testRevisionTranslationRendering

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testRevisionTranslationRendering()
  2. 8.9.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testRevisionTranslationRendering()
  3. 11.x core/modules/node/tests/src/Functional/NodeTranslationUITest.php \Drupal\Tests\node\Functional\NodeTranslationUITest::testRevisionTranslationRendering()

Tests that revision translations are rendered properly.

File

core/modules/node/tests/src/Functional/NodeTranslationUITest.php, line 508

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\Tests\node\Functional

Code

public function testRevisionTranslationRendering() : void {
    $storage = \Drupal::entityTypeManager()->getStorage('node');
    // Create a node.
    $nid = $this->createEntity([
        'title' => 'First rev en title',
    ], 'en');
    $node = $storage->load($nid);
    $original_revision_id = $node->getRevisionId();
    // Add a French translation.
    $translation = $node->addTranslation('fr');
    $translation->title = 'First rev fr title';
    $translation->setNewRevision(FALSE);
    $translation->save();
    // Create a new revision.
    $node->title = 'Second rev en title';
    $node->setNewRevision(TRUE);
    $node->save();
    // Get an English view of this revision.
    $original_revision = $storage->loadRevision($original_revision_id);
    $original_revision_url = $original_revision->toUrl('revision')
        ->toString();
    // Should be different from regular node URL.
    $this->assertNotSame($original_revision_url, $original_revision->toUrl()
        ->toString());
    $this->drupalGet($original_revision_url);
    $this->assertSession()
        ->statusCodeEquals(200);
    // Contents should be in English, of correct revision.
    $this->assertSession()
        ->pageTextContains('First rev en title');
    $this->assertSession()
        ->pageTextNotContains('First rev fr title');
    // Get a French view.
    $url_fr = $original_revision->getTranslation('fr')
        ->toUrl('revision')
        ->toString();
    // Should have different URL from English.
    $this->assertNotSame($url_fr, $original_revision->toUrl()
        ->toString());
    $this->assertNotSame($url_fr, $original_revision_url);
    $this->drupalGet($url_fr);
    $this->assertSession()
        ->statusCodeEquals(200);
    // Contents should be in French, of correct revision.
    $this->assertSession()
        ->pageTextContains('First rev fr title');
    $this->assertSession()
        ->pageTextNotContains('First rev en title');
}

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