You are here

public function DiffRevisionTest::testRevisionOverviewErrorMessages in Diff 8

Tests the revisions overview error messages.

@todo Move to DiffLocaleTest?

File

tests/src/Functional/DiffRevisionTest.php, line 332

Class

DiffRevisionTest
Tests the diff revisions overview.

Namespace

Drupal\Tests\diff\Functional

Code

public function testRevisionOverviewErrorMessages() {

  // Enable some languages for this test.
  $language = ConfigurableLanguage::createFromLangcode('de');
  $language
    ->save();

  // Login as admin with the required permissions.
  $this
    ->loginAsAdmin([
    'administer node form display',
    'administer languages',
    'administer content translation',
    'create content translations',
    'translate any entity',
  ]);

  // Make article content translatable.
  $edit = [
    'entity_types[node]' => TRUE,
    'settings[node][article][translatable]' => TRUE,
    'settings[node][article][settings][language][language_alterable]' => TRUE,
  ];
  $this
    ->drupalPostForm('admin/config/regional/content-language', $edit, t('Save configuration'));

  // Create an article.
  $title = 'test_title_b';
  $edit = [
    'title[0][value]' => $title,
    'body[0][value]' => '<p>Revision 1</p>',
  ];
  $this
    ->drupalPostNodeForm('node/add/article', $edit, t('Save and publish'));
  $node = $this
    ->drupalGetNodeByTitle($title);
  $revision1 = $node
    ->getRevisionId();

  // Create a revision, changing the node language to German.
  $edit = [
    'langcode[0][value]' => 'de',
    'body[0][value]' => '<p>Revision 2</p>',
    'revision' => TRUE,
  ];
  $this
    ->drupalPostNodeForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Check the revisions overview, ensure only one revisions is available.
  $this
    ->clickLink(t('Revisions'));
  $rows = $this
    ->xpath('//tbody/tr');
  $this
    ->assertEqual(count($rows), 1);

  // Compare the revisions and assert the first error message.
  $this
    ->drupalPostForm(NULL, NULL, t('Compare selected revisions'));
  $this
    ->assertText('Multiple revisions are needed for comparison.');

  // Create another revision, changing the node language back to English.
  $edit = [
    'langcode[0][value]' => 'en',
    'body[0][value]' => '<p>Revision 3</p>',
    'revision' => TRUE,
  ];
  $this
    ->drupalPostNodeForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));
  $node = $this
    ->drupalGetNodeByTitle($title, TRUE);
  $revision3 = $node
    ->getRevisionId();

  // Check the revisions overview, ensure two revisions are available.
  $this
    ->clickLink(t('Revisions'));
  $rows = $this
    ->xpath('//tbody/tr');
  $this
    ->assertEqual(count($rows), 2);
  $this
    ->assertNoFieldChecked('edit-node-revisions-table-0-select-column-one');
  $this
    ->assertFieldChecked('edit-node-revisions-table-0-select-column-two');
  $this
    ->assertNoFieldChecked('edit-node-revisions-table-1-select-column-one');
  $this
    ->assertNoFieldChecked('edit-node-revisions-table-1-select-column-two');

  // Compare the revisions and assert the second error message.
  $this
    ->drupalPostForm(NULL, NULL, t('Compare selected revisions'));
  $this
    ->assertText('Select two revisions to compare.');

  // Check the same revisions twice and compare.
  $edit = [
    'radios_left' => $revision3,
    'radios_right' => $revision3,
  ];
  $this
    ->drupalPostForm('/node/' . $node
    ->id() . '/revisions', $edit, 'Compare selected revisions');

  // Assert the third error message.
  $this
    ->assertText('Select different revisions to compare.');

  // Check different revisions and compare. This time should work correctly.
  $edit = [
    'radios_left' => $revision3,
    'radios_right' => $revision1,
  ];
  $this
    ->drupalPostForm('/node/' . $node
    ->id() . '/revisions', $edit, 'Compare selected revisions');
  $this
    ->assertLinkByHref('node/' . $node
    ->id() . '/revisions/view/' . $revision1 . '/' . $revision3);
}