You are here

public function DiffPluginVariousTest::testCorePlugin in Diff 8

Tests the Core plugin.

@covers \Drupal\diff\Plugin\diff\Field\CoreFieldBuilder

File

tests/src/Functional/DiffPluginVariousTest.php, line 100

Class

DiffPluginVariousTest
Tests the Diff module plugins.

Namespace

Drupal\Tests\diff\Functional

Code

public function testCorePlugin() {

  // Add an email field (supported by the Diff core plugin) to the Article
  // content type.
  $field_name = 'field_email';
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'email',
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'article',
    'label' => 'Email',
  ])
    ->save();

  // Add the email field to the article form.
  $this->formDisplay
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'email_default',
  ])
    ->save();

  // Add the email field to the default display.
  $this->viewDisplay
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'basic_string',
  ])
    ->save();

  // Create an article with an email.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'field_email' => 'foo@example.com',
  ]);

  // Edit the article and change the email.
  $edit = array(
    'field_email[0][value]' => 'bar@example.com',
    'revision' => TRUE,
  );
  $this
    ->drupalPostNodeForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Check the difference between the last two revisions.
  $this
    ->clickLink(t('Revisions'));
  $this
    ->drupalPostForm(NULL, NULL, t('Compare selected revisions'));
  $this
    ->assertText('Email');
  $this
    ->assertText('foo@example.com');
  $this
    ->assertText('bar@example.com');
}