class CKEditor5Test

Same name in this branch
  1. 9 core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test
Same name in other branches
  1. 10 core/modules/ckeditor5/tests/src/Unit/CKEditor5Test.php \Drupal\Tests\ckeditor5\Unit\CKEditor5Test
  2. 10 core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test
  3. 11.x core/modules/ckeditor5/tests/src/Unit/CKEditor5Test.php \Drupal\Tests\ckeditor5\Unit\CKEditor5Test
  4. 11.x core/modules/ckeditor5/tests/src/FunctionalJavascript/CKEditor5Test.php \Drupal\Tests\ckeditor5\FunctionalJavascript\CKEditor5Test

@coversDefaultClass \Drupal\ckeditor5\Plugin\Editor\CKEditor5 @group ckeditor5 @internal

Hierarchy

Expanded class hierarchy of CKEditor5Test

File

core/modules/ckeditor5/tests/src/Unit/CKEditor5Test.php, line 16

Namespace

Drupal\Tests\ckeditor5\Unit
View source
class CKEditor5Test extends UnitTestCase {
    use PrivateMethodUnitTestTrait;
    
    /**
     * Simulated CKEditor5::buildConfigurationForm() form structure.
     *
     * @var array
     */
    protected const SIMULATED_FORM_STRUCTURE = [
        'toolbar' => [
            'available' => [],
            'items' => [],
        ],
        'available_items_description' => [],
        'active_items_description' => [],
        'plugin_settings' => [],
        'plugins' => [
            'providerA_plugin1' => [],
            'providerB_plugin2' => [
                'foo' => [],
                'bar' => [],
            ],
        ],
    ];
    
    /**
     * @covers \Drupal\ckeditor5\Plugin\Editor\CKEditor5::mapViolationPropertyPathsToFormNames
     * @dataProvider providerPathsToFormNames
     */
    public function testPathsToFormNames(string $property_path, string $expected_form_item_name, bool $expect_exception = FALSE) : void {
        $mapMethod = self::getMethod(CKEditor5::class, 'mapViolationPropertyPathsToFormNames');
        if ($expect_exception) {
            $this->expectExceptionMessage('assert($shifted === \'settings\')');
        }
        $form_item_name = $mapMethod->invokeArgs(NULL, [
            $property_path,
            static::SIMULATED_FORM_STRUCTURE,
        ]);
        if (!$expect_exception) {
            $this->assertSame($expected_form_item_name, $form_item_name);
        }
    }
    
    /**
     * Data provider for testing mapViolationPropertyPathsToFormNames.
     *
     * @return array[]
     *   An array with the property path and expected form item name.
     */
    public function providerPathsToFormNames() : array {
        return [
            'validation error targeting toolbar items' => [
                'settings.toolbar.items',
                'settings][toolbar][items',
            ],
            'validation error targeting a specific toolbar item' => [
                'settings.toolbar.items.6',
                'settings][toolbar][items',
            ],
            'validation error targeting a simple plugin form' => [
                'settings.plugins.providerA_plugin1',
                'settings][plugins][providerA_plugin1',
            ],
            'validation error targeting a simple plugin form, with deep config schema detail' => [
                'settings.plugins.providerA_plugin1.foo.bar.baz',
                'settings][plugins][providerA_plugin1',
            ],
            'validation error targeting a complex plugin form' => [
                'settings.plugins.providerB_plugin2',
                'settings][plugins][providerB_plugin2',
            ],
            'validation error targeting a complex plugin form, with deep config schema detail' => [
                'settings.plugins.providerB_plugin2.foo.bar.baz',
                'settings][plugins][providerB_plugin2][foo',
            ],
            'unrealistic example one — should trigger exception' => [
                'bad.bad.worst',
                'I DO NOT EXIST',
                TRUE,
            ],
            'unrealistic example two — should trigger exception' => [
                'one.two.three.four',
                'one][two][three][four',
                TRUE,
            ],
        ];
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
CKEditor5Test::providerPathsToFormNames public function Data provider for testing mapViolationPropertyPathsToFormNames.
CKEditor5Test::SIMULATED_FORM_STRUCTURE protected constant Simulated CKEditor5::buildConfigurationForm() form structure.
CKEditor5Test::testPathsToFormNames public function @covers \Drupal\ckeditor5\Plugin\Editor\CKEditor5::mapViolationPropertyPathsToFormNames
@dataProvider providerPathsToFormNames
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
PrivateMethodUnitTestTrait::getMethod protected static function Gets a protected/private method to test.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
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 338
UnitTestCase::setUpBeforeClass public static function

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