diff --git a/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php b/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php index 00e5959047..2effdccbbe 100644 --- a/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php +++ b/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php @@ -40,9 +40,13 @@ protected function assertNoBlockAppears(Block $block) { * @return array * The result from the xpath query. * - * @deprecated + * @deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no + * replacement. + * + * @see https://www.drupal.org/node/7654321 */ protected function findBlockInstance(Block $block) { + @trigger_error(__METHOD__ . '() is deprecated in drupal:10.0.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/7654321', E_USER_DEPRECATED); return $this->xpath('//div[@id = :id]', [':id' => 'block-' . $block->id()]); } diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php index 0d60b435ca..08c7f151a1 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationLocaleTest.php @@ -547,9 +547,9 @@ public function assertNotLatestVersionPage(NodeInterface $node, bool $moderation */ public function assertModerationForm(NodeInterface $node, bool $latest_tab = TRUE): void { $this->drupalGet($node->toUrl()); - $this->assertEquals(!$latest_tab, $this->hasModerationForm()); + $this->assertTrue($this->hasModerationForm(!$latest_tab)); $this->drupalGet($node->toUrl('latest-version')); - $this->assertEquals($latest_tab, $this->hasModerationForm()); + $this->assertTrue($this->hasModerationForm($latest_tab)); } /** @@ -562,19 +562,22 @@ public function assertModerationForm(NodeInterface $node, bool $latest_tab = TRU */ public function assertNoModerationForm(NodeInterface $node): void { $this->drupalGet($node->toUrl()); - $this->assertFalse($this->hasModerationForm()); + $this->assertTrue($this->hasModerationForm()); $this->drupalGet($node->toUrl('latest-version')); $this->assertEquals(403, $this->getSession()->getStatusCode()); } /** * Checks whether the page contains the moderation form. - * - * @return bool - * TRUE if the moderation form could be find in the page, FALSE otherwise. */ - public function hasModerationForm() { - return (bool) $this->xpath('//ul[@class="entity-moderation-form"]'); + public function hasModerationForm(bool $exists = TRUE) { + if ($exists) { + $this->assertSession()->elementExists('xpath', '//ul[@class="entity-moderation-form"]'); + } + else { + $this->assertSession()->elementNotExists('xpath', '//ul[@class="entity-moderation-form"]'); + } + return TRUE; } } diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php index de65d5464f..cf3183fa1f 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php @@ -98,8 +98,7 @@ public function testSettingsUI() { 'settings[comment][comment_article][fields][uid]' => FALSE, ]; $this->assertSettings('comment', 'comment_article', FALSE, $edit); - $xpath_err = '//div[contains(@class, "error")]'; - $this->assertNotEmpty($this->xpath($xpath_err), 'Enabling translation only for entity bundles generates a form error.'); + $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]'); // Test that the translation settings are not stored if a non-configurable // language is set as default and the language selector is hidden. @@ -111,7 +110,7 @@ public function testSettingsUI() { 'settings[comment][comment_article][fields][comment_body]' => TRUE, ]; $this->assertSettings('comment', 'comment_article', FALSE, $edit); - $this->assertNotEmpty($this->xpath($xpath_err), 'Enabling translation with a fixed non-configurable language generates a form error.'); + $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]'); // Test that a field shared among different bundles can be enabled without // needing to make all the related bundles translatable. diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php index e853e595df..cb1ee5d106 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php @@ -263,12 +263,12 @@ protected function doTestOutdatedStatus() { if ($added_langcode == $langcode) { // Verify that the retranslate flag is not checked by default. $this->assertSession()->fieldValueEquals('content_translation[retranslate]', FALSE); - $this->assertEmpty($this->xpath('//details[@id="edit-content-translation" and @open="open"]'), 'The translation tab should be collapsed by default.'); + $this->assertSession()->elementNotExists('xpath', '//details[@id="edit-content-translation" and @open="open"]'); } else { // Verify that the translate flag is checked by default. $this->assertSession()->fieldValueEquals('content_translation[outdated]', TRUE); - $this->assertNotEmpty($this->xpath('//details[@id="edit-content-translation" and @open="open"]'), 'The translation tab is correctly expanded when the translation is outdated.'); + $this->assertSession()->elementExists('xpath', '//details[@id="edit-content-translation" and @open="open"]'); $edit = ['content_translation[outdated]' => FALSE]; $this->drupalGet($url); $this->submitForm($edit, $this->getFormSubmitAction($entity, $added_langcode)); diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php index aabea9e313..e8756d62cc 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUntranslatableFieldsTest.php @@ -88,9 +88,9 @@ public function testHiddenWidgets() { $en_edit_url = $entity->toUrl('edit-form'); $this->drupalGet($en_edit_url); $field_xpath = '//input[@name="' . $this->fieldName . '[0][value]"]'; - $this->assertNotEmpty($this->xpath($field_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); $clue_xpath = '//label[@for="edit-' . strtr($this->fieldName, '_', '-') . '-0-value"]/span[text()="(all languages)"]'; - $this->assertEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementNotExists('xpath', $clue_xpath); $this->assertSession()->pageTextContains('Untranslatable-but-visible test field'); // Add a translation and check that the untranslatable field widget is @@ -102,20 +102,20 @@ public function testHiddenWidgets() { 'target' => 'it', ]); $this->drupalGet($add_url); - $this->assertNotEmpty($this->xpath($field_xpath)); - $this->assertNotEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); + $this->assertSession()->elementExists('xpath', $clue_xpath); $this->assertSession()->pageTextContains('Untranslatable-but-visible test field'); $this->submitForm([], 'Save'); // Check that the widget is displayed along with its clue in the edit form // for both languages. $this->drupalGet($en_edit_url); - $this->assertNotEmpty($this->xpath($field_xpath)); - $this->assertNotEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); + $this->assertSession()->elementExists('xpath', $clue_xpath); $it_edit_url = $entity->toUrl('edit-form', ['language' => ConfigurableLanguage::load('it')]); $this->drupalGet($it_edit_url); - $this->assertNotEmpty($this->xpath($field_xpath)); - $this->assertNotEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); + $this->assertSession()->elementExists('xpath', $clue_xpath); // Configure untranslatable field widgets to be hidden on non-default // language edit forms. @@ -128,22 +128,19 @@ public function testHiddenWidgets() { // but no clue is displayed. $this->drupalGet($en_edit_url); $field_xpath = '//input[@name="' . $this->fieldName . '[0][value]"]'; - $this->assertNotEmpty($this->xpath($field_xpath)); - $this->assertEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); + $this->assertSession()->elementNotExists('xpath', $clue_xpath); $this->assertSession()->pageTextContains('Untranslatable-but-visible test field'); // Verify no widget is displayed on the non-default language edit form. $this->drupalGet($it_edit_url); - $this->assertEmpty($this->xpath($field_xpath)); - $this->assertEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementNotExists('xpath', $field_xpath); + $this->assertSession()->elementNotExists('xpath', $clue_xpath); $this->assertSession()->pageTextContains('Untranslatable-but-visible test field'); // Verify a warning is displayed. $this->assertSession()->pageTextContains('Fields that apply to all languages are hidden to avoid conflicting changes.'); - $edit_path = $entity->toUrl('edit-form')->toString(); - $link_xpath = '//a[@href=:edit_path and text()="Edit them on the original language form"]'; - $elements = $this->xpath($link_xpath, [':edit_path' => $edit_path]); - $this->assertNotEmpty($elements); + $this->assertSession()->elementExists('xpath', '//a[@href="' . $entity->toUrl('edit-form')->toString() . '" and text()="Edit them on the original language form"]'); // Configure untranslatable field widgets to be displayed on non-default // language edit forms. @@ -153,23 +150,22 @@ public function testHiddenWidgets() { // Check that the widget is displayed along with its clue in the edit form // for both languages. $this->drupalGet($en_edit_url); - $this->assertNotEmpty($this->xpath($field_xpath)); - $this->assertNotEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); + $this->assertSession()->elementExists('xpath', $clue_xpath); $this->drupalGet($it_edit_url); - $this->assertNotEmpty($this->xpath($field_xpath)); - $this->assertNotEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementExists('xpath', $field_xpath); + $this->assertSession()->elementExists('xpath', $clue_xpath); // Enable content moderation and verify that widgets are hidden despite them // being configured to be displayed. $this->enableContentModeration(); $this->drupalGet($it_edit_url); - $this->assertEmpty($this->xpath($field_xpath)); - $this->assertEmpty($this->xpath($clue_xpath)); + $this->assertSession()->elementNotExists('xpath', $field_xpath); + $this->assertSession()->elementNotExists('xpath', $clue_xpath); // Verify a warning is displayed. $this->assertSession()->pageTextContains('Fields that apply to all languages are hidden to avoid conflicting changes.'); - $elements = $this->xpath($link_xpath, [':edit_path' => $edit_path]); - $this->assertNotEmpty($elements); + $this->assertSession()->elementExists('xpath', '//a[@href="' . $entity->toUrl('edit-form')->toString() . '" and text()="Edit them on the original language form"]'); // Verify that checkboxes on the language content settings page are checked // and disabled for moderated bundles. diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php index 7355414411..c4d3c45e53 100644 --- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php +++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php @@ -918,8 +918,7 @@ public function testDateStorageSettings() { $this->drupalGet('node/add/date_content'); $this->submitForm($edit, 'Save'); $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage'); - $result = $this->xpath("//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]"); - $this->assertCount(1, $result, "Changing datetime setting is disabled."); + $this->assertSession()->elementsCount('xpath', "//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]", 1); $this->assertSession()->pageTextContains('There is data for this field in the database. The field settings can no longer be changed.'); } diff --git a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php index 3d323450b8..024042be89 100644 --- a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php +++ b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php @@ -1416,8 +1416,7 @@ public function testDateStorageSettings() { $this->drupalGet('node/add/date_content'); $this->submitForm($edit, 'Save'); $this->drupalGet('admin/structure/types/manage/date_content/fields/node.date_content.' . $field_name . '/storage'); - $result = $this->xpath("//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]"); - $this->assertCount(1, $result, "Changing datetime setting is disabled."); + $this->assertSession()->elementsCount('xpath', "//*[@id='edit-settings-datetime-type' and contains(@disabled, 'disabled')]", 1); $this->assertSession()->pageTextContains('There is data for this field in the database. The field settings can no longer be changed.'); } diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index f83931cf4d..b499f6cd46 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -160,10 +160,11 @@ public function test403LogEventPage() { $wid = $query->execute()->fetchField(); $this->drupalGet('admin/reports/dblog/event/' . $wid); - $table = $this->xpath("//table[@class='dblog-event']"); - $this->assertCount(1, $table); + $table_xpath = "//table[@class='dblog-event']"; + $this->assertSession()->elementsCount('xpath', $table_xpath, 1); // Verify type, severity and location. + $table_xpath = $this->xpath($table_xpath); $type = $table[0]->findAll('xpath', "//tr/th[contains(text(), 'Type')]/../td"); $this->assertCount(1, $type); $this->assertEquals('access denied', $type[0]->getText()); @@ -367,8 +368,7 @@ private function verifyBreadcrumbs() { $query->addExpression('MIN([wid])'); $wid = $query->execute()->fetchField(); $this->drupalGet('admin/reports/dblog/event/' . $wid); - $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEquals('Recent log messages', current($this->xpath($xpath))->getText(), 'DBLogs link displayed at breadcrumb in event page.'); + $this->assertSession()->elementTextEquals('xpath', '//nav[@class="breadcrumb"]/ol/li[last()]/a', 'Recent log messages'); } /** diff --git a/core/modules/editor/tests/src/Functional/EditorLoadingTest.php b/core/modules/editor/tests/src/Functional/EditorLoadingTest.php index 51f7c5d81c..50ed06c214 100644 --- a/core/modules/editor/tests/src/Functional/EditorLoadingTest.php +++ b/core/modules/editor/tests/src/Functional/EditorLoadingTest.php @@ -150,7 +150,7 @@ public function testLoading() { [, $editor_settings_present, $editor_js_present, $body] = $this->getThingsToCheck('body'); $this->assertFalse($editor_settings_present, 'No Text Editor module settings.'); $this->assertFalse($editor_js_present, 'No Text Editor JavaScript.'); - $this->assertCount(1, $body, 'A body field exists.'); + $this->assertSession()->elementsCount('xpath', $body, 1); $this->assertSession()->elementNotExists('css', 'select.js-filter-list'); $this->drupalLogout($this->normalUser); @@ -174,7 +174,7 @@ public function testLoading() { $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page."); $this->assertSame($expected, $settings['editor'], "Text Editor module's JavaScript settings on the page are correct."); $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.'); - $this->assertCount(1, $body, 'A body field exists.'); + $this->assertSession()->elementsCount('xpath', $body, 1); $this->assertSession()->elementsCount('css', 'select.js-filter-list', 1); $select = $this->assertSession()->elementExists('css', 'select.js-filter-list'); $this->assertSame('edit-body-0-value', $select->getAttribute('data-editor-for')); @@ -212,7 +212,7 @@ public function testLoading() { $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page."); $this->assertSame($expected, $settings['editor'], "Text Editor module's JavaScript settings on the page are correct."); $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.'); - $this->assertCount(1, $body, 'A body field exists.'); + $this->assertSession()->elementsCount('xpath', $body, 1); $this->assertSession()->elementNotExists('css', 'select.js-filter-list'); // Verify that a single text format hidden input exists on the page and has // a "data-editor-for" attribute with the correct value. @@ -236,7 +236,7 @@ public function testLoading() { [, $editor_settings_present, $editor_js_present, $body] = $this->getThingsToCheck('body'); $this->assertTrue($editor_settings_present, 'Text Editor module settings.'); $this->assertTrue($editor_js_present, 'Text Editor JavaScript.'); - $this->assertCount(1, $body, 'A body field exists.'); + $this->assertSession()->elementsCount('xpath', $body, 1); $this->assertSession()->fieldDisabled("edit-body-0-value"); $this->assertSession()->fieldValueEquals("edit-body-0-value", 'This field has been disabled because you do not have sufficient permissions to edit it.'); $this->assertSession()->elementNotExists('css', 'select.js-filter-list'); @@ -276,7 +276,7 @@ public function testSupportedElementTypes() { [, $editor_settings_present, $editor_js_present, $field] = $this->getThingsToCheck('field-text', 'input'); $this->assertTrue($editor_settings_present, "Text Editor module's JavaScript settings are on the page."); $this->assertTrue($editor_js_present, 'Text Editor JavaScript is present.'); - $this->assertCount(1, $field, 'A text field exists.'); + $this->assertSession()->elementsCount('xpath', $field, 1); // Verify that a single text format selector exists on the page and has the // "editor" class and a "data-editor-for" attribute with the correct value. $this->assertSession()->elementsCount('css', 'select.js-filter-list', 1); @@ -295,7 +295,7 @@ public function testSupportedElementTypes() { [, $editor_settings_present, $editor_js_present, $field] = $this->getThingsToCheck('field-text', 'input'); $this->assertFalse($editor_settings_present, "Text Editor module's JavaScript settings are not on the page."); $this->assertFalse($editor_js_present, 'Text Editor JavaScript is not present.'); - $this->assertCount(1, $field, 'A text field exists.'); + $this->assertSession()->elementsCount('xpath', $field, 1); // Verify that a single text format selector exists on the page but without // the "editor" class or a "data-editor-for" attribute with the expected // value. @@ -315,7 +315,7 @@ protected function getThingsToCheck($field_name, $type = 'textarea') { // Editor.module's JS present. strpos($this->getSession()->getPage()->getContent(), $this->getModulePath('editor') . '/js/editor.js') !== FALSE, // Body field. - $this->xpath('//' . $type . '[@id="edit-' . $field_name . '-0-value"]'), + '//' . $type . '[@id="edit-' . $field_name . '-0-value"]', ]; }