1 field_ui.test | FieldUITestCase::fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) |
Creates a new field through the Field UI.
Parameters
$bundle_path: Admin path of the bundle that the new field is to be attached to.
$initial_edit: $edit parameter for backdropPost() on the first step ('Manage fields' screen).
$field_edit: $edit parameter for backdropPost() on the second step ('Field settings' form).
$instance_edit: $edit parameter for backdropPost() on the third step ('Instance settings' form).
File
- core/
modules/ field_ui/ tests/ field_ui.test, line 55 - Tests for field_ui.module.
Class
- FieldUITestCase
- Provides common functionality for the Field UI test classes.
Code
function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
// Use 'test_field' field type by default.
$initial_edit += array(
'fields[_add_new_field][type]' => 'test_field',
'fields[_add_new_field][widget_type]' => 'test_field_widget',
);
$label = $initial_edit['fields[_add_new_field][label]'];
$field_name = $initial_edit['fields[_add_new_field][field_name]'];
// First step : 'Add new field' on the 'Manage fields' page.
$this->backdropPost("$bundle_path/fields", $initial_edit, t('Save'));
// Second step : 'Field settings' form.
if (state_get('field_ui_test_field_settings', TRUE)) {
$this->assertRaw(format_string('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), 'Field settings page was displayed.');
$this->backdropPost(NULL, $field_edit, t('Save field settings'));
$this->assertRaw(format_string('Updated field %label field settings.', array('%label' => $label)), 'Redirected to instance and widget settings page.');
}
// Second step is skipped if the field has no settings.
else {
$this->assertNoRaw(format_string('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), 'Field settings page was skipped because it had no settings.');
}
// Third step : 'Instance settings' form.
$this->assertRaw(format_string('These settings apply only to the %field field', array('%field' => $label)), 'Field instance settings page was displayed.');
$this->backdropPost(NULL, $instance_edit, t('Save settings'));
$this->assertRaw(format_string('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.');
// Check that the field appears in the overview form.
$this->assertLinkByHref("$bundle_path/fields/field_$field_name", 0, 'Field was created and appears in the overview page.');
}