function SelectOrOtherTestBase::testEmptyOption in Select (or other) 7.3
Make sure an empty option is present when relevant.
3 calls to SelectOrOtherTestBase::testEmptyOption()
- SelectOrOtherNumberTestCase::testEmptyOption in tests/
select_or_other_number.test - Make sure an empty option is present when relevant.
- SelectOrOtherTaxonomyTestCase::testEmptyOption in modules/
select_or_other_taxonomy/ tests/ select_or_other_taxonomy.test - Make sure an empty option is present when relevant.
- SelectOrOtherTextTestCase::testEmptyOption in tests/
select_or_other_text.test - Make sure an empty option is present when relevant.
3 methods override SelectOrOtherTestBase::testEmptyOption()
- SelectOrOtherNumberTestCase::testEmptyOption in tests/
select_or_other_number.test - Make sure an empty option is present when relevant.
- SelectOrOtherTaxonomyTestCase::testEmptyOption in modules/
select_or_other_taxonomy/ tests/ select_or_other_taxonomy.test - Make sure an empty option is present when relevant.
- SelectOrOtherTextTestCase::testEmptyOption in tests/
select_or_other_text.test - Make sure an empty option is present when relevant.
File
- tests/
SelectOrOtherTestBase.test, line 90 - Contains SelectOrOtherTestBase.
Class
- SelectOrOtherTestBase
- Class SelectOrOtherTestBase Base class for select_or_other testing.
Code
function testEmptyOption($other_option = '') {
foreach ($this->fields as $field_name => $field) {
$this
->drupalGet('node/add/' . $this
->getFieldContentType($field_name));
$type = $this
->getWidgetType($field_name);
$multiple = $field['cardinality'] !== 1;
$required = $field['instance_settings']['required'];
// First test empty behaviour. Only single select boxes should always have
// an empty value.
if ($type === 'select' && !$multiple) {
if ($required) {
$this
->assertText(t('- Select -'));
}
else {
$this
->assertText(t('- None -'));
}
}
else {
$this
->assertNoText(t('- Select -'));
$this
->assertNoText(t('- None -'));
}
// Test non-empty behaviour. Once again only single cardinality elements
// should have empty options to allow for the removal of values if the
// field is not required.
if ($other_option !== '') {
// We set the other option, because we can set that in the same way
// always.
$this
->setFieldValue($field_name, 'select_or_other', $other_option);
$this
->clickLink(t('Edit'));
if (!$multiple && !$required) {
$this
->assertText(t('- None -'));
}
else {
$this
->assertNoText(t('- Select -'));
$this
->assertNoText(t('- None -'));
}
}
else {
$this
->fail('No $other_option provided, this test should be overridden and calling itself from individual test classes.');
}
}
}