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

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

Issue #3211838 by mondrake, longwave: Convert assertions involving use of xpath on spans to WebAssert
parent a4715517
No related branches found
No related tags found
25 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1896Issue #2940605: Can only intentionally re-render an entity with references 20 times,!1101Issue #2412669 by claudiu.cristea, Julfabre, sidharrell, catch, daffie,...,!1039Issue #2556069 by claudiu.cristea, bnjmnm, lauriii, pfrenssen, Tim Bozeman,...,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!1012Issue #3226887: Hreflang on non-canonical content pages,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!825Issue #3211838 by mondrake, longwave: Convert assertions involving use of...,!795Issue #3212005 by guilhermevp, tedbow, phenaproxima: Add @throws docs to...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!748#1091852 Display Bug when using #states (Forms API) with Ajax Request,!731Add a new recipe to Umami demo - Chicken souvlaki and couscous,!730Issue #3211810 by alexpott, xjm, Spokje, Amber Himes Matz, Kristen Pol,...,!700Issue #3185165 by Spokje, vipin.mittal18, Suresh Prabhu Parkala, lauriii,...,!594Put each entity type table into a details element on admin/config/regional/content-language,!592Issue #2957953: Editing menus user-experience has regressed,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!512Issue #3207771: Menu UI node type form documentation points to non-existent function,!485Sets the autocomplete attribute for username/password input field on login form.,!449Issue #2784233: Allow multiple vocabularies in the taxonomy filter,!231Issue #2671162: summary text wysiwyg patch working fine on 9.2.0-dev,!43Resolve #3173180: Add UI for 'loading' html attribute to images,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
...@@ -74,8 +74,8 @@ public function testNodeTitle() { ...@@ -74,8 +74,8 @@ public function testNodeTitle() {
$xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a';
$this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node'); $this->assertEqual($this->xpath($xpath)[0]->getText(), $node->label(), 'Node breadcrumb is equal to node title.', 'Node');
// Test node title in comment preview. // Verify that node preview title is equal to node title.
$this->assertEqual($this->xpath('//article[contains(concat(" ", normalize-space(@class), " "), :node-class)]/h2/a/span', [':node-class' => ' node--type-' . $node->bundle() . ' '])[0]->getText(), $node->label(), 'Node preview title is equal to node title.', 'Node'); $this->assertSession()->elementTextEquals('xpath', "//article[contains(concat(' ', normalize-space(@class), ' '), ' node--type-{$node->bundle()} ')]/h2/a/span", $node->label());
// Test node title is clickable on teaser list (/node). // Test node title is clickable on teaser list (/node).
$this->drupalGet('node'); $this->drupalGet('node');
......
...@@ -98,8 +98,8 @@ public function testMultiByteUtf8() { ...@@ -98,8 +98,8 @@ public function testMultiByteUtf8() {
$this->assertLessThan(strlen($title), mb_strlen($title, 'utf-8')); $this->assertLessThan(strlen($title), mb_strlen($title, 'utf-8'));
$node = $this->drupalCreateNode(['title' => $title]); $node = $this->drupalCreateNode(['title' => $title]);
$this->drupalGet($node->toUrl()); $this->drupalGet($node->toUrl());
$result = $this->xpath('//span[contains(@class, "field--name-title")]'); // Verify that the passed title was returned.
$this->assertEqual($title, $result[0]->getText(), 'The passed title was returned.'); $this->assertSession()->elementTextEquals('xpath', '//span[contains(@class, "field--name-title")]', $title);
} }
} }
...@@ -65,11 +65,8 @@ public function testFormLabels() { ...@@ -65,11 +65,8 @@ public function testFormLabels() {
$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")]');
// Check #field_prefix and #field_suffix placement. // Check #field_prefix and #field_suffix placement.
$elements = $this->xpath('//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]'); $this->assertSession()->elementExists('xpath', '//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]');
$this->assertTrue(isset($elements[0]), 'Properly placed the #field_prefix element after the label and before the field.'); $this->assertSession()->elementExists('xpath', '//span[@class="field-suffix"]/preceding-sibling::div[@id="edit-form-radios-test"]');
$elements = $this->xpath('//span[@class="field-suffix"]/preceding-sibling::div[@id="edit-form-radios-test"]');
$this->assertTrue(isset($elements[0]), 'Properly places the #field_suffix element immediately after the form field.');
// Check #prefix and #suffix placement. Both elements placed before the form // Check #prefix and #suffix placement. Both elements placed before the form
// item. // item.
...@@ -80,11 +77,13 @@ public function testFormLabels() { ...@@ -80,11 +77,13 @@ public function testFormLabels() {
$this->assertSession()->elementAttributeContains('css', '#edit-form-checkboxes-title-attribute', 'title', 'Checkboxes test (Required)'); $this->assertSession()->elementAttributeContains('css', '#edit-form-checkboxes-title-attribute', 'title', 'Checkboxes test (Required)');
$this->assertSession()->elementAttributeContains('css', '#edit-form-radios-title-attribute', 'title', 'Radios test (Required)'); $this->assertSession()->elementAttributeContains('css', '#edit-form-radios-title-attribute', 'title', 'Radios test (Required)');
$elements = $this->xpath('//fieldset[@id="edit-form-checkboxes-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]'); // Check Title/Label not displayed when 'visually-hidden' attribute is set
$this->assertTrue(!empty($elements), "Title/Label not displayed when 'visually-hidden' attribute is set in checkboxes."); // in checkboxes.
$this->assertSession()->elementExists('xpath', '//fieldset[@id="edit-form-checkboxes-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]');
$elements = $this->xpath('//fieldset[@id="edit-form-radios-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]'); // Check Title/Label not displayed when 'visually-hidden' attribute is set
$this->assertTrue(!empty($elements), "Title/Label not displayed when 'visually-hidden' attribute is set in radios."); // in radios.
$this->assertSession()->elementExists('xpath', '//fieldset[@id="edit-form-radios-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]');
} }
/** /**
......
...@@ -48,43 +48,45 @@ protected function setUp($import_test_views = TRUE): void { ...@@ -48,43 +48,45 @@ protected function setUp($import_test_views = TRUE): void {
* Tests arguments. * Tests arguments.
*/ */
public function testArguments() { public function testArguments() {
$xpath = '//span[@class="field-content"]';
// Ensure that all the entries are returned.
$this->drupalGet('test_route_without_arguments'); $this->drupalGet('test_route_without_arguments');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$result = $this->xpath('//span[@class="field-content"]'); $this->assertSession()->elementsCount('xpath', $xpath, 5);
$this->assertCount(5, $result, 'All entries was returned');
$this->drupalGet('test_route_without_arguments/1'); $this->drupalGet('test_route_without_arguments/1');
$this->assertSession()->statusCodeEquals(404); $this->assertSession()->statusCodeEquals(404);
// Ensure that just the filtered entry is returned.
$this->drupalGet('test_route_with_argument/1'); $this->drupalGet('test_route_with_argument/1');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']); $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']);
$result = $this->xpath('//span[@class="field-content"]'); $this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); $this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.');
// Ensure that just the filtered entry is returned.
$this->drupalGet('test_route_with_suffix/1/suffix'); $this->drupalGet('test_route_with_suffix/1/suffix');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$result = $this->xpath('//span[@class="field-content"]'); $this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); $this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.');
// Ensure that no result is returned.
$this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2'); $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$result = $this->xpath('//span[@class="field-content"]'); $this->assertSession()->elementNotExists('xpath', $xpath);
$this->assertCount(0, $result, 'No result was returned.');
// Ensure that just the filtered entry is returned.
$this->drupalGet('test_route_with_suffix_and_argument/1/suffix/1'); $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/1');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$result = $this->xpath('//span[@class="field-content"]'); $this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); $this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.');
// Ensure that just the filtered entry is returned.
$this->drupalGet('test_route_with_long_argument/1'); $this->drupalGet('test_route_with_long_argument/1');
$this->assertSession()->statusCodeEquals(200); $this->assertSession()->statusCodeEquals(200);
$result = $this->xpath('//span[@class="field-content"]'); $this->assertSession()->elementsCount('xpath', $xpath, 1);
$this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); $this->assertSession()->elementTextEquals('xpath', $xpath, 1);
$this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.');
} }
/** /**
......
...@@ -72,8 +72,9 @@ protected function setUpProfile() { ...@@ -72,8 +72,9 @@ protected function setUpProfile() {
PerformanceTestRecorder::registerService($this->siteDirectory . '/services.yml', TRUE); PerformanceTestRecorder::registerService($this->siteDirectory . '/services.yml', TRUE);
// Assert that the expected title is present. // Assert that the expected title is present.
$this->assertEqual('Select an installation profile', $this->cssSelect('main h2')[0]->getText()); $this->assertEqual('Select an installation profile', $this->cssSelect('main h2')[0]->getText());
$result = $this->xpath('//span[contains(@class, :class) and contains(text(), :text)]', [':class' => 'visually-hidden', ':text' => 'Select an installation profile']); // Verify that Title/Label are not displayed when '#title_display' =>
$this->assertCount(1, $result, "Title/Label not displayed when '#title_display' => 'invisible' attribute is set"); // 'invisible' attribute is set.
$this->assertSession()->elementsCount('xpath', "//span[contains(@class, 'visually-hidden') and contains(text(), 'Select an installation profile')]", 1);
parent::setUpProfile(); parent::setUpProfile();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment