public function TriggeringElementTest::testNoButtonInfoInPost in Drupal 10
Same name and namespace in other branches
- 8 core/modules/system/tests/src/FunctionalJavascript/Form/TriggeringElementTest.php \Drupal\Tests\system\FunctionalJavascript\Form\TriggeringElementTest::testNoButtonInfoInPost()
- 9 core/modules/system/tests/src/FunctionalJavascript/Form/TriggeringElementTest.php \Drupal\Tests\system\FunctionalJavascript\Form\TriggeringElementTest::testNoButtonInfoInPost()
Tests the triggering element when no button information is included.
Test the determination of the triggering element when no button information is included in the POST data, as is sometimes the case when the ENTER key is pressed in a textfield in Internet Explorer.
File
- core/
modules/ system/ tests/ src/ FunctionalJavascript/ Form/ TriggeringElementTest.php, line 31
Class
- TriggeringElementTest
- Tests that FAPI correctly determines the triggering element.
Namespace
Drupal\Tests\system\FunctionalJavascript\FormCode
public function testNoButtonInfoInPost() {
$path = '/form-test/clicked-button';
$form_html_id = 'form-test-clicked-button';
// Ensure submitting a form with no buttons results in no triggering element
// and the form submit handler not running.
$this
->drupalGet($path);
$assert_session = $this
->assertSession();
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('There is no clicked button.');
$assert_session
->pageTextNotContains('Submit handler for form_test_clicked_button executed.');
// Ensure submitting a form with one or more submit buttons results in the
// triggering element being set to the first one the user has access to. An
// argument with 'r' in it indicates a restricted (#access=FALSE) button.
$this
->drupalGet($path . '/s');
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('The clicked button is button1.');
$assert_session
->pageTextContains('Submit handler for form_test_clicked_button executed.');
$this
->drupalGet($path . '/s/s');
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('The clicked button is button1.');
$assert_session
->pageTextContains('Submit handler for form_test_clicked_button executed.');
$this
->drupalGet($path . '/rs/s');
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('The clicked button is button2.');
$assert_session
->pageTextContains('Submit handler for form_test_clicked_button executed.');
// Ensure submitting a form with buttons of different types results in the
// triggering element being set to the first button, regardless of type. For
// the FAPI 'button' type, this should result in the submit handler not
// executing. The types are 's' (submit), 'b' (button), and 'i'
// (image_button).
$this
->drupalGet($path . '/s/b/i');
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('The clicked button is button1.');
$assert_session
->pageTextContains('Submit handler for form_test_clicked_button executed.');
$this
->drupalGet($path . '/b/s/i');
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('The clicked button is button1.');
$assert_session
->pageTextNotContains('Submit handler for form_test_clicked_button executed.');
$this
->drupalGet($path . '/i/s/b');
$this
->getSession()
->getDriver()
->submitForm('//form[@id="' . $form_html_id . '"]');
$assert_session
->pageTextContains('The clicked button is button1.');
$assert_session
->pageTextContains('Submit handler for form_test_clicked_button executed.');
}