View source
<?php
namespace Drupal\Tests\entity_reference_revisions\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\field_ui\Traits\FieldUiTestTrait;
class EntityReferenceRevisionsDiffTest extends BrowserTestBase {
use FieldUiTestTrait;
public static $modules = [
'block_content',
'node',
'field',
'entity_reference_revisions',
'field_ui',
'diff',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$config = $this
->config('diff.settings')
->set('general_settings.layout_plugins.visual_inline.enabled', FALSE);
$config
->save();
$admin_user = $this
->drupalCreateUser([
'administer site configuration',
'administer nodes',
'administer content types',
'administer node fields',
'administer node display',
'administer node form display',
'view all revisions',
'edit any article content',
]);
$this
->drupalLogin($admin_user);
$this
->drupalPlaceBlock('system_breadcrumb_block');
}
public function testEntityReferenceRevisionsDiff() {
static::fieldUIAddNewField('admin/structure/types/manage/article', 'err_field', 'err_field', 'entity_reference_revisions', [
'settings[target_type]' => 'node',
'cardinality' => '-1',
], [
'settings[handler_settings][target_bundles][article]' => TRUE,
]);
$title_node_1 = 'referenced_node_1';
$edit = [
'title[0][value]' => $title_node_1,
'body[0][value]' => 'body_node_1',
];
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
$title_node_2 = 'referenced_node_2';
$edit = [
'title[0][value]' => $title_node_2,
'body[0][value]' => 'body_node_2',
];
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
$title = 'referencing_node';
$node = $this
->drupalGetNodeByTitle($title_node_1);
$edit = [
'title[0][value]' => $title,
'field_err_field[0][target_id]' => $title_node_1 . ' (' . $node
->id() . ')',
];
$this
->drupalGet('node/add/article');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('admin/config/content/diff/fields');
$this
->submitForm([
'fields[node__field_err_field][plugin][type]' => 'entity_reference_revisions_field_diff_builder',
], 'Save');
$node = $this
->drupalGetNodeByTitle($title);
$referenced_node_new = $this
->drupalGetNodeByTitle($title_node_2);
$edit = [
'field_err_field[0][target_id]' => $title_node_2 . ' (' . $referenced_node_new
->id() . ')',
'revision' => TRUE,
];
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->submitForm($edit, 'Save');
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$this
->submitForm([], 'Compare selected revisions');
$this
->assertRaw('class="diff-context diff-deletedline">' . $title_node_1);
$this
->assertRaw('class="diff-context diff-addedline">' . $title_node_2);
}
}