public function EditorSelectionTest::testTextWysiwyg in Drupal 9
Same name and namespace in other branches
- 8 core/modules/quickedit/tests/src/Kernel/EditorSelectionTest.php \Drupal\Tests\quickedit\Kernel\EditorSelectionTest::testTextWysiwyg()
Tests a textual field, with text filtering, with cardinality 1 and >1, always with an Editor plugin present that supports textual fields with text filtering, but with varying text format compatibility.
File
- core/
modules/ quickedit/ tests/ src/ Kernel/ EditorSelectionTest.php, line 87
Class
- EditorSelectionTest
- Tests in-place field editor selection.
Namespace
Drupal\Tests\quickedit\KernelCode
public function testTextWysiwyg() {
// Enable edit_test module so that the 'wysiwyg' editor becomes available.
$this
->enableModules([
'quickedit_test',
]);
$this->editorManager = $this->container
->get('plugin.manager.quickedit.editor');
$this->editorSelector = new EditorSelector($this->editorManager, $this->container
->get('plugin.manager.field.formatter'));
$field_name = 'field_textarea';
$this
->createFieldWithStorage($field_name, 'text', 1, 'Long text field', [], 'text_textarea', [
'size' => 42,
], 'text_default', []);
// Create an entity with values for this text field.
$entity = EntityTest::create();
$entity->{$field_name}->value = 'Hello, world!';
$entity->{$field_name}->format = 'filtered_html';
$entity
->save();
// Editor selection w/ cardinality 1, text format w/o associated text editor.
$this
->assertEquals('form', $this
->getSelectedEditor($entity
->id(), $field_name), "With cardinality 1, and the filtered_html text format, the 'form' editor is selected.");
// Editor selection w/ cardinality 1, text format w/ associated text editor.
$entity->{$field_name}->format = 'full_html';
$entity
->save();
$this
->assertEquals('wysiwyg', $this
->getSelectedEditor($entity
->id(), $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected.");
// Editor selection with text field, cardinality >1.
$this->fields->field_textarea_field_storage
->setCardinality(2);
$this->fields->field_textarea_field_storage
->save();
$this
->assertEquals('form', $this
->getSelectedEditor($entity
->id(), $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}