View source
<?php
namespace Drupal\system\Tests\Form;
use Drupal\simpletest\WebTestBase;
class TriggeringElementTest extends WebTestBase {
public static $modules = array(
'form_test',
);
function testNoButtonInfoInPost() {
$path = 'form-test/clicked-button';
$edit = array();
$form_html_id = 'form-test-clicked-button';
$this
->drupalPostForm($path, $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('There is no clicked button.', '$form_state->getTriggeringElement() set to NULL.');
$this
->assertNoText('Submit handler for form_test_clicked_button executed.', 'Form submit handler did not execute.');
$this
->drupalPostForm($path . '/s', $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to only button.');
$this
->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.');
$this
->drupalPostForm($path . '/s/s', $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.');
$this
->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.');
$this
->drupalPostForm($path . '/rs/s', $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('The clicked button is button2.', '$form_state->getTriggeringElement() set to first available button.');
$this
->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.');
$this
->drupalPostForm($path . '/s/b/i', $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.');
$this
->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.');
$this
->drupalPostForm($path . '/b/s/i', $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.');
$this
->assertNoText('Submit handler for form_test_clicked_button executed.', 'Form submit handler did not execute.');
$this
->drupalPostForm($path . '/i/s/b', $edit, NULL, array(), array(), $form_html_id);
$this
->assertText('The clicked button is button1.', '$form_state->getTriggeringElement() set to first button.');
$this
->assertText('Submit handler for form_test_clicked_button executed.', 'Form submit handler executed.');
}
function testAttemptAccessControlBypass() {
$path = 'form-test/clicked-button';
$form_html_id = 'form-test-clicked-button';
$this
->drupalGet($path . '/rs/s');
$elements = $this
->xpath('//form[@id="' . $form_html_id . '"]//input[@name="text"]');
$elements[0]['name'] = 'button1';
$this
->drupalPostForm(NULL, array(
'button1' => 'button1',
), NULL, array(), array(), $form_html_id);
$this
->assertNoText('The clicked button is button1.', '$form_state->getTriggeringElement() not set to a restricted button.');
$this
->assertText('The clicked button is button2.', '$form_state->getTriggeringElement() not set to a restricted button.');
}
}