You are here

public function DiffPluginVariousTest::testLinkPlugin in Diff 8

Tests the Link plugin.

@covers \Drupal\diff\Plugin\diff\Field\LinkFieldBuilder

File

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

Class

DiffPluginVariousTest
Tests the Diff module plugins.

Namespace

Drupal\Tests\diff\Functional

Code

public function testLinkPlugin() {

  // Add a link field to the article content type.
  $field_name = 'field_link';
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'link',
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'article',
    'label' => 'Link',
    'settings' => array(
      'title' => DRUPAL_OPTIONAL,
      'link_type' => LinkItemInterface::LINK_GENERIC,
    ),
  ])
    ->save();
  $this->formDisplay
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'link_default',
    'settings' => [
      'placeholder_url' => 'http://example.com',
    ],
  ])
    ->save();
  $this->viewDisplay
    ->load('node.article.default')
    ->setComponent($field_name, [
    'type' => 'link',
  ])
    ->save();

  // Enable the comparison of the link's title field.
  $this
    ->config('diff.plugins')
    ->set('fields.node.field_link.type', 'link_field_diff_builder')
    ->set('fields.node.field_link.settings', [
    'compare_title' => TRUE,
  ])
    ->save();

  // Create an article, setting values on the link field.
  $node = $this
    ->drupalCreateNode([
    'type' => 'article',
    'title' => 'Test article',
    'field_link' => [
      'title' => 'Google',
      'uri' => 'http://www.google.com',
    ],
  ]);

  // Update the link field.
  $edit = [
    'field_link[0][title]' => 'Guguel',
    'field_link[0][uri]' => 'http://www.google.es',
    'revision' => TRUE,
  ];
  $this
    ->drupalPostNodeForm('node/' . $node
    ->id() . '/edit', $edit, t('Save and keep published'));

  // Check differences between revisions.
  $this
    ->clickLink(t('Revisions'));
  $this
    ->drupalPostForm(NULL, [], t('Compare selected revisions'));
  $this
    ->assertText('Link');
  $this
    ->assertText('Google');
  $this
    ->assertText('http://www.google.com');
  $this
    ->assertText('Guguel');
  $this
    ->assertText('http://www.google.es');
}