function UiHelperTrait::submitForm
Same name in other branches
- 9 core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::submitForm()
- 8.9.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::submitForm()
- 11.x core/tests/Drupal/Tests/UiHelperTrait.php \Drupal\Tests\UiHelperTrait::submitForm()
Fills and submits a form.
Parameters
array $edit: Field data in an associative array. Changes the current input fields (where possible) to the values indicated.
A checkbox can be set to TRUE to be checked and should be set to FALSE to be unchecked.
string $submit: Value of the submit button whose click is to be emulated. For example, 'Save'. The processing of the request depends on this value. For example, a form may have one button with the value 'Save' and another button with the value 'Delete', and execute different code depending on which one is clicked.
string $form_html_id: (optional) HTML ID of the form to be submitted. On some pages there are many identical forms, so just using the value of the submit button is not enough. For example: 'trigger-node-presave-assign-form'. Note that this is not the Drupal $form_id, but rather the HTML ID of the form, which is typically the same thing but with hyphens replacing the underscores.
1136 calls to UiHelperTrait::submitForm()
- AccessDeniedTest::testAccessDenied in core/
modules/ system/ tests/ src/ Functional/ System/ AccessDeniedTest.php - AccessRoleUITest::testAccessRoleUI in core/
modules/ user/ tests/ src/ Functional/ AccessRoleUITest.php - Tests the role access plugin UI.
- AnalyzeTest::testAnalyzeBasic in core/
modules/ views_ui/ tests/ src/ Functional/ AnalyzeTest.php - Tests that analyze works in general.
- ArbitraryRebuildTest::testUserRegistrationMultipleField in core/
modules/ system/ tests/ src/ Functional/ Form/ ArbitraryRebuildTest.php - Tests a rebuild caused by a multiple value field.
- ArbitraryRebuildTest::testUserRegistrationRebuild in core/
modules/ system/ tests/ src/ Functional/ Form/ ArbitraryRebuildTest.php - Tests a basic rebuild with the user registration form.
File
-
core/
tests/ Drupal/ Tests/ UiHelperTrait.php, line 73
Class
- UiHelperTrait
- Provides UI helper methods.
Namespace
Drupal\TestsCode
protected function submitForm(array $edit, $submit, $form_html_id = NULL) {
$assert_session = $this->assertSession();
// Get the form.
if (isset($form_html_id)) {
$form = $assert_session->elementExists('xpath', "//form[@id='{$form_html_id}']");
$submit_button = $assert_session->buttonExists($submit, $form);
$action = $form->getAttribute('action');
}
else {
$submit_button = $assert_session->buttonExists($submit);
$form = $assert_session->elementExists('xpath', './ancestor::form', $submit_button);
$action = $form->getAttribute('action');
}
// Edit the form values.
foreach ($edit as $name => $value) {
$field = $assert_session->fieldExists($name, $form);
$value = match ($field->getAttribute('type')) { 'checkbox' => (bool) $value,
'text', 'number', 'radio' => (string) $value,
default => $value,
};
$field->setValue($value);
}
// Submit form.
$this->prepareRequest();
$submit_button->press();
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
// Check if there are any meta refresh redirects (like Batch API pages).
if ($this->checkForMetaRefresh()) {
// We are finished with all meta refresh redirects, so reset the counter.
$this->metaRefreshCount = 0;
}
// Log only for WebDriverTestBase tests because for tests using
// DrupalTestBrowser we log with ::getResponseLogHandler.
if ($this->htmlOutputEnabled && !$this->isTestUsingGuzzleClient()) {
$out = $this->getSession()
->getPage()
->getContent();
$html_output = 'POST request to: ' . $action . '<hr />Ending URL: ' . $this->getSession()
->getCurrentUrl();
$html_output .= '<hr />' . $out;
$html_output .= $this->getHtmlOutputHeaders();
$this->htmlOutput($html_output);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.