Skip to content
Snippets Groups Projects
Commit b7ae0cb1 authored by catch's avatar catch
Browse files

Issue #3220183 by mondrake, longwave: Convert assertions involving use of...

Issue #3220183 by mondrake, longwave: Convert assertions involving use of xpath on labels to WebAssert

(cherry picked from commit 67bfb63d)
parent 69ba7f7e
No related branches found
No related tags found
No related merge requests found
Showing with 21 additions and 40 deletions
...@@ -366,8 +366,7 @@ public function testFieldFormUnlimitedRequired() { ...@@ -366,8 +366,7 @@ public function testFieldFormUnlimitedRequired() {
$this->assertTrue(isset($element[0]), 'Required symbol added field label.'); $this->assertTrue(isset($element[0]), 'Required symbol added field label.');
// Check that the label of the field input is visually hidden and contains // Check that the label of the field input is visually hidden and contains
// the field title and an indication of the delta for a11y. // the field title and an indication of the delta for a11y.
$element = $this->xpath('//label[@for=:for and contains(@class, "visually-hidden") and contains(text(), :value)]', [':for' => 'edit-field-unlimited-0-value', ':value' => $this->field['label'] . ' (value 1)']); $this->assertSession()->elementExists('xpath', "//label[@for='edit-field-unlimited-0-value' and contains(@class, 'visually-hidden') and contains(text(), '{$this->field['label']} (value 1)')]");
$this->assertTrue(isset($element[0]), 'Required symbol not added for field input.');
} }
/** /**
......
...@@ -150,16 +150,13 @@ public function testBooleanFilterHandler() { ...@@ -150,16 +150,13 @@ public function testBooleanFilterHandler() {
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
// Verify that using a boolean field as a filter also results in using the // Verify that using a boolean field as a filter also results in using the
// boolean plugin. // boolean plugin.
$option = $this->xpath('//label[@for="edit-options-value-1"]'); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-options-value-1"]', 'True');
$this->assertEquals(t('True'), $option[0]->getText()); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-options-value-0"]', 'False');
$option = $this->xpath('//label[@for="edit-options-value-0"]');
$this->assertEquals(t('False'), $option[0]->getText());
// Expose the filter and see if the 'Any' option is added and if we can save // Expose the filter and see if the 'Any' option is added and if we can save
// it. // it.
$this->submitForm([], 'Expose filter'); $this->submitForm([], 'Expose filter');
$option = $this->xpath('//label[@for="edit-options-value-all"]'); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-options-value-all"]', '- Any -');
$this->assertEquals(t('- Any -'), $option[0]->getText());
$this->submitForm(['options[value]' => 'All', 'options[expose][required]' => FALSE], 'Apply'); $this->submitForm(['options[value]' => 'All', 'options[expose][required]' => FALSE], 'Apply');
$this->submitForm([], 'Save'); $this->submitForm([], 'Save');
$this->drupalGet('/admin/structure/views/nojs/handler/test_view_fieldapi/default/filter/field_boolean_value'); $this->drupalGet('/admin/structure/views/nojs/handler/test_view_fieldapi/default/filter/field_boolean_value');
......
...@@ -106,8 +106,7 @@ public function testSingleValuedWidget() { ...@@ -106,8 +106,7 @@ public function testSingleValuedWidget() {
$this->assertSession()->buttonExists('Upload'); $this->assertSession()->buttonExists('Upload');
// Test label has correct 'for' attribute. // Test label has correct 'for' attribute.
$input = $this->assertSession()->fieldExists("files[{$field_name}_0]"); $input = $this->assertSession()->fieldExists("files[{$field_name}_0]");
$label = $this->xpath('//label[@for="' . $input->getAttribute('id') . '"]'); $this->assertSession()->elementExists('xpath', '//label[@for="' . $input->getAttribute('id') . '"]');
$this->assertTrue(isset($label[0]), 'Label for upload found.');
// Save the node and ensure it does not have the file. // Save the node and ensure it does not have the file.
$this->submitForm([], 'Save'); $this->submitForm([], 'Save');
......
...@@ -182,14 +182,8 @@ public function testRequiredAttributes() { ...@@ -182,14 +182,8 @@ public function testRequiredAttributes() {
$this->uploadNodeImage($image, $field_name, 'article'); $this->uploadNodeImage($image, $field_name, 'article');
// Look for form-required for the alt text. // Look for form-required for the alt text.
$elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-alt" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-alt"]'); $this->assertSession()->elementExists('xpath', '//label[@for="edit-' . $field_name . '-0-alt" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-alt"]');
$this->assertSession()->elementExists('xpath', '//label[@for="edit-' . $field_name . '-0-title" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-title"]');
$this->assertTrue(isset($elements[0]), 'Required marker is shown for the required alt text.');
$elements = $this->xpath('//label[@for="edit-' . $field_name . '-0-title" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-' . $field_name . '-0-title"]');
$this->assertTrue(isset($elements[0]), 'Required marker is shown for the required title text.');
$this->assertSession()->pageTextContains('Alternative text field is required.'); $this->assertSession()->pageTextContains('Alternative text field is required.');
$this->assertSession()->pageTextContains('Title field is required.'); $this->assertSession()->pageTextContains('Title field is required.');
......
...@@ -48,8 +48,9 @@ public function testFormLabels() { ...@@ -48,8 +48,9 @@ public function testFormLabels() {
// Exercise various defaults for textboxes and modifications to ensure // Exercise various defaults for textboxes and modifications to ensure
// appropriate override and correct behavior. // appropriate override and correct behavior.
$elements = $this->xpath('//label[@for="edit-form-textfield-test-title-and-required" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-form-textfield-test-title-and-required"]');
$this->assertTrue(isset($elements[0]), 'Label precedes textfield, with required marker inside label.'); // Verify that label precedes textfield, with required marker inside label.
$this->assertSession()->elementExists('xpath', '//label[@for="edit-form-textfield-test-title-and-required" and @class="js-form-required form-required"]/following-sibling::input[@id="edit-form-textfield-test-title-and-required"]');
$this->assertSession()->elementExists('xpath', '//input[@id="edit-form-textfield-test-no-title-required"]/preceding-sibling::label[@for="edit-form-textfield-test-no-title-required" and @class="js-form-required form-required"]'); $this->assertSession()->elementExists('xpath', '//input[@id="edit-form-textfield-test-no-title-required"]/preceding-sibling::label[@for="edit-form-textfield-test-no-title-required" and @class="js-form-required form-required"]');
$this->assertSession()->elementExists('xpath', '//input[@id="edit-form-textfield-test-title-invisible"]/preceding-sibling::label[@for="edit-form-textfield-test-title-invisible" and @class="visually-hidden"]'); $this->assertSession()->elementExists('xpath', '//input[@id="edit-form-textfield-test-title-invisible"]/preceding-sibling::label[@for="edit-form-textfield-test-title-invisible" and @class="visually-hidden"]');
...@@ -58,8 +59,8 @@ public function testFormLabels() { ...@@ -58,8 +59,8 @@ public function testFormLabels() {
$this->assertSession()->elementExists('xpath', '//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and @class="option"]'); $this->assertSession()->elementExists('xpath', '//input[@id="edit-form-textfield-test-title-after"]/following-sibling::label[@for="edit-form-textfield-test-title-after" and @class="option"]');
$elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]'); // Verify that no label tag exists when title set not to display.
$this->assertFalse(isset($elements[0]), 'No label tag when title set not to display.'); $this->assertSession()->elementNotExists('xpath', '//label[@for="edit-form-textfield-test-title-no-show"]');
// Verify that field class is form-no-label when there is no label. // Verify that field class is form-no-label when there is no label.
$this->assertSession()->elementExists('xpath', '//div[contains(@class, "js-form-item-form-textfield-test-title-invisible") and contains(@class, "form-no-label")]'); $this->assertSession()->elementExists('xpath', '//div[contains(@class, "js-form-item-form-textfield-test-title-invisible") and contains(@class, "form-no-label")]');
......
...@@ -132,8 +132,7 @@ public function testBulkForm() { ...@@ -132,8 +132,7 @@ public function testBulkForm() {
// Check the default title. // Check the default title.
$this->drupalGet('test_bulk_form'); $this->drupalGet('test_bulk_form');
$result = $this->xpath('//label[@for="edit-action"]'); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-action"]', 'Action');
$this->assertEquals('Action', $result[0]->getText());
// Setup up a different bulk form title. // Setup up a different bulk form title.
$view = Views::getView('test_bulk_form'); $view = Views::getView('test_bulk_form');
...@@ -142,8 +141,7 @@ public function testBulkForm() { ...@@ -142,8 +141,7 @@ public function testBulkForm() {
$view->save(); $view->save();
$this->drupalGet('test_bulk_form'); $this->drupalGet('test_bulk_form');
$result = $this->xpath('//label[@for="edit-action"]'); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-action"]', 'Test title');
$this->assertEquals('Test title', $result[0]->getText());
$this->drupalGet('test_bulk_form'); $this->drupalGet('test_bulk_form');
// Call the node delete action. // Call the node delete action.
......
...@@ -123,10 +123,8 @@ public function testFilterNumericUI() { ...@@ -123,10 +123,8 @@ public function testFilterNumericUI() {
// Check the field (wrapper) label. // Check the field (wrapper) label.
$this->assertSession()->elementTextContains('css', 'fieldset#edit-age-wrapper legend', 'Age between'); $this->assertSession()->elementTextContains('css', 'fieldset#edit-age-wrapper legend', 'Age between');
// Check the min/max labels. // Check the min/max labels.
$min_element_label = $this->xpath('//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-min") and contains(text(), "Min")]'); $this->assertSession()->elementsCount('xpath', '//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-min") and contains(text(), "Min")]', 1);
$this->assertCount(1, $min_element_label); $this->assertSession()->elementsCount('xpath', '//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-max") and contains(text(), "Max")]', 1);
$max_element_label = $this->xpath('//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-max") and contains(text(), "Max")]');
$this->assertCount(1, $max_element_label);
// Check that the description is shown in the right place. // Check that the description is shown in the right place.
$this->assertEquals('Description of the exposed filter', trim($this->cssSelect('#edit-age-wrapper--description')[0]->getText())); $this->assertEquals('Description of the exposed filter', trim($this->cssSelect('#edit-age-wrapper--description')[0]->getText()));
...@@ -145,8 +143,7 @@ public function testFilterNumericUI() { ...@@ -145,8 +143,7 @@ public function testFilterNumericUI() {
$this->submitForm([], 'Update preview'); $this->submitForm([], 'Update preview');
// Make sure the label is visible and that there's no fieldset wrapper. // Make sure the label is visible and that there's no fieldset wrapper.
$label = $this->xpath('//label[contains(@for, "edit-age") and contains(text(), "Age greater than")]'); $this->assertSession()->elementsCount('xpath', '//label[contains(@for, "edit-age") and contains(text(), "Age greater than")]', 1);
$this->assertCount(1, $label);
$fieldset = $this->xpath('//fieldset[contains(@id, "edit-age-wrapper")]'); $fieldset = $this->xpath('//fieldset[contains(@id, "edit-age-wrapper")]');
$this->assertEmpty($fieldset); $this->assertEmpty($fieldset);
} }
......
...@@ -35,10 +35,8 @@ protected function setUpSettings() { ...@@ -35,10 +35,8 @@ protected function setUpSettings() {
$this->testDriverName = 'Drivertest' . ucfirst($driver); $this->testDriverName = 'Drivertest' . ucfirst($driver);
// Assert that we are using the database drivers from the driver_test module. // Assert that we are using the database drivers from the driver_test module.
$elements = $this->xpath('//label[@for="edit-driver-drivertestmysql"]'); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestmysql"]', 'MySQL by the driver_test module');
$this->assertEquals('MySQL by the driver_test module', current($elements)->getText()); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestpgsql"]', 'PostgreSQL by the driver_test module');
$elements = $this->xpath('//label[@for="edit-driver-drivertestpgsql"]');
$this->assertEquals('PostgreSQL by the driver_test module', current($elements)->getText());
$settings = $this->parameters['forms']['install_settings_form']; $settings = $this->parameters['forms']['install_settings_form'];
......
...@@ -88,10 +88,8 @@ protected function setUpSettings() { ...@@ -88,10 +88,8 @@ protected function setUpSettings() {
// Assert that we use the by core supported database drivers by default and // Assert that we use the by core supported database drivers by default and
// not the ones from the driver_test module. // not the ones from the driver_test module.
$elements = $this->xpath('//label[@for="edit-driver-mysql"]'); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-mysql"]', 'MySQL, MariaDB, Percona Server, or equivalent');
$this->assertEquals('MySQL, MariaDB, Percona Server, or equivalent', current($elements)->getText()); $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-pgsql"]', 'PostgreSQL');
$elements = $this->xpath('//label[@for="edit-driver-pgsql"]');
$this->assertEquals('PostgreSQL', current($elements)->getText());
parent::setUpSettings(); parent::setUpSettings();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment