diff --git a/core/modules/node/tests/src/Functional/NodeTitleTest.php b/core/modules/node/tests/src/Functional/NodeTitleTest.php index 4f048e63839408cf4fbd7caa480aced57423fd84..ddd939c5799e3ce932b6b5901857e2b999004f22 100644 --- a/core/modules/node/tests/src/Functional/NodeTitleTest.php +++ b/core/modules/node/tests/src/Functional/NodeTitleTest.php @@ -74,8 +74,8 @@ public function testNodeTitle() { $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'); - // Test node title in comment preview. - $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'); + // Verify that node preview title is equal to node title. + $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). $this->drupalGet('node'); diff --git a/core/modules/node/tests/src/Functional/NodeViewTest.php b/core/modules/node/tests/src/Functional/NodeViewTest.php index 730212e1e741b7d58d2938b2e584243d4f2d5661..c063cc9a80ac034987138ecef10e434d87f83896 100644 --- a/core/modules/node/tests/src/Functional/NodeViewTest.php +++ b/core/modules/node/tests/src/Functional/NodeViewTest.php @@ -98,8 +98,8 @@ public function testMultiByteUtf8() { $this->assertLessThan(strlen($title), mb_strlen($title, 'utf-8')); $node = $this->drupalCreateNode(['title' => $title]); $this->drupalGet($node->toUrl()); - $result = $this->xpath('//span[contains(@class, "field--name-title")]'); - $this->assertEqual($title, $result[0]->getText(), 'The passed title was returned.'); + // Verify that the passed title was returned. + $this->assertSession()->elementTextEquals('xpath', '//span[contains(@class, "field--name-title")]', $title); } } diff --git a/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php b/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php index 093f41ab1469e288e43b880fc51e44a673ee0dde..973be481350cb46eb3be2623ba2bed99ab552fb8 100644 --- a/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php +++ b/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php @@ -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")]'); // Check #field_prefix and #field_suffix placement. - $elements = $this->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.'); - - $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.'); + $this->assertSession()->elementExists('xpath', '//span[@class="field-prefix"]/following-sibling::div[@id="edit-form-radios-test"]'); + $this->assertSession()->elementExists('xpath', '//span[@class="field-suffix"]/preceding-sibling::div[@id="edit-form-radios-test"]'); // Check #prefix and #suffix placement. Both elements placed before the form // item. @@ -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-radios-title-attribute', 'title', 'Radios test (Required)'); - $elements = $this->xpath('//fieldset[@id="edit-form-checkboxes-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]'); - $this->assertTrue(!empty($elements), "Title/Label not displayed when 'visually-hidden' attribute is set in checkboxes."); + // Check Title/Label not displayed when 'visually-hidden' attribute is set + // 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")]'); - $this->assertTrue(!empty($elements), "Title/Label not displayed when 'visually-hidden' attribute is set in radios."); + // Check Title/Label not displayed when 'visually-hidden' attribute is set + // in radios. + $this->assertSession()->elementExists('xpath', '//fieldset[@id="edit-form-radios-title-invisible--wrapper"]/legend/span[contains(@class, "visually-hidden")]'); } /** diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php index f6f6c018a7344398833caa672e5ce5e7348115aa..0ec4e2bbcd791484727fbeab1725e8fc691a99b1 100644 --- a/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php @@ -48,43 +48,45 @@ protected function setUp($import_test_views = TRUE): void { * Tests arguments. */ public function testArguments() { + $xpath = '//span[@class="field-content"]'; + + // Ensure that all the entries are returned. $this->drupalGet('test_route_without_arguments'); $this->assertSession()->statusCodeEquals(200); - $result = $this->xpath('//span[@class="field-content"]'); - $this->assertCount(5, $result, 'All entries was returned'); + $this->assertSession()->elementsCount('xpath', $xpath, 5); $this->drupalGet('test_route_without_arguments/1'); $this->assertSession()->statusCodeEquals(404); + // Ensure that just the filtered entry is returned. $this->drupalGet('test_route_with_argument/1'); $this->assertSession()->statusCodeEquals(200); $this->assertCacheContexts(['languages:language_interface', 'route', 'theme', 'url']); - $result = $this->xpath('//span[@class="field-content"]'); - $this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.'); + $this->assertSession()->elementsCount('xpath', $xpath, 1); + $this->assertSession()->elementTextEquals('xpath', $xpath, 1); + // Ensure that just the filtered entry is returned. $this->drupalGet('test_route_with_suffix/1/suffix'); $this->assertSession()->statusCodeEquals(200); - $result = $this->xpath('//span[@class="field-content"]'); - $this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.'); + $this->assertSession()->elementsCount('xpath', $xpath, 1); + $this->assertSession()->elementTextEquals('xpath', $xpath, 1); + // Ensure that no result is returned. $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2'); $this->assertSession()->statusCodeEquals(200); - $result = $this->xpath('//span[@class="field-content"]'); - $this->assertCount(0, $result, 'No result was returned.'); + $this->assertSession()->elementNotExists('xpath', $xpath); + // Ensure that just the filtered entry is returned. $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/1'); $this->assertSession()->statusCodeEquals(200); - $result = $this->xpath('//span[@class="field-content"]'); - $this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.'); + $this->assertSession()->elementsCount('xpath', $xpath, 1); + $this->assertSession()->elementTextEquals('xpath', $xpath, 1); + // Ensure that just the filtered entry is returned. $this->drupalGet('test_route_with_long_argument/1'); $this->assertSession()->statusCodeEquals(200); - $result = $this->xpath('//span[@class="field-content"]'); - $this->assertCount(1, $result, 'Ensure that just the filtered entry was returned.'); - $this->assertEqual(1, $result[0]->getText(), 'The passed ID was returned.'); + $this->assertSession()->elementsCount('xpath', $xpath, 1); + $this->assertSession()->elementTextEquals('xpath', $xpath, 1); } /** diff --git a/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php b/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php index 397ff79211bd33d86eb68f534810c4368a2be669..41d9092c39425fbe336b797ff5ebec60dd86aeb6 100644 --- a/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php +++ b/core/tests/Drupal/FunctionalTests/Installer/InstallerTest.php @@ -72,8 +72,9 @@ protected function setUpProfile() { PerformanceTestRecorder::registerService($this->siteDirectory . '/services.yml', TRUE); // Assert that the expected title is present. $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']); - $this->assertCount(1, $result, "Title/Label not displayed when '#title_display' => 'invisible' attribute is set"); + // Verify that Title/Label are not displayed when '#title_display' => + // 'invisible' attribute is set. + $this->assertSession()->elementsCount('xpath', "//span[contains(@class, 'visually-hidden') and contains(text(), 'Select an installation profile')]", 1); parent::setUpProfile(); }