class EditorBaseTest

@coversDefaultClass \Drupal\editor\Plugin\EditorBase @group editor

@group legacy

Hierarchy

Expanded class hierarchy of EditorBaseTest

File

core/modules/editor/tests/src/Unit/EditorBaseTest.php, line 18

Namespace

Drupal\Tests\editor\Unit
View source
class EditorBaseTest extends UnitTestCase {
    
    /**
     * @covers ::buildConfigurationForm
     * @covers ::validateConfigurationForm
     * @covers ::submitConfigurationForm
     *
     * @expectedDeprecation Drupal\Tests\editor\Unit\BcEditor::settingsForm is deprecated since version 8.3.x. Rename the implementation 'buildConfigurationForm'. See https://www.drupal.org/node/2819753
     * @expectedDeprecation Drupal\Tests\editor\Unit\BcEditor::settingsFormValidate is deprecated since version 8.3.x. Rename the implementation 'validateConfigurationForm'. See https://www.drupal.org/node/2819753
     * @expectedDeprecation Drupal\Tests\editor\Unit\BcEditor::settingsFormSubmit is deprecated since version 8.3.x. Rename the implementation 'submitConfigurationForm'. See https://www.drupal.org/node/2819753
     */
    public function testBc() {
        $form_state = new FormState();
        $form_state->set('editor', $this->prophesize(Editor::class)
            ->reveal());
        $editor_plugin = new BcEditor([], 'editor_plugin', []);
        // settingsForm() is deprecated in favor of buildConfigurationForm().
        $this->assertSame($editor_plugin->settingsForm([], clone $form_state, $this->prophesize(Editor::class)
            ->reveal()), $editor_plugin->buildConfigurationForm([], clone $form_state));
        // settingsFormValidate() is deprecated in favor of
        // validateConfigurationForm().
        $form = [];
        $form_state_a = clone $form_state;
        $form_state_b = clone $form_state;
        $editor_plugin->settingsFormValidate($form, $form_state_a, $this->prophesize(Editor::class)
            ->reveal());
        $editor_plugin->validateConfigurationForm($form, $form_state_b);
        $this->assertEquals($form_state_a, $form_state_b);
        // settingsFormSubmit() is deprecated in favor of submitConfigurationForm().
        $form = [];
        $form_state_a = clone $form_state;
        $form_state_b = clone $form_state;
        $editor_plugin->settingsFormSubmit($form, $form_state_a, $this->prophesize(Editor::class)
            ->reveal());
        $editor_plugin->submitConfigurationForm($form, $form_state_b);
        $this->assertEquals($form_state_a, $form_state_b);
    }
    
    /**
     * @covers ::buildConfigurationForm
     * @covers ::validateConfigurationForm
     * @covers ::submitConfigurationForm
     */
    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());
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
EditorBaseTest::testBc public function @covers ::buildConfigurationForm
@covers ::validateConfigurationForm
@covers ::submitConfigurationForm
EditorBaseTest::testBcWithSubformState public function @covers ::buildConfigurationForm
@covers ::validateConfigurationForm
@covers ::submitConfigurationForm
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 340

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.