function FieldUiTestTrait::fieldUIAddExistingField
Same name in other branches
- 9 core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php \Drupal\Tests\field_ui\Traits\FieldUiTestTrait::fieldUIAddExistingField()
- 8.9.x core/modules/field_ui/src/Tests/FieldUiTestTrait.php \Drupal\field_ui\Tests\FieldUiTestTrait::fieldUIAddExistingField()
- 8.9.x core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php \Drupal\Tests\field_ui\Traits\FieldUiTestTrait::fieldUIAddExistingField()
- 10 core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php \Drupal\Tests\field_ui\Traits\FieldUiTestTrait::fieldUIAddExistingField()
Adds an existing field through the Field UI.
Parameters
string $bundle_path: Admin path of the bundle that the field is to be attached to.
string $existing_storage_name: The name of the existing field storage for which we want to add a new field.
string $label: (optional) The label of the new field. Defaults to a random string.
array $field_edit: (optional) $edit parameter for submitForm() on the second step ('Field settings' form).
6 calls to FieldUiTestTrait::fieldUIAddExistingField()
- FieldUIDeleteTest::testDeleteField in core/
modules/ field_ui/ tests/ src/ Functional/ FieldUIDeleteTest.php - Tests that deletion removes field storages and fields as expected.
- ManageFieldsFunctionalTest::testTranslationDefaults in core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsFunctionalTest.php - Test translation defaults.
- ManageFieldsLifecycleTest::addExistingField in core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsLifecycleTest.php - Tests adding an existing field in another content type.
- ManageFieldsLifecycleTest::addPersistentFieldStorage in core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsLifecycleTest.php - Tests that persistent field storage appears in the field UI.
- ManageFieldsMultipleTypesTest::testReuseField in core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsMultipleTypesTest.php - Tests that options are copied over when reusing a field.
File
-
core/
modules/ field_ui/ tests/ src/ Traits/ FieldUiTestTrait.php, line 125
Class
- FieldUiTestTrait
- Provides common functionality for the Field UI test classes.
Namespace
Drupal\Tests\field_ui\TraitsCode
public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = []) {
$label = $label ?: $this->randomMachineName();
$field_edit['edit-label'] = $label;
// First step: navigate to the re-use field page.
$this->drupalGet("{$bundle_path}/fields/");
// Confirm that the local action is visible.
$this->assertSession()
->linkExists('Re-use an existing field');
$this->clickLink('Re-use an existing field');
$this->assertSession()
->elementExists('css', "input[value=Re-use][name={$existing_storage_name}]");
$this->click("input[value=Re-use][name={$existing_storage_name}]");
// Set the main content to only the content region because the label can
// contain HTML which will be auto-escaped by Twig.
$this->assertSession()
->responseContains('field-config-edit-form');
// Check that the page does not have double escaped HTML tags.
$this->assertSession()
->responseNotContains('<');
// Second step: 'Field settings' form.
$this->submitForm($field_edit, 'Save settings');
$this->assertSession()
->pageTextContains("Saved {$label} configuration.");
// Check that the field appears in the overview form.
$xpath = $this->assertSession()
->buildXPathQuery("//table[@id=\"field-overview\"]//tr/td[1 and text() = :label]", [
':label' => $label,
]);
$this->assertSession()
->elementExists('xpath', $xpath);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.