function FormBuilderTest::testUniqueElementHtmlId
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testUniqueElementHtmlId()
- 10 core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testUniqueElementHtmlId()
- 11.x core/tests/Drupal/Tests/Core/Form/FormBuilderTest.php \Drupal\Tests\Core\Form\FormBuilderTest::testUniqueElementHtmlId()
Tests that HTML IDs are unique between 2 forms with the same element names.
File
-
core/
tests/ Drupal/ Tests/ Core/ Form/ FormBuilderTest.php, line 491
Class
- FormBuilderTest
- @coversDefaultClass \Drupal\Core\Form\FormBuilder @group Form
Namespace
Drupal\Tests\Core\FormCode
public function testUniqueElementHtmlId() {
$form_id_1 = 'test_form_id';
$form_id_2 = 'test_form_id_2';
$expected_form = $form_id_1();
// Mock 2 form objects that will be built once each.
$form_arg_1 = $this->createMock('Drupal\\Core\\Form\\FormInterface');
$form_arg_1->expects($this->exactly(1))
->method('getFormId')
->will($this->returnValue($form_id_1));
$form_arg_1->expects($this->exactly(1))
->method('buildForm')
->will($this->returnValue($expected_form));
$form_arg_2 = $this->createMock('Drupal\\Core\\Form\\FormInterface');
$form_arg_2->expects($this->exactly(1))
->method('getFormId')
->will($this->returnValue($form_id_2));
$form_arg_2->expects($this->exactly(1))
->method('buildForm')
->will($this->returnValue($expected_form));
$form_state = new FormState();
$form_1 = $this->simulateFormSubmission($form_id_1, $form_arg_1, $form_state);
$form_state = new FormState();
$form_2 = $this->simulateFormSubmission($form_id_2, $form_arg_2, $form_state);
$this->assertNotSame($form_1['actions']["#id"], $form_2['actions']["#id"]);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.