You are here

public function EditorSelectionTest::testTextWysiwyg in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/quickedit/src/Tests/EditorSelectionTest.php \Drupal\quickedit\Tests\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/src/Tests/EditorSelectionTest.php, line 87
Contains \Drupal\quickedit\Tests\EditorSelectionTest.

Class

EditorSelectionTest
Tests in-place field editor selection.

Namespace

Drupal\quickedit\Tests

Code

public function testTextWysiwyg() {

  // Enable edit_test module so that the 'wysiwyg' editor becomes available.
  $this
    ->enableModules(array(
    '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', array(), 'text_textarea', array(
    'size' => 42,
  ), 'text_default', array());

  // Create an entity with values for this text field.
  $entity = entity_create('entity_test');
  $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
    ->assertEqual('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
    ->assertEqual('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
    ->assertEqual('form', $this
    ->getSelectedEditor($entity
    ->id(), $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}