You are here

function ManageFieldsTest::cardinalitySettings in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/ManageFieldsTest.php \Drupal\field_ui\Tests\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 core/modules/field_ui/src/Tests/ManageFieldsTest.php
Runs the field CRUD tests.

File

core/modules/field_ui/src/Tests/ManageFieldsTest.php, line 246
Contains \Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\field_ui\Tests

Code

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

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

  // Submit a custom number.
  $edit = array(
    'cardinality' => 'number',
    'cardinality_number' => 6,
  );
  $this
    ->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
  $this
    ->assertText('Updated field Body field settings.');
  $this
    ->drupalGet($field_edit_path);
  $this
    ->assertFieldByXPath("//select[@name='cardinality']", 'number');
  $this
    ->assertFieldByXPath("//input[@name='cardinality_number']", 6);

  // Check that tabs displayed.
  $this
    ->assertLink(t('Edit'));
  $this
    ->assertLinkByHref('admin/structure/types/manage/article/fields/node.article.body');
  $this
    ->assertLink(t('Field settings'));
  $this
    ->assertLinkByHref($field_edit_path);

  // Set to unlimited.
  $edit = array(
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
  );
  $this
    ->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
  $this
    ->assertText('Updated field Body field settings.');
  $this
    ->drupalGet($field_edit_path);
  $this
    ->assertFieldByXPath("//select[@name='cardinality']", FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $this
    ->assertFieldByXPath("//input[@name='cardinality_number']", 1);
}