Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / editor / tests / src / Unit / EditorBaseTest.php
1 <?php
2
3 namespace Drupal\Tests\editor\Unit;
4
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;
10
11 /**
12  * @coversDefaultClass \Drupal\editor\Plugin\EditorBase
13  * @group editor
14  */
15 class EditorBaseTest extends UnitTestCase {
16
17   /**
18    * @covers ::buildConfigurationForm
19    * @covers ::validateConfigurationForm
20    * @covers ::submitConfigurationForm
21    */
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', []);
26
27     // settingsForm() is deprecated in favor of buildConfigurationForm().
28     $this->assertSame(
29       $editor_plugin->settingsForm([], clone $form_state, $this->prophesize(Editor::class)->reveal()),
30       $editor_plugin->buildConfigurationForm([], clone $form_state)
31     );
32
33     // settingsFormValidate() is deprecated in favor of
34     // validateConfigurationForm().
35     $form = [];
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);
41
42     // settingsFormSubmit() is deprecated in favor of submitConfigurationForm().
43     $form = [];
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);
49   }
50
51 }
52
53 class BcEditor extends EditorBase {
54
55   public function settingsForm(array $form, FormStateInterface $form_state, Editor $editor) {
56     return ['foo' => 'bar'];
57   }
58
59   public function settingsFormValidate(array $form, FormStateInterface $form_state) {
60     $form_state->setValue('foo', 'bar');
61   }
62
63   public function settingsFormSubmit(array $form, FormStateInterface $form_state) {
64     $form_state->setValue('bar', 'baz');
65   }
66
67   public function getJSSettings(Editor $editor) {
68     return [];
69   }
70
71   public function getLibraries(Editor $editor) {
72     return [];
73   }
74
75 }