You are here

public function EditorImageDialogTest::testEditorImageDialog in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/editor/tests/src/Kernel/EditorImageDialogTest.php \Drupal\Tests\editor\Kernel\EditorImageDialogTest::testEditorImageDialog()

Tests that editor image dialog works as expected.

File

core/modules/editor/tests/src/Kernel/EditorImageDialogTest.php, line 88

Class

EditorImageDialogTest
Tests EditorImageDialog validation and conversion functionality.

Namespace

Drupal\Tests\editor\Kernel

Code

public function testEditorImageDialog() {
  $input = [
    'editor_object' => [
      'src' => '/sites/default/files/inline-images/somefile.png',
      'alt' => 'fda',
      'width' => '',
      'height' => '',
      'data-entity-type' => 'file',
      'data-entity-uuid' => 'some-uuid',
      'data-align' => 'none',
      'hasCaption' => 'false',
    ],
    'dialogOptions' => [
      'title' => 'Edit Image',
      'dialogClass' => 'editor-image-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,
  ]);
  $form_builder = $this->container
    ->get('form_builder');
  $form_object = new EditorImageDialog(\Drupal::entityTypeManager()
    ->getStorage('file'));
  $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);

  // Assert these two values are present and we don't get the 'not-this'
  // default back.
  $this
    ->assertEqual(FALSE, $form_state
    ->getValue([
    'attributes',
    'hasCaption',
  ], 'not-this'));
}