You are here

public function LinkitEditorLinkDialogTest::testEditWithoutDataAttributes in Linkit 8.5

Tests editing a link without data attributes.

File

tests/src/Kernel/LinkitEditorLinkDialogTest.php, line 205

Class

LinkitEditorLinkDialogTest
Tests EditorLinkDialog validation and conversion functionality.

Namespace

Drupal\Tests\linkit\Kernel

Code

public function testEditWithoutDataAttributes() {
  $form_object = new EditorLinkDialog();
  $input = [
    'editor_object' => [
      'href' => 'http://example.com/',
    ],
    'dialogOptions' => [
      'title' => 'Edit Link',
      'dialogClass' => 'editor-link-dialog',
      'autoResize' => 'true',
    ],
    '_drupal_ajax' => '1',
    'ajax_page_state' => [
      'theme' => 'bartik',
      'theme_token' => 'some-token',
      'libraries' => '',
    ],
  ];
  $form_state = (new FormState())
    ->setRequestMethod('POST')
    ->setUserInput($input)
    ->addBuildInfo('args', [
    $this->editor,
  ]);

  /** @var \Drupal\Core\Form\FormBuilderInterface $form_builder */
  $form_builder = $this->container
    ->get('form_builder');
  $form_id = $form_builder
    ->getFormId($form_object, $form_state);
  $form = $form_builder
    ->retrieveForm($form_id, $form_state);
  $form_builder
    ->prepareForm($form_id, $form, $form_state);
  $form_builder
    ->processForm($form_id, $form, $form_state);
  $this
    ->assertEquals('linkit.autocomplete', $form['attributes']['href']['#autocomplete_route_name'], 'Linkit is enabled on the href field.');
  $this
    ->assertEquals('http://example.com/', $form['attributes']['href']['#default_value'], 'The href field default value is the external URI.');
  $this
    ->assertEmpty($form['attributes']['data-entity-type']['#default_value']);
  $this
    ->assertEmpty($form['attributes']['data-entity-uuid']['#default_value']);
  $this
    ->assertEmpty($form['attributes']['data-entity-substitution']['#default_value']);
}