You are here

public function EditorSelectionTest::testText in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/quickedit/tests/src/Kernel/EditorSelectionTest.php \Drupal\Tests\quickedit\Kernel\EditorSelectionTest::testText()

Tests a string (plain text) field, with cardinality 1 and >1.

File

core/modules/quickedit/tests/src/Kernel/EditorSelectionTest.php, line 53

Class

EditorSelectionTest
Tests in-place field editor selection.

Namespace

Drupal\Tests\quickedit\Kernel

Code

public function testText() {
  $field_name = 'field_text';
  $this
    ->createFieldWithStorage($field_name, 'string', 1, 'Simple text field', [], 'string_textfield', [
    'size' => 42,
  ], 'string', []);

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

  // With cardinality 1.
  $this
    ->assertEqual('plain_text', $this
    ->getSelectedEditor($entity
    ->id(), $field_name), "With cardinality 1, the 'plain_text' editor is selected.");

  // With cardinality >1
  $this->fields->field_text_field_storage
    ->setCardinality(2);
  $this->fields->field_text_field_storage
    ->save();
  $this
    ->assertEqual('form', $this
    ->getSelectedEditor($entity
    ->id(), $field_name), "With cardinality >1, the 'form' editor is selected.");
}