You are here

protected function DiffLocaleTest::doTestTranslationFilter in Diff 8

Tests the translation filtering when navigating trough revisions.

1 call to DiffLocaleTest::doTestTranslationFilter()
DiffLocaleTest::testAll in tests/src/FunctionalJavascript/DiffLocaleTest.php
Run all independent tests.

File

tests/src/FunctionalJavascript/DiffLocaleTest.php, line 114

Class

DiffLocaleTest
Test diff functionality with localization and translation.

Namespace

Drupal\Tests\diff\FunctionalJavascript

Code

protected function doTestTranslationFilter() {

  // Create a node in English.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'english_revision_0',
  ]);
  $revision1 = $node
    ->getRevisionId();

  // Translate to french.
  $node
    ->addTranslation('fr', [
    'title' => 'french_revision_0',
  ]);
  $node
    ->save();

  // Create a revision in English.
  $english_node = $node
    ->getTranslation('en');
  $english_node
    ->setTitle('english_revision_1');
  $english_node
    ->setNewRevision(TRUE);
  $english_node
    ->save();
  $revision2 = $node
    ->getRevisionId();

  // Create a revision in French.
  $french_node = $node
    ->getTranslation('fr');
  $french_node
    ->setTitle('french_revision_1');
  $french_node
    ->setNewRevision(TRUE);
  $french_node
    ->save();

  // Create a new revision in English.
  $english_node = $node
    ->getTranslation('en');
  $english_node
    ->setTitle('english_revision_2');
  $english_node
    ->setNewRevision(TRUE);
  $english_node
    ->save();

  // Create a new revision in French.
  $french_node = $node
    ->getTranslation('fr');
  $french_node
    ->setTitle('french_revision_2');
  $french_node
    ->setNewRevision(TRUE);
  $french_node
    ->save();

  // Compare first two revisions.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/revisions/view/' . $revision1 . '/' . $revision2 . '/split_fields');
  $diffs = $this
    ->getSession()
    ->getPage()
    ->findAll('xpath', '//span[@class="diffchange"]');
  $this
    ->assertEqual($diffs[0]
    ->getText(), 'english_revision_0');
  $this
    ->assertEqual($diffs[1]
    ->getText(), 'english_revision_1');

  // Check next difference.
  $this
    ->clickLink('Next change');
  $diffs = $this
    ->getSession()
    ->getPage()
    ->findAll('xpath', '//span[@class="diffchange"]');
  $this
    ->assertEqual($diffs[0]
    ->getText(), 'english_revision_1');
  $this
    ->assertEqual($diffs[1]
    ->getText(), 'english_revision_2');

  // There shouldn't be other differences in the current language.
  $this
    ->assertNoLink('Next change');
}