public function FieldUiTestTrait::fieldUIAddNewField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field_ui/src/Tests/FieldUiTestTrait.php \Drupal\field_ui\Tests\FieldUiTestTrait::fieldUIAddNewField()
Creates a new field through the Field UI.
Parameters
string $bundle_path: Admin path of the bundle that the new field is to be attached to.
string $field_name: The field name of the new field storage.
string $label: (optional) The label of the new field. Defaults to a random string.
string $field_type: (optional) The field type of the new field storage. Defaults to 'test_field'.
array $storage_edit: (optional) $edit parameter for drupalPostForm() on the second step ('Storage settings' form).
array $field_edit: (optional) $edit parameter for drupalPostForm() on the third step ('Field settings' form).
16 calls to FieldUiTestTrait::fieldUIAddNewField()
- CommentNonNodeTest::testCommentFunctionality in core/
modules/ comment/ src/ Tests/ CommentNonNodeTest.php - Tests anonymous comment functionality.
- ContactSitewideTest::testSiteWideContact in core/
modules/ contact/ src/ Tests/ ContactSitewideTest.php - Tests configuration options and the site-wide contact form.
- EntityReferenceAdminTest::createEntityReferenceField in core/
modules/ field/ src/ Tests/ EntityReference/ EntityReferenceAdminTest.php - Creates a new Entity Reference fields with a given target type.
- FieldUIDeleteTest::testDeleteField in core/
modules/ field_ui/ src/ Tests/ FieldUIDeleteTest.php - Tests that deletion removes field storages and fields as expected.
- FileFieldWidgetTest::testPrivateFileComment in core/
modules/ file/ src/ Tests/ FileFieldWidgetTest.php - Tests that download restrictions on private files work on comments.
File
- core/
modules/ field_ui/ src/ Tests/ FieldUiTestTrait.php, line 34 - Contains \Drupal\field_ui\Tests\FieldUiTestTrait.
Class
- FieldUiTestTrait
- Provides common functionality for the Field UI test classes.
Namespace
Drupal\field_ui\TestsCode
public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = array(), array $field_edit = array()) {
$label = $label ?: $this
->randomString();
$initial_edit = array(
'new_storage_type' => $field_type,
'label' => $label,
'field_name' => $field_name,
);
// Allow the caller to set a NULL path in case they navigated to the right
// page before calling this method.
if ($bundle_path !== NULL) {
$bundle_path = "{$bundle_path}/fields/add-field";
}
// First step: 'Add field' page.
$this
->drupalPostForm($bundle_path, $initial_edit, t('Save and continue'));
$this
->assertRaw(t('These settings apply to the %label field everywhere it is used.', array(
'%label' => $label,
)), 'Storage settings page was displayed.');
// Test Breadcrumbs.
$this
->assertLink($label, 0, 'Field label is correct in the breadcrumb of the storage settings page.');
// Second step: 'Storage settings' form.
$this
->drupalPostForm(NULL, $storage_edit, t('Save field settings'));
$this
->assertRaw(t('Updated field %label field settings.', array(
'%label' => $label,
)), 'Redirected to field settings page.');
// Third step: 'Field settings' form.
$this
->drupalPostForm(NULL, $field_edit, t('Save settings'));
$this
->assertRaw(t('Saved %label configuration.', array(
'%label' => $label,
)), 'Redirected to "Manage fields" page.');
// Check that the field appears in the overview form.
$this
->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
}