You are here

public function EditorSelectionTest::testNumber 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::testNumber()

Tests a number field, with cardinality 1 and >1.

File

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

Class

EditorSelectionTest
Tests in-place field editor selection.

Namespace

Drupal\Tests\quickedit\Kernel

Code

public function testNumber() {
  $field_name = 'field_nr';
  $this
    ->createFieldWithStorage($field_name, 'integer', 1, 'Simple number field', [], 'number', [], 'number_integer', []);

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

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

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