TriggeringElementTest.php in Drupal 9
File
core/modules/system/tests/src/FunctionalJavascript/Form/TriggeringElementTest.php
View source
<?php
namespace Drupal\Tests\system\FunctionalJavascript\Form;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class TriggeringElementTest extends WebDriverTestBase {
protected static $modules = [
'form_test',
];
protected $defaultTheme = 'stark';
public function testNoButtonInfoInPost() {
$path = '/form-test/clicked-button';
$form_html_id = 'form-test-clicked-button';
$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.');
$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.');
$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.');
}
public function testAttemptAccessControlBypass() {
$path = 'form-test/clicked-button';
$form_html_id = 'form-test-clicked-button';
$this
->drupalGet($path . '/rs/s');
$page = $this
->getSession()
->getPage();
$input = $page
->find('css', 'input[name="text"]');
$this
->assertNotNull($input, 'text input located.');
$input
->setValue('name', 'button1');
$input
->setValue('value', 'button1');
$this
->xpath('//form[@id="' . $form_html_id . '"]//input[@type="submit"]')[0]
->click();
$this
->assertSession()
->pageTextNotContains('The clicked button is button1.');
$this
->assertSession()
->pageTextContains('The clicked button is button2.');
}
}