You are here

public function DiffPluginTest::testTrimmingField in Diff 8

Tests field content trimming.

File

tests/src/Functional/DiffPluginTest.php, line 171

Class

DiffPluginTest
Tests the Diff module plugins.

Namespace

Drupal\Tests\diff\Functional

Code

public function testTrimmingField() {

  // Create a node.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'test_trim',
    'body' => '<p>body</p>',
  ]);

  // Save a second revision.
  $node
    ->save();

  // Create a revision adding a new empty line to the body.
  $node = $this
    ->drupalGetNodeByTitle('test_trim');
  $edit = [
    'revision' => TRUE,
    'body[0][value]' => '<p>body</p>
',
  ];
  $this
    ->drupalPostNodeForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Assert the revision comparison.
  $this
    ->drupalGet('node/' . $node
    ->id() . '/revisions');
  $this
    ->drupalPostForm(NULL, [], t('Compare selected revisions'));
  $this
    ->assertNoText('No visible changes.');
  $rows = $this
    ->xpath('//tbody/tr');
  $diff_row = $rows[1]
    ->findAll('xpath', '/td');
  $this
    ->assertEqual(count($rows), 3);
  $this
    ->assertEqual(htmlspecialchars_decode(strip_tags($diff_row[2]
    ->getHtml())), '<p>body</p>');

  // Create a new revision and update the body.
  $edit = [
    'revision' => TRUE,
    'body[0][value]' => '<p>body</p>

<p>body_new</p>
',
  ];
  $this
    ->drupalPostNodeForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));
  $this
    ->drupalGet('node/' . $node
    ->id() . '/revisions');
  $this
    ->drupalPostForm(NULL, [], t('Compare selected revisions'));
  $this
    ->assertNoText('No visible changes.');

  // Assert that empty rows also show a line number.
  $rows = $this
    ->xpath('//tbody/tr');
  $this
    ->assertEqual(count($rows), 5);
  $diff_row = $rows[4]
    ->findAll('xpath', '/td');
  $this
    ->assertEqual(htmlspecialchars_decode(strip_tags($diff_row[3]
    ->getHtml())), '4');
  $this
    ->assertEqual(htmlspecialchars_decode(strip_tags($diff_row[0]
    ->getHtml())), '2');
}