function EditorSelectionTest::testTextWysiwyg

Tests a textual field, with text processing, with cardinality 1 and >1, always with an Editor plugin present that supports textual fields with text processing, but with varying text format compatibility.

File

drupal/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php, line 108
Contains \Drupal\edit\Tests\EditorSelectionTest.

Class

EditorSelectionTest
Test in-place field editor selection.

Namespace

Drupal\edit\Tests

Code

function testTextWysiwyg() {

  // Enable edit_test module so that the 'wysiwyg' editor becomes available.
  $this
    ->enableModules(array(
    'edit_test',
  ));
  $field_name = 'field_textarea';
  $this
    ->createFieldWithInstance($field_name, 'text', 1, 'Long text field', array(
    'text_processing' => 1,
  ), 'text_textarea', array(
    'size' => 42,
  ), 'text_default', array());

  // Pretend there is an entity with these items for the field.
  $items = array(
    array(
      'value' => 'Hello, world!',
      'format' => 'filtered_html',
    ),
  );

  // Editor selection w/ cardinality 1, text format w/o associated text editor.
  $this
    ->assertEqual('form', $this
    ->getSelectedEditor($items, $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.
  $items[0]['format'] = 'full_html';
  $this
    ->assertEqual('wysiwyg', $this
    ->getSelectedEditor($items, $field_name), "With cardinality 1, and the full_html text format, the 'wysiwyg' editor is selected.");

  // Editor selection with text processing, cardinality >1
  $this->field_textarea_field['cardinality'] = 2;
  field_update_field($this->field_textarea_field);
  $items[] = array(
    'value' => 'Hallo, wereld!',
    'format' => 'full_html',
  );
  $this
    ->assertEqual('form', $this
    ->getSelectedEditor($items, $field_name), "With cardinality >1, and both items using the full_html text format, the 'form' editor is selected.");
}