function ValidatorsTest::test

Same name in other branches
  1. 9 core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php \Drupal\Tests\ckeditor5\Kernel\ValidatorsTest::test()
  2. 11.x core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php \Drupal\Tests\ckeditor5\Kernel\ValidatorsTest::test()

@covers \Drupal\ckeditor5\Plugin\Validation\Constraint\CKEditor5ElementConstraintValidator @covers \Drupal\ckeditor5\Plugin\Validation\Constraint\StyleSensibleElementConstraintValidator @covers \Drupal\ckeditor5\Plugin\Validation\Constraint\UniqueLabelInListConstraintValidator @dataProvider provider

Parameters

array $ckeditor5_settings: The CKEditor 5 settings to test.

array $expected_violations: All expected violations for the given CKEditor 5 settings, with property path as keys and message as values.

File

core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php, line 75

Class

ValidatorsTest
@covers \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemConstraintValidator @covers \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemDependencyConstraintValidator @covers…

Namespace

Drupal\Tests\ckeditor5\Kernel

Code

public function test(array $ckeditor5_settings, array $expected_violations) : void {
    // The data provider is unable to access services, so the test scenario of
    // testing with CKEditor 5's default settings is partially provided here.
    if ($ckeditor5_settings === [
        '__DEFAULT__',
    ]) {
        $ckeditor5_settings = \Drupal::service('plugin.manager.editor')->createInstance('ckeditor5')
            ->getDefaultSettings();
    }
    FilterFormat::create([
        'format' => 'dummy',
        'name' => 'Dummy',
    ])->save();
    $editor = Editor::create([
        'format' => 'dummy',
        'editor' => 'ckeditor5',
        'settings' => $ckeditor5_settings,
        'image_upload' => [
            'status' => FALSE,
        ],
    ]);
    $typed_config = $this->typedConfig
        ->createFromNameAndData($editor->getConfigDependencyName(), $editor->toArray());
    $violations = $typed_config->validate();
    $actual_violations = self::violationsToArray($violations);
    $this->assertSame($expected_violations, self::violationsToArray($violations));
    if (empty($expected_violations)) {
        $this->assertConfigSchema($this->typedConfig, $editor->getConfigDependencyName(), $typed_config->getValue());
    }
}

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