Loading core/modules/system/tests/src/Functional/Form/ElementTest.php +26 −11 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ * Tests building and processing of core form elements. * * @group Form * @group #slow */ class ElementTest extends BrowserTestBase { Loading @@ -26,10 +25,26 @@ class ElementTest extends BrowserTestBase { */ protected $defaultTheme = 'starterkit_theme'; /** * Test form elements. */ public function testFormElements(): void { $this->testPlaceHolderText(); $this->testOptions(); $this->testRadiosChecked(); $this->testWrapperIds(); $this->testButtonClasses(); $this->testGroupElements(); $this->testRequiredFieldsetsAndDetails(); $this->testFormAutocomplete(); $this->testFormElementErrors(); $this->testDetailsSummaryAttributes(); } /** * Tests placeholder text for elements that support placeholders. */ public function testPlaceHolderText(): void { protected function testPlaceHolderText(): void { $this->drupalGet('form-test/placeholder-text'); foreach (['textfield', 'tel', 'url', 'password', 'email', 'number', 'textarea'] as $type) { $field = $this->assertSession()->fieldExists("edit-$type"); Loading @@ -40,7 +55,7 @@ public function testPlaceHolderText(): void { /** * Tests expansion of #options for #type checkboxes and radios. */ public function testOptions(): void { protected function testOptions(): void { $this->drupalGet('form-test/checkboxes-radios'); // Verify that all options appear in their defined order. Loading Loading @@ -81,7 +96,7 @@ public function testOptions(): void { /** * Tests correct checked attribute for radios element. */ public function testRadiosChecked(): void { protected function testRadiosChecked(): void { // Verify that there is only one radio option checked. $this->drupalGet('form-test/radios-checked'); $this->assertSession()->elementsCount('xpath', '//input[@name="radios" and @checked]', 1); Loading Loading @@ -110,7 +125,7 @@ public function testRadiosChecked(): void { /** * Tests wrapper ids for checkboxes and radios. */ public function testWrapperIds(): void { protected function testWrapperIds(): void { $this->drupalGet('form-test/checkboxes-radios'); // Verify that wrapper id is different from element id. Loading @@ -124,7 +139,7 @@ public function testWrapperIds(): void { /** * Tests button classes. */ public function testButtonClasses(): void { protected function testButtonClasses(): void { $this->drupalGet('form-test/button-class'); // Just contains(@class, "button") won't do because then // "button--foo" would contain "button". Instead, check Loading @@ -138,7 +153,7 @@ public function testButtonClasses(): void { /** * Tests the #group property. */ public function testGroupElements(): void { protected function testGroupElements(): void { $this->drupalGet('form-test/group-details'); $this->assertSession()->elementsCount('xpath', '//div[@class="details-wrapper"]//div[@class="details-wrapper"]//label', 1); $this->drupalGet('form-test/group-container'); Loading @@ -154,7 +169,7 @@ public function testGroupElements(): void { /** * Tests the #required property on details and fieldset elements. */ public function testRequiredFieldsetsAndDetails(): void { protected function testRequiredFieldsetsAndDetails(): void { $this->drupalGet('form-test/group-details'); $this->assertEmpty($this->cssSelect('summary.form-required')); $this->drupalGet('form-test/group-details/1'); Loading @@ -168,7 +183,7 @@ public function testRequiredFieldsetsAndDetails(): void { /** * Tests a form with an autocomplete setting.. */ public function testFormAutocomplete(): void { protected function testFormAutocomplete(): void { $this->drupalGet('form-test/autocomplete'); // Ensure that the user does not have access to the autocompletion. Loading @@ -190,7 +205,7 @@ public function testFormAutocomplete(): void { /** * Tests form element error messages. */ public function testFormElementErrors(): void { protected function testFormElementErrors(): void { $this->drupalGet('form_test/details-form'); $this->submitForm([], 'Submit'); $this->assertSession()->pageTextContains('I am an error on the details element.'); Loading @@ -199,7 +214,7 @@ public function testFormElementErrors(): void { /** * Tests summary attributes of details. */ public function testDetailsSummaryAttributes(): void { protected function testDetailsSummaryAttributes(): void { $this->drupalGet('form-test/group-details'); $this->assertSession()->elementExists('css', 'summary[data-summary-attribute="test"]'); } Loading Loading
core/modules/system/tests/src/Functional/Form/ElementTest.php +26 −11 Original line number Diff line number Diff line Loading @@ -10,7 +10,6 @@ * Tests building and processing of core form elements. * * @group Form * @group #slow */ class ElementTest extends BrowserTestBase { Loading @@ -26,10 +25,26 @@ class ElementTest extends BrowserTestBase { */ protected $defaultTheme = 'starterkit_theme'; /** * Test form elements. */ public function testFormElements(): void { $this->testPlaceHolderText(); $this->testOptions(); $this->testRadiosChecked(); $this->testWrapperIds(); $this->testButtonClasses(); $this->testGroupElements(); $this->testRequiredFieldsetsAndDetails(); $this->testFormAutocomplete(); $this->testFormElementErrors(); $this->testDetailsSummaryAttributes(); } /** * Tests placeholder text for elements that support placeholders. */ public function testPlaceHolderText(): void { protected function testPlaceHolderText(): void { $this->drupalGet('form-test/placeholder-text'); foreach (['textfield', 'tel', 'url', 'password', 'email', 'number', 'textarea'] as $type) { $field = $this->assertSession()->fieldExists("edit-$type"); Loading @@ -40,7 +55,7 @@ public function testPlaceHolderText(): void { /** * Tests expansion of #options for #type checkboxes and radios. */ public function testOptions(): void { protected function testOptions(): void { $this->drupalGet('form-test/checkboxes-radios'); // Verify that all options appear in their defined order. Loading Loading @@ -81,7 +96,7 @@ public function testOptions(): void { /** * Tests correct checked attribute for radios element. */ public function testRadiosChecked(): void { protected function testRadiosChecked(): void { // Verify that there is only one radio option checked. $this->drupalGet('form-test/radios-checked'); $this->assertSession()->elementsCount('xpath', '//input[@name="radios" and @checked]', 1); Loading Loading @@ -110,7 +125,7 @@ public function testRadiosChecked(): void { /** * Tests wrapper ids for checkboxes and radios. */ public function testWrapperIds(): void { protected function testWrapperIds(): void { $this->drupalGet('form-test/checkboxes-radios'); // Verify that wrapper id is different from element id. Loading @@ -124,7 +139,7 @@ public function testWrapperIds(): void { /** * Tests button classes. */ public function testButtonClasses(): void { protected function testButtonClasses(): void { $this->drupalGet('form-test/button-class'); // Just contains(@class, "button") won't do because then // "button--foo" would contain "button". Instead, check Loading @@ -138,7 +153,7 @@ public function testButtonClasses(): void { /** * Tests the #group property. */ public function testGroupElements(): void { protected function testGroupElements(): void { $this->drupalGet('form-test/group-details'); $this->assertSession()->elementsCount('xpath', '//div[@class="details-wrapper"]//div[@class="details-wrapper"]//label', 1); $this->drupalGet('form-test/group-container'); Loading @@ -154,7 +169,7 @@ public function testGroupElements(): void { /** * Tests the #required property on details and fieldset elements. */ public function testRequiredFieldsetsAndDetails(): void { protected function testRequiredFieldsetsAndDetails(): void { $this->drupalGet('form-test/group-details'); $this->assertEmpty($this->cssSelect('summary.form-required')); $this->drupalGet('form-test/group-details/1'); Loading @@ -168,7 +183,7 @@ public function testRequiredFieldsetsAndDetails(): void { /** * Tests a form with an autocomplete setting.. */ public function testFormAutocomplete(): void { protected function testFormAutocomplete(): void { $this->drupalGet('form-test/autocomplete'); // Ensure that the user does not have access to the autocompletion. Loading @@ -190,7 +205,7 @@ public function testFormAutocomplete(): void { /** * Tests form element error messages. */ public function testFormElementErrors(): void { protected function testFormElementErrors(): void { $this->drupalGet('form_test/details-form'); $this->submitForm([], 'Submit'); $this->assertSession()->pageTextContains('I am an error on the details element.'); Loading @@ -199,7 +214,7 @@ public function testFormElementErrors(): void { /** * Tests summary attributes of details. */ public function testDetailsSummaryAttributes(): void { protected function testDetailsSummaryAttributes(): void { $this->drupalGet('form-test/group-details'); $this->assertSession()->elementExists('css', 'summary[data-summary-attribute="test"]'); } Loading