function FieldUiJSTestTrait::fieldUIAddNewFieldJS
Same name in other branches
- 10 core/modules/field_ui/tests/src/Traits/FieldUiJSTestTrait.php \Drupal\Tests\field_ui\Traits\FieldUiJSTestTrait::fieldUIAddNewFieldJS()
Creates a new field through the Field UI.
Parameters
string|null $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|null $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'.
bool $save_settings: (optional) Parameter for conditional execution of second and third step (Saving the storage settings and field settings). Defaults to 'TRUE'.
Throws
\Behat\Mink\Exception\ElementNotFoundException
9 calls to FieldUiJSTestTrait::fieldUIAddNewFieldJS()
- DefaultValueWidgetTest::testDefaultValueOptionsForChangingBundles in core/
modules/ field_ui/ tests/ src/ FunctionalJavascript/ DefaultValueWidgetTest.php - Tests default value options on field config change.
- EntityReferenceAdminTest::testFieldAdminHandler in core/
modules/ field/ tests/ src/ FunctionalJavascript/ EntityReference/ EntityReferenceAdminTest.php - Tests the Entity Reference Admin UI.
- ManageDisplayTest::testFormatterUI in core/
modules/ field_ui/ tests/ src/ FunctionalJavascript/ ManageDisplayTest.php - Tests formatter settings.
- ManageDisplayTest::testNotAppliedUntilSavedWarning in core/
modules/ field_ui/ tests/ src/ FunctionalJavascript/ ManageDisplayTest.php - Confirms that notifications to save appear when necessary.
- ManageDisplayTest::testWidgetUI in core/
modules/ field_ui/ tests/ src/ FunctionalJavascript/ ManageDisplayTest.php - Tests widget settings.
File
-
core/
modules/ field_ui/ tests/ src/ Traits/ FieldUiJSTestTrait.php, line 30
Class
- FieldUiJSTestTrait
- Provides common functionality for the Field UI tests that depend on JS.
Namespace
Drupal\Tests\field_ui\TraitsCode
public function fieldUIAddNewFieldJS(?string $bundle_path, string $field_name, ?string $label = NULL, string $field_type = 'test_field', bool $save_settings = TRUE) : void {
$label = $label ?: $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";
$this->drupalGet($bundle_path);
}
// First step: 'Add field' page.
$session = $this->getSession();
$page = $session->getPage();
$assert_session = $this->assertSession();
if ($assert_session->waitForElementVisible('css', "[name='new_storage_type'][value='{$field_type}']")) {
$page = $this->getSession()
->getPage();
$field_card = $page->find('css', "[name='new_storage_type'][value='{$field_type}']")
->getParent();
}
else {
$field_card = $this->getFieldFromGroupJS($field_type);
}
$field_card?->click();
$page->findButton('Continue')
->click();
$field_label = $page->findField('edit-label');
$this->assertTrue($field_label->isVisible());
$field_label = $page->find('css', 'input[data-drupal-selector="edit-label"]');
$field_label->setValue($label);
$machine_name = $assert_session->waitForElementVisible('css', '[data-drupal-selector="edit-label"] + * .machine-name-value');
$this->assertNotEmpty($machine_name);
$page->findButton('Edit')
->press();
$field_field_name = $page->findField('field_name');
$this->assertTrue($field_field_name->isVisible());
$field_field_name->setValue($field_name);
$page->findButton('Continue')
->click();
$assert_session->waitForText("These settings apply to the {$label} field everywhere it is used.");
if ($save_settings) {
// Second step: Save field settings.
$page->findButton('Save settings')
->click();
$assert_session->pageTextContains("Saved {$label} configuration.");
// Check that the field appears in the overview form.
$row = $page->find('css', '#field-' . $field_name);
$this->assertNotEmpty($row, 'Field was created and appears in the overview page.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.