3 namespace Drupal\Tests\editor\Kernel;
5 use Drupal\Core\Form\FormState;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\editor\Form\EditorImageDialog;
8 use Drupal\filter\Entity\FilterFormat;
9 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
10 use Drupal\node\Entity\NodeType;
13 * Tests EditorImageDialog validation and conversion functionality.
17 class EditorImageDialogTest extends EntityKernelTestBase {
20 * Text editor config entity for testing.
22 * @var \Drupal\editor\EditorInterface
31 public static $modules = ['node', 'file', 'editor', 'editor_test', 'user', 'system'];
36 protected function setUp() {
38 $this->installEntitySchema('file');
39 $this->installSchema('system', ['key_value_expire']);
40 $this->installSchema('node', ['node_access']);
41 $this->installSchema('file', ['file_usage']);
42 $this->installConfig(['node']);
45 $format = FilterFormat::create([
46 'format' => 'filtered_html',
47 'name' => 'Filtered HTML',
50 'filter_align' => ['status' => TRUE],
51 'filter_caption' => ['status' => TRUE],
56 // Set up text editor.
57 $editor = Editor::create([
58 'format' => 'filtered_html',
59 'editor' => 'unicorn',
68 $this->editor = $editor;
70 // Create a node type for testing.
71 $type = NodeType::create(['type' => 'page', 'name' => 'page']);
73 node_add_body_field($type);
74 $this->installEntitySchema('user');
75 \Drupal::service('router.builder')->rebuild();
79 * Tests that editor image dialog works as expected.
81 public function testEditorImageDialog() {
84 'src' => '/sites/default/files/inline-images/somefile.png',
88 'data-entity-type' => 'file',
89 'data-entity-uuid' => 'some-uuid',
90 'data-align' => 'none',
91 'hasCaption' => 'false',
94 'title' => 'Edit Image',
95 'dialogClass' => 'editor-image-dialog',
96 'autoResize' => 'true',
98 '_drupal_ajax' => '1',
99 'ajax_page_state' => [
101 'theme_token' => 'some-token',
105 $form_state = (new FormState())
106 ->setRequestMethod('POST')
107 ->setUserInput($input)
108 ->addBuildInfo('args', [$this->editor]);
110 $form_builder = $this->container->get('form_builder');
111 $form_object = new EditorImageDialog(\Drupal::entityManager()->getStorage('file'));
112 $form_id = $form_builder->getFormId($form_object, $form_state);
113 $form = $form_builder->retrieveForm($form_id, $form_state);
114 $form_builder->prepareForm($form_id, $form, $form_state);
115 $form_builder->processForm($form_id, $form, $form_state);
117 // Assert these two values are present and we don't get the 'not-this'
119 $this->assertEqual(FALSE, $form_state->getValue(['attributes', 'hasCaption'], 'not-this'));