DiffViewsTest.php in Diff 8
File
tests/src/Functional/DiffViewsTest.php
View source
<?php
namespace Drupal\Tests\diff\Functional;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\views\Functional\ViewTestBase;
class DiffViewsTest extends ViewTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'node',
'diff',
'user',
'views',
'diff_test',
];
public function testDiffView() {
$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>');
}
}