You are here

public function DiffViewsTest::testDiffView in Diff 8

Tests the behavior of a view that uses the diff_from and diff_to fields.

File

tests/src/Functional/DiffViewsTest.php, line 32

Class

DiffViewsTest
Tests the diff views integration.

Namespace

Drupal\Tests\diff\Functional

Code

public function testDiffView() {

  // Make sure HTML Diff is disabled.
  $this
    ->config('diff.settings')
    ->set('general_settings.layout_plugins.visual_inline.enabled', FALSE)
    ->save();
  $node_type = NodeType::create([
    'type' => 'article',
    'label' => 'Article',
  ]);
  $node_type
    ->save();
  $node = Node::create([
    'type' => 'article',
    'title' => 'Test article: giraffe',
  ]);
  $node
    ->save();
  $revision1 = $node
    ->getRevisionId();
  $node
    ->setNewRevision(TRUE);
  $node
    ->setTitle('Test article: llama');
  $node
    ->save();
  $revision2 = $node
    ->getRevisionId();
  $this
    ->drupalGet("node/{$node->id()}/diff-views");
  $this
    ->assertResponse(403);
  $user = $this
    ->createUser([
    'view all revisions',
  ]);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet("node/{$node->id()}/diff-views");
  $this
    ->assertResponse(200);
  $from_first = $this
    ->cssSelect('#edit-diff-from--3')[0]
    ->getAttribute('value');
  $to_second = $this
    ->cssSelect('#edit-diff-to--2')[0]
    ->getAttribute('value');
  $edit = [
    'diff_from' => $from_first,
    'diff_to' => $to_second,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Compare'));
  $expected_url = Url::fromRoute('diff.revisions_diff', [
    'node' => $node
      ->id(),
    'left_revision' => $revision1,
    'right_revision' => $revision2,
    'filter' => 'split_fields',
  ], [
    'query' => [
      'destination' => Url::fromUri("internal:/node/{$node->id()}/diff-views")
        ->toString(),
    ],
  ]);
  $this
    ->assertUrl($expected_url);
  $this
    ->assertRaw('<td class="diff-context diff-deletedline">Test article: <span class="diffchange">giraffe</span></td>');
  $this
    ->assertRaw('<td class="diff-context diff-addedline">Test article: <span class="diffchange">llama</span></td>');
}