diff --git a/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php b/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php new file mode 100644 index 0000000..d25875b --- /dev/null +++ b/core/modules/system/tests/modules/test_page_test/src/Form/TestForm.php @@ -0,0 +1,66 @@ + 'table', + '#header' => array('Column 1', 'Column 2', 'Column 3'), + 'row_1' => [ + 'col_1' => ['#plain_text' => 'foo'], + 'col_2' => ['#plain_text' => 'bar'], + 'col_3' => ['#plain_text' => 'baz'], + ], + 'row_2' => [ + 'col_1' => ['#plain_text' => 'one'], + 'col_2' => ['#plain_text' => 'two'], + 'col_3' => ['#plain_text' => 'three'], + ], + ]; + + $form['name'] = [ + '#type' => 'textfield', + '#title' => 'Name', + '#default_value' => 'Test name', + ]; + + $form['options'] = [ + '#type' => 'select', + '#title' => 'Options', + '#options' => [ + 1 => 'one', + 2 => 'two', + 3 => 'three', + ], + '#default_value' => 2, + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'test_page_form'; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + // Empty on purpose, we just want to test the rendered form elements. + } + +} diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml index 9d07a34..5d84695 100644 --- a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml @@ -74,3 +74,11 @@ test_page_test.pipe: _controller: '\Drupal\test_page_test\Controller\Test::renderPipeInLink' requirements: _access: 'TRUE' + +test_page_test.field_xpath: + path: '/test-field-xpath' + defaults: + _title: 'Table and form elements for field xpath assertion testing' + _form: '\Drupal\test_page_test\Form\TestForm' + requirements: + _access: 'TRUE' diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index ecee04b..ef9c6b5 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -148,19 +148,15 @@ public function testLegacyTextAsserts() { * Tests legacy XPath asserts. */ public function testLegacyXPathAsserts() { - $account = $this->drupalCreateUser(['administer users'], 'test'); - $this->drupalLogin($account); - - $this->drupalGet('admin/people'); + $this->drupalGet('test-field-xpath'); $this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL); - $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]/span'), $account->getAccountName()); - $this->assertFieldByXPath('//table/tbody/tr[2]/td[1]/span', $account->getAccountName()); - - $this->drupalGet('user/' . $account->id() . '/edit'); - $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), $account->getAccountName()); - $this->assertFieldByXPath("//input[@id = 'edit-name']", $account->getAccountName()); - $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-timezone--2']"), 'Australia/Sydney'); - $this->assertFieldByXPath("//select[@id = 'edit-timezone--2']", 'Australia/Sydney'); + $this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one'); + $this->assertFieldByXPath('//table/tbody/tr[2]/td[1]', 'one'); + + $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'Test name'); + $this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name'); + $this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2'); + $this->assertFieldByXPath("//select[@id = 'edit-options']", '2'); $this->assertNoFieldByXPath('//notexisting'); $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');