function ValidatorsTest::testPair
Same name in other branches
- 9 core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php \Drupal\Tests\ckeditor5\Kernel\ValidatorsTest::testPair()
- 11.x core/modules/ckeditor5/tests/src/Kernel/ValidatorsTest.php \Drupal\Tests\ckeditor5\Kernel\ValidatorsTest::testPair()
@covers \Drupal\ckeditor5\Plugin\Validation\Constraint\SourceEditingPreventSelfXssConstraintValidator @dataProvider providerPair
Parameters
array $ckeditor5_settings: The paired text editor's CKEditor 5 settings to test.
array $editor_image_upload_settings: The paired text editor's image upload settings to test.
array $filters: The paired text format's filters and filter settings.
array $expected_violations: All expected violations for the pair.
File
-
core/
modules/ ckeditor5/ tests/ src/ Kernel/ ValidatorsTest.php, line 658
Class
- ValidatorsTest
- @covers \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemConstraintValidator @covers \Drupal\ckeditor5\Plugin\Validation\Constraint\ToolbarItemDependencyConstraintValidator @covers…
Namespace
Drupal\Tests\ckeditor5\KernelCode
public function testPair(array $ckeditor5_settings, array $editor_image_upload_settings, array $filters, array $expected_violations) : void {
$text_editor = Editor::create([
'format' => 'dummy',
'editor' => 'ckeditor5',
'settings' => $ckeditor5_settings,
'image_upload' => $editor_image_upload_settings,
]);
EntityViewMode::create([
'id' => 'media.view_mode_1',
'targetEntityType' => 'media',
'status' => TRUE,
'enabled' => TRUE,
'label' => 'View Mode 1',
])->save();
EntityViewMode::create([
'id' => 'media.view_mode_2',
'targetEntityType' => 'media',
'status' => TRUE,
'enabled' => TRUE,
'label' => 'View Mode 2',
])->save();
assert($text_editor instanceof EditorInterface);
$text_format = FilterFormat::create([
'filters' => $filters,
]);
assert($text_format instanceof FilterFormatInterface);
// TRICKY: because we're validating using `editor.editor.*` as the config
// name, TextEditorObjectDependentValidatorTrait will load the stored
// filter format. That has not yet been updated at this point, so in order
// for validation to pass, it must first be saved.
// @see \Drupal\ckeditor5\Plugin\Validation\Constraint\TextEditorObjectDependentValidatorTrait::createTextEditorObjectFromContext()
// @todo Remove this work-around in https://www.drupal.org/project/drupal/issues/3231354
$text_format->set('format', $text_editor->id())
->set('name', $this->randomString())
->save();
// TRICKY: only assert config schema (and validation constraints) if we
// expect NO violations: when violations are expected, this would just find
// the very violations that the next assertion is checking.
if (empty($expected_violations)) {
$this->assertConfigSchema($this->typedConfig, $text_editor->getConfigDependencyName(), $text_editor->toArray());
}
$this->assertSame($expected_violations, $this->validatePairToViolationsArray($text_editor, $text_format, TRUE));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.