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() {
$this->assertTrue(isset($element[0]), 'Required symbol added field label.');
// Check that the label of the field input is visually hidden and contains
// 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->assertTrue(isset($element[0]), 'Required symbol not added for field input.');
$this->assertSession()->elementExists('xpath', "//label[@for='edit-field-unlimited-0-value' and contains(@class, 'visually-hidden') and contains(text(), '{$this->field['label']} (value 1)')]");
}
/**
......
......@@ -150,16 +150,13 @@ public function testBooleanFilterHandler() {
$this->assertSession()->statusCodeEquals(200);
// Verify that using a boolean field as a filter also results in using the
// boolean plugin.
$option = $this->xpath('//label[@for="edit-options-value-1"]');
$this->assertEquals(t('True'), $option[0]->getText());
$option = $this->xpath('//label[@for="edit-options-value-0"]');
$this->assertEquals(t('False'), $option[0]->getText());
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-options-value-1"]', 'True');
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-options-value-0"]', 'False');
// Expose the filter and see if the 'Any' option is added and if we can save
// it.
$this->submitForm([], 'Expose filter');
$option = $this->xpath('//label[@for="edit-options-value-all"]');
$this->assertEquals(t('- Any -'), $option[0]->getText());
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-options-value-all"]', '- Any -');
$this->submitForm(['options[value]' => 'All', 'options[expose][required]' => FALSE], 'Apply');
$this->submitForm([], 'Save');
$this->drupalGet('/admin/structure/views/nojs/handler/test_view_fieldapi/default/filter/field_boolean_value');
......
......@@ -106,8 +106,7 @@ public function testSingleValuedWidget() {
$this->assertSession()->buttonExists('Upload');
// Test label has correct 'for' attribute.
$input = $this->assertSession()->fieldExists("files[{$field_name}_0]");
$label = $this->xpath('//label[@for="' . $input->getAttribute('id') . '"]');
$this->assertTrue(isset($label[0]), 'Label for upload found.');
$this->assertSession()->elementExists('xpath', '//label[@for="' . $input->getAttribute('id') . '"]');
// Save the node and ensure it does not have the file.
$this->submitForm([], 'Save');
......
......@@ -182,14 +182,8 @@ public function testRequiredAttributes() {
$this->uploadNodeImage($image, $field_name, 'article');
// 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->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()->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->assertSession()->pageTextContains('Alternative text field is required.');
$this->assertSession()->pageTextContains('Title field is required.');
......
......@@ -48,8 +48,9 @@ public function testFormLabels() {
// Exercise various defaults for textboxes and modifications to ensure
// 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-title-invisible"]/preceding-sibling::label[@for="edit-form-textfield-test-title-invisible" and @class="visually-hidden"]');
......@@ -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"]');
$elements = $this->xpath('//label[@for="edit-form-textfield-test-title-no-show"]');
$this->assertFalse(isset($elements[0]), 'No label tag when title set not to display.');
// Verify that no label tag exists 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.
$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() {
// Check the default title.
$this->drupalGet('test_bulk_form');
$result = $this->xpath('//label[@for="edit-action"]');
$this->assertEquals('Action', $result[0]->getText());
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-action"]', 'Action');
// Setup up a different bulk form title.
$view = Views::getView('test_bulk_form');
......@@ -142,8 +141,7 @@ public function testBulkForm() {
$view->save();
$this->drupalGet('test_bulk_form');
$result = $this->xpath('//label[@for="edit-action"]');
$this->assertEquals('Test title', $result[0]->getText());
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-action"]', 'Test title');
$this->drupalGet('test_bulk_form');
// Call the node delete action.
......
......@@ -123,10 +123,8 @@ public function testFilterNumericUI() {
// Check the field (wrapper) label.
$this->assertSession()->elementTextContains('css', 'fieldset#edit-age-wrapper legend', 'Age between');
// 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->assertCount(1, $min_element_label);
$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);
$this->assertSession()->elementsCount('xpath', '//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-min") and contains(text(), "Min")]', 1);
$this->assertSession()->elementsCount('xpath', '//fieldset[contains(@id, "edit-age-wrapper")]//label[contains(@for, "edit-age-max") and contains(text(), "Max")]', 1);
// 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()));
......@@ -145,8 +143,7 @@ public function testFilterNumericUI() {
$this->submitForm([], 'Update preview');
// 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->assertCount(1, $label);
$this->assertSession()->elementsCount('xpath', '//label[contains(@for, "edit-age") and contains(text(), "Age greater than")]', 1);
$fieldset = $this->xpath('//fieldset[contains(@id, "edit-age-wrapper")]');
$this->assertEmpty($fieldset);
}
......
......@@ -35,10 +35,8 @@ protected function setUpSettings() {
$this->testDriverName = 'Drivertest' . ucfirst($driver);
// Assert that we are using the database drivers from the driver_test module.
$elements = $this->xpath('//label[@for="edit-driver-drivertestmysql"]');
$this->assertEquals('MySQL by the driver_test module', current($elements)->getText());
$elements = $this->xpath('//label[@for="edit-driver-drivertestpgsql"]');
$this->assertEquals('PostgreSQL by the driver_test module', current($elements)->getText());
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestmysql"]', 'MySQL by the driver_test module');
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestpgsql"]', 'PostgreSQL by the driver_test module');
$settings = $this->parameters['forms']['install_settings_form'];
......
......@@ -88,10 +88,8 @@ protected function setUpSettings() {
// Assert that we use the by core supported database drivers by default and
// not the ones from the driver_test module.
$elements = $this->xpath('//label[@for="edit-driver-mysql"]');
$this->assertEquals('MySQL, MariaDB, Percona Server, or equivalent', current($elements)->getText());
$elements = $this->xpath('//label[@for="edit-driver-pgsql"]');
$this->assertEquals('PostgreSQL', current($elements)->getText());
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-mysql"]', 'MySQL, MariaDB, Percona Server, or equivalent');
$this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-pgsql"]', 'PostgreSQL');
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