function ManageDisplayTest::fieldUIAddNewField

Same name and namespace in other branches
  1. 8.9.x core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php \Drupal\Tests\field_ui\FunctionalJavascript\ManageDisplayTest::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'.

2 calls to ManageDisplayTest::fieldUIAddNewField()
ManageDisplayTest::testFormatterUI in core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
Tests formatter settings.
ManageDisplayTest::testWidgetUI in core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php
Tests widget settings.

File

core/modules/field_ui/tests/src/FunctionalJavascript/ManageDisplayTest.php, line 434

Class

ManageDisplayTest
Tests the Field UI "Manage display" and "Manage form display" screens.

Namespace

Drupal\Tests\field_ui\FunctionalJavascript

Code

public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field') {
    $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";
    }
    // First step: 'Add field' page.
    $this->drupalGet($bundle_path);
    $session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();
    $field_new_storage_type = $page->findField('new_storage_type');
    $field_new_storage_type->setValue($field_type);
    $assert_session->assertWaitOnAjaxRequest();
    $field_label = $page->findField('label');
    $this->assertTrue($field_label->isVisible());
    $field_label->setValue($label);
    $machine_name = $assert_session->waitForElementVisible('css', '[name="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);
    $assert_session->assertWaitOnAjaxRequest();
    $page->findButton('Save and continue')
        ->click();
    $assert_session->pageTextContains("These settings apply to the {$label} field everywhere it is used.");
    $breadcrumb_link = $page->findLink($label);
    // Test breadcrumb.
    $this->assertTrue($breadcrumb_link->isVisible());
    // Second step: 'Storage settings' form.
    $page->findButton('Save field settings')
        ->click();
    $assert_session->pageTextContains("Updated field {$label} field settings.");
    // Third step: 'Field settings' form.
    $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.