You are here

public function EditorIntegrationTest::testEditorSelection in Drupal 9

Tests editor selection when the Editor module is present.

Tests a textual field, with text filtering, with cardinality 1 and >1, always with a ProcessedTextEditor plug-in present, but with varying text format compatibility.

File

core/modules/quickedit/tests/src/Kernel/EditorIntegrationTest.php, line 140

Class

EditorIntegrationTest
Tests Edit module integration (Editor module's inline editing support).

Namespace

Drupal\Tests\quickedit\Kernel

Code

public function testEditorSelection() {
  $this->editorManager = $this->container
    ->get('plugin.manager.quickedit.editor');
  $this->editorSelector = $this->container
    ->get('quickedit.editor.selector');

  // Create an entity with values for this text field.
  $entity = EntityTest::create();
  $entity->{$this->fieldName}->value = 'Hello, world!';
  $entity->{$this->fieldName}->format = 'filtered_html';
  $entity
    ->save();

  // Editor selection w/ cardinality 1, text format w/o associated text editor.
  $this
    ->assertEquals('form', $this
    ->getSelectedEditor($entity
    ->id(), $this->fieldName), "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->{$this->fieldName}->format = 'full_html';
  $entity
    ->save();
  $this
    ->assertEquals('editor', $this
    ->getSelectedEditor($entity
    ->id(), $this->fieldName), "With cardinality 1, and the full_html text format, the 'editor' editor is selected.");

  // Editor selection with text processing, cardinality >1
  $this->fields->field_textarea_field_storage
    ->setCardinality(2);
  $this->fields->field_textarea_field_storage
    ->save();
  $this
    ->assertEquals('form', $this
    ->getSelectedEditor($entity
    ->id(), $this->fieldName), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}