3 namespace Drupal\Tests\editor\Unit;
5 use Drupal\Core\Form\FormState;
6 use Drupal\Core\Form\FormStateInterface;
7 use Drupal\editor\Entity\Editor;
8 use Drupal\editor\Plugin\EditorBase;
9 use Drupal\Tests\UnitTestCase;
12 * @coversDefaultClass \Drupal\editor\Plugin\EditorBase
15 class EditorBaseTest extends UnitTestCase {
18 * @covers ::buildConfigurationForm
19 * @covers ::validateConfigurationForm
20 * @covers ::submitConfigurationForm
22 public function testBc() {
23 $form_state = new FormState();
24 $form_state->set('editor', $this->prophesize(Editor::class)->reveal());
25 $editor_plugin = new BcEditor([], 'editor_plugin', []);
27 // settingsForm() is deprecated in favor of buildConfigurationForm().
29 $editor_plugin->settingsForm([], clone $form_state, $this->prophesize(Editor::class)->reveal()),
30 $editor_plugin->buildConfigurationForm([], clone $form_state)
33 // settingsFormValidate() is deprecated in favor of
34 // validateConfigurationForm().
36 $form_state_a = clone $form_state;
37 $form_state_b = clone $form_state;
38 $editor_plugin->settingsFormValidate($form, $form_state_a, $this->prophesize(Editor::class)->reveal());
39 $editor_plugin->validateConfigurationForm($form, $form_state_b);
40 $this->assertEquals($form_state_a, $form_state_b);
42 // settingsFormSubmit() is deprecated in favor of submitConfigurationForm().
44 $form_state_a = clone $form_state;
45 $form_state_b = clone $form_state;
46 $editor_plugin->settingsFormSubmit($form, $form_state_a, $this->prophesize(Editor::class)->reveal());
47 $editor_plugin->submitConfigurationForm($form, $form_state_b);
48 $this->assertEquals($form_state_a, $form_state_b);
53 class BcEditor extends EditorBase {
55 public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
56 return ['foo' => 'bar'];
59 public function settingsFormValidate(array $form, FormStateInterface $form_state) {
60 $form_state->setValue('foo', 'bar');
63 public function settingsFormSubmit(array $form, FormStateInterface $form_state) {
64 $form_state->setValue('bar', 'baz');
67 public function getJSSettings(Editor $editor) {
71 public function getLibraries(Editor $editor) {