function ManageFieldsTest::cardinalitySettings

Tests the cardinality settings of a field.

We do not test if the number can be submitted with anything else than a numeric value. That is tested already in FormTest::testNumber().

1 call to ManageFieldsTest::cardinalitySettings()
ManageFieldsTest::testCRUDFields in drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
Runs the field CRUD tests.

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php, line 172
Definition of Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the functionality of the 'Manage fields' screen.

Namespace

Drupal\field_ui\Tests

Code

function cardinalitySettings() {
  $field_edit_path = 'admin/structure/types/manage/article/fields/body';

  // Assert the cardinality other field cannot be empty when cardinality is
  // set to other.
  $edit = array(
    'field[container][cardinality]' => 'other',
    'field[container][cardinality_other]' => '',
  );
  $this
    ->drupalPost($field_edit_path, $edit, t('Save settings'));
  $this
    ->assertText('Number of values is required.');

  // Assert the cardinality field is set to 'Other' when the value is greater
  // than 5.
  $edit = array(
    'field[container][cardinality]' => 'other',
    'field[container][cardinality_other]' => 16,
  );
  $this
    ->drupalPost($field_edit_path, $edit, t('Save settings'));
  $this
    ->assertText('Saved Body configuration.');
  $this
    ->drupalGet($field_edit_path);
  $this
    ->assertFieldByXPath("//select[@name='field[container][cardinality]']", 'other');
  $this
    ->assertFieldByXPath("//input[@name='field[container][cardinality_other]']", 16);

  // Assert the cardinality other field is set back to 6 after changing the
  // cardinality to less than 6.
  $edit = array(
    'field[container][cardinality]' => 3,
    'field[container][cardinality_other]' => 16,
  );
  $this
    ->drupalPost($field_edit_path, $edit, t('Save settings'));
  $this
    ->assertText('Saved Body configuration.');
  $this
    ->drupalGet($field_edit_path);
  $this
    ->assertFieldByXPath("//select[@name='field[container][cardinality]']", 3);
  $this
    ->assertFieldByXPath("//input[@name='field[container][cardinality_other]']", 6);
}