public function EditorBaseTest::testBcWithSubformState in Drupal 8
@covers ::buildConfigurationForm @covers ::validateConfigurationForm @covers ::submitConfigurationForm
File
- core/
modules/ editor/ tests/ src/ Unit/ EditorBaseTest.php, line 63
Class
- EditorBaseTest
- @coversDefaultClass \Drupal\editor\Plugin\EditorBase @group editor
Namespace
Drupal\Tests\editor\UnitCode
public function testBcWithSubformState() {
$form_state = new FormState();
$form_state
->set('editor', $this
->prophesize(Editor::class)
->reveal());
$editor_plugin = new BcEditor([], 'editor_plugin', []);
$form['#parents'] = [];
$form['nested'] = [
'#parents' => [
'nested',
],
];
$subform_state = SubformState::createForSubform($form['nested'], $form, $form_state);
// settingsForm() uses SubFormState and is deprecated in favor of
// buildConfigurationForm() which uses FormState, the BC layer ensures they
// have the same results.
$this
->assertSame($editor_plugin
->settingsForm([], clone $form_state, $this
->prophesize(Editor::class)
->reveal()), $editor_plugin
->buildConfigurationForm([], clone $subform_state));
// settingsForm() uses SubFormState and is deprecated in favor of
// validateConfigurationForm() which uses FormState, the BC layer ensures
// they have the same results.
$form = [];
$form_state_a = clone $form_state;
$form_state_b = clone $subform_state;
$editor_plugin
->settingsFormValidate($form, $form_state_a, $this
->prophesize(Editor::class)
->reveal());
$editor_plugin
->validateConfigurationForm($form, $form_state_b);
$this
->assertEquals('bar', $form_state_a
->getValue([
'nested',
'foo',
]));
$this
->assertEquals('bar', $form_state_b
->getValue('foo'));
$this
->assertEquals($form_state_a, $form_state_b
->getCompleteFormState());
// settingsFormSubmit() uses SubFormState and is deprecated in favor of
// submitConfigurationForm() which uses FormState, the BC layer ensures they
// have the same results.
$form = [];
$form_state_a = clone $form_state;
$form_state_b = clone $subform_state;
$editor_plugin
->settingsFormSubmit($form, $form_state_a, $this
->prophesize(Editor::class)
->reveal());
$editor_plugin
->submitConfigurationForm($form, $form_state_b);
$this
->assertEquals('baz', $form_state_a
->getValue([
'nested',
'bar',
]));
$this
->assertEquals('baz', $form_state_b
->getValue('bar'));
$this
->assertEquals($form_state_a, $form_state_b
->getCompleteFormState());
}