1 field_ui.test | FieldUIManageFieldsTestCase::testCardinalitySettings() |
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 FormsTestCase::testNumber().
File
- core/
modules/ field_ui/ tests/ field_ui.test, line 308 - Tests for field_ui.module.
Class
- FieldUIManageFieldsTestCase
- Tests the functionality of the 'Manage fields' screen.
Code
function testCardinalitySettings() {
$this->createField();
$field_edit_path = 'admin/structure/types/manage/' . $this->hyphen_type . '/fields/' . $this->field_name;
// Assert the cardinality other field cannot be empty when cardinality is
// set to 'number'.
$edit = array(
'field[cardinality]' => 'number',
'field[cardinality_number]' => '',
);
$this->backdropPost($field_edit_path, $edit, t('Save settings'));
$this->assertText('Number of values is required.');
// Submit a custom number.
$edit = array(
'field[cardinality]' => 'number',
'field[cardinality_number]' => 6,
);
$this->backdropPost($field_edit_path, $edit, t('Save settings'));
$this->assertRaw(format_string('Saved %label configuration.', array('%label' => $this->field_label)), 'Redirected to "Manage fields" page.');
$this->backdropGet($field_edit_path);
$this->assertFieldByXPath("//select[@name='field[cardinality]']", 'number');
$this->assertFieldByXPath("//input[@name='field[cardinality_number]']", 6);
// Set to unlimited.
$edit = array(
'field[cardinality]' => FIELD_CARDINALITY_UNLIMITED,
);
$this->backdropPost($field_edit_path, $edit, t('Save settings'));
$this->assertRaw(format_string('Saved %label configuration.', array('%label' => $this->field_label)), 'Redirected to "Manage fields" page.');
$this->backdropGet($field_edit_path);
$this->assertFieldByXPath("//select[@name='field[cardinality]']", FIELD_CARDINALITY_UNLIMITED);
$this->assertFieldByXPath("//input[@name='field[cardinality_number]']", 1);
}