diff --git a/core/modules/block/tests/src/Functional/BlockHtmlTest.php b/core/modules/block/tests/src/Functional/BlockHtmlTest.php
index 8944c7a3cb..f6e8a28419 100644
--- a/core/modules/block/tests/src/Functional/BlockHtmlTest.php
+++ b/core/modules/block/tests/src/Functional/BlockHtmlTest.php
@@ -45,7 +45,7 @@ public function testHtml() {
// Ensure that a block's ID is converted to an HTML valid ID, and that
// block-specific attributes are added to the same DOM element.
- $this->assertFieldByXPath('//div[@id="block-test-html-block" and @data-custom-attribute="foo"]', NULL, 'HTML ID and attributes for test block are valid and on the same DOM element.');
+ $this->assertSession()->elementExists('xpath', '//div[@id="block-test-html-block" and @data-custom-attribute="foo"]');
// Ensure expected markup for a menu block.
$elements = $this->xpath('//nav[contains(@class, :nav-class)]/ul[contains(@class, :ul-class)]/li', [':nav-class' => 'block-menu', ':ul-class' => 'menu']);
diff --git a/core/modules/block/tests/src/Functional/BlockTest.php b/core/modules/block/tests/src/Functional/BlockTest.php
index a7ab47a4c8..773694db6f 100644
--- a/core/modules/block/tests/src/Functional/BlockTest.php
+++ b/core/modules/block/tests/src/Functional/BlockTest.php
@@ -224,7 +224,7 @@ public function testBlock() {
// Check for
if the machine name
// is my_block_instance_name.
$xpath = $this->assertSession()->buildXPathQuery('//div[@id=:id]/*', [':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))]);
- $this->assertNoFieldByXPath($xpath, FALSE, 'Block found in no regions.');
+ $this->assertSession()->elementNotExists('xpath', $xpath);
// Test deleting the block from the edit form.
$this->drupalGet('admin/structure/block/manage/' . $block['id']);
@@ -352,7 +352,7 @@ public function moveBlockToRegion(array $block, $region) {
':region-class' => 'region region-' . Html::getClass($region),
':block-id' => 'block-' . str_replace('_', '-', strtolower($block['id'])),
]);
- $this->assertFieldByXPath($xpath, NULL, t('Block found in %region_name region.', ['%region_name' => Html::getClass($region)]));
+ $this->assertSession()->elementExists('xpath', $xpath);
}
/**
diff --git a/core/modules/block/tests/src/Functional/BlockUiTest.php b/core/modules/block/tests/src/Functional/BlockUiTest.php
index f396a306cd..2a80a81f95 100644
--- a/core/modules/block/tests/src/Functional/BlockUiTest.php
+++ b/core/modules/block/tests/src/Functional/BlockUiTest.php
@@ -270,7 +270,7 @@ public function testContextAwareBlocks() {
// Tests that conditions with missing context are not displayed.
$this->drupalGet('admin/structure/block/manage/testcontextawareblock');
$this->assertNoRaw('No existing type');
- $this->assertNoFieldByXPath('//*[@name="visibility[condition_test_no_existing_type][negate]"]');
+ $this->assertSession()->elementNotExists('xpath', '//*[@name="visibility[condition_test_no_existing_type][negate]"]');
}
/**
diff --git a/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php b/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php
index 54dc07e3f2..aad9519b72 100644
--- a/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php
+++ b/core/modules/block_content/tests/src/Functional/BlockContentCreationTest.php
@@ -65,7 +65,7 @@ public function testBlockContentCreation() {
]));
// Check that the view mode setting is hidden because only one exists.
- $this->assertNoFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting hidden because only one exists');
+ $this->assertSession()->fieldNotExists('settings[view_mode]');
// Check that the block exists in the database.
$blocks = \Drupal::entityTypeManager()
@@ -140,7 +140,7 @@ public function testBlockContentCreationMultipleViewModes() {
// Check that the view mode setting is shown because more than one exists.
$this->drupalGet('admin/structure/block/manage/testblock');
- $this->assertFieldByXPath('//select[@name="settings[view_mode]"]', NULL, 'View mode setting shown because multiple exist');
+ $this->assertSession()->fieldExists('settings[view_mode]');
// Change the view mode.
$view_mode['region'] = 'content';
@@ -149,7 +149,7 @@ public function testBlockContentCreationMultipleViewModes() {
// Go to the configure page and verify the view mode has changed.
$this->drupalGet('admin/structure/block/manage/testblock');
- $this->assertFieldByXPath('//select[@name="settings[view_mode]"]/option[@selected="selected"]', 'test_view_mode', 'View mode changed to Test View Mode');
+ $this->assertSession()->fieldValueEquals('settings[view_mode]', 'test_view_mode');
// Check that the block exists in the database.
$blocks = \Drupal::entityTypeManager()
diff --git a/core/modules/block_content/tests/src/Functional/BlockContentListTest.php b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php
index 695987ade4..9ac4150c5b 100644
--- a/core/modules/block_content/tests/src/Functional/BlockContentListTest.php
+++ b/core/modules/block_content/tests/src/Functional/BlockContentListTest.php
@@ -68,7 +68,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page).
- $this->assertFieldByXpath('//td', $label, 'Label found for added block.');
+ $this->assertSession()->elementTextContains('xpath', '//td', $label);
// Check the number of table row cells.
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td');
@@ -98,7 +98,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page).
- $this->assertFieldByXpath('//td', $new_label, 'Label found for updated custom block.');
+ $this->assertSession()->elementTextContains('xpath', '//td', $new_label);
// Delete the added entity using the operations link.
$this->assertSession()->linkByHrefExists('block/' . $block->id() . '/delete');
@@ -110,7 +110,7 @@ public function testListing() {
// Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page).
- $this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
+ $this->assertSession()->elementTextNotContains('xpath', '//td', $new_label);
// Confirm that the empty text is displayed.
$this->assertText(t('There are no custom blocks yet.'));
diff --git a/core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php b/core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php
index 88e42a2170..638ce2dec9 100644
--- a/core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php
+++ b/core/modules/block_content/tests/src/Functional/BlockContentListViewsTest.php
@@ -80,7 +80,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page).
- $this->assertFieldByXpath('//td/a', $label, 'Label found for added block.');
+ $this->assertSession()->elementTextContains('xpath', '//td/a', $label);
// Check the number of table row cells.
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td');
@@ -110,7 +110,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page).
- $this->assertFieldByXpath('//td/a', $new_label, 'Label found for updated custom block.');
+ $this->assertSession()->elementTextContains('xpath', '//td/a', $new_label);
// Delete the added entity using the operations link.
$this->assertSession()->linkByHrefExists('block/' . $block->id() . '/delete');
@@ -122,7 +122,7 @@ public function testListing() {
// Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page).
- $this->assertNoFieldByXpath('//td', $new_label, 'No label found for deleted custom block.');
+ $this->assertSession()->elementTextNotContains('xpath', '//td', $new_label);
// Confirm that the empty text is displayed.
$this->assertText('There are no custom blocks available.');
diff --git a/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php b/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php
index 4f35718047..4d4094692f 100644
--- a/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php
+++ b/core/modules/ckeditor/tests/src/Functional/CKEditorAdminTest.php
@@ -140,7 +140,7 @@ public function testExistingFormat() {
// Ensure the styles textarea exists and is initialized empty.
$styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]');
- $this->assertFieldByXPath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]', '', 'The styles textarea exists and is empty.');
+ $this->assertSession()->fieldValueEquals('editor[settings][plugins][stylescombo][styles]', '');
$this->assertCount(1, $styles_textarea, 'The "styles" textarea exists.');
// Submit the form to save the selection of CKEditor as the chosen editor.
@@ -284,7 +284,7 @@ public function testNewFormat() {
// Ensure the styles textarea exists and is initialized empty.
$styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]');
- $this->assertFieldByXPath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]', '', 'The styles textarea exists and is empty.');
+ $this->assertSession()->fieldValueEquals('editor[settings][plugins][stylescombo][styles]', '');
$this->assertCount(1, $styles_textarea, 'The "styles" textarea exists.');
// Submit the form to create both a new text format and an associated text
diff --git a/core/modules/comment/tests/src/Functional/CommentPreviewTest.php b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php
index ffdcd3d53f..4f0f8d8c88 100644
--- a/core/modules/comment/tests/src/Functional/CommentPreviewTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php
@@ -76,7 +76,7 @@ public function testCommentPreview() {
$this->assertSession()->fieldValueEquals('comment_body[0][value]', $edit['comment_body[0][value]']);
// Check that the user picture is displayed.
- $this->assertFieldByXPath("//article[contains(@class, 'preview')]//div[contains(@class, 'user-picture')]//img", NULL, 'User picture displayed.');
+ $this->assertSession()->elementExists('xpath', "//article[contains(@class, 'preview')]//div[contains(@class, 'user-picture')]//img");
}
/**
diff --git a/core/modules/comment/tests/src/Functional/CommentThreadingTest.php b/core/modules/comment/tests/src/Functional/CommentThreadingTest.php
index 50217d38c1..e4407d34cd 100644
--- a/core/modules/comment/tests/src/Functional/CommentThreadingTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentThreadingTest.php
@@ -2,7 +2,6 @@
namespace Drupal\Tests\comment\Functional;
-use Drupal\Component\Render\FormattableMarkup;
use Drupal\comment\CommentManagerInterface;
/**
@@ -143,13 +142,7 @@ protected function assertParentLink($cid, $pid) {
//
$pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]//a[contains(@href, 'comment-$pid')]";
- $this->assertFieldByXpath($pattern, NULL, new FormattableMarkup(
- 'Comment %cid has a link to parent %pid.',
- [
- '%cid' => $cid,
- '%pid' => $pid,
- ]
- ));
+ $this->assertSession()->elementExists('xpath', $pattern);
}
/**
@@ -166,12 +159,7 @@ protected function assertNoParentLink($cid) {
//
$pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]";
- $this->assertNoFieldByXpath($pattern, NULL, new FormattableMarkup(
- 'Comment %cid does not have a link to a parent.',
- [
- '%cid' => $cid,
- ]
- ));
+ $this->assertSession()->elementNotExists('xpath', $pattern);
}
}
diff --git a/core/modules/config/tests/src/Functional/ConfigEntityListTest.php b/core/modules/config/tests/src/Functional/ConfigEntityListTest.php
index 95358c8e6a..ddba30c94a 100644
--- a/core/modules/config/tests/src/Functional/ConfigEntityListTest.php
+++ b/core/modules/config/tests/src/Functional/ConfigEntityListTest.php
@@ -209,8 +209,8 @@ public function testListUI() {
// Confirm that the user is returned to the listing, and verify that the
// text of the label and machine name appears in the list (versus elsewhere
// on the page).
- $this->assertFieldByXpath('//td', 'Antelope', "Label found for added 'Antelope' entity.");
- $this->assertFieldByXpath('//td', 'antelope', "Machine name found for added 'Antelope' entity.");
+ $this->assertSession()->elementExists('xpath', '//td[text() = "Antelope"]');
+ $this->assertSession()->elementExists('xpath', '//td[text() = "antelope"]');
// Edit the entity using the operations link.
$this->assertSession()->linkByHrefExists('admin/structure/config_test/manage/antelope');
@@ -223,8 +223,8 @@ public function testListUI() {
// Confirm that the user is returned to the listing, and verify that the
// text of the label and machine name appears in the list (versus elsewhere
// on the page).
- $this->assertFieldByXpath('//td', 'Albatross', "Label found for updated 'Albatross' entity.");
- $this->assertFieldByXpath('//td', 'albatross', "Machine name found for updated 'Albatross' entity.");
+ $this->assertSession()->elementExists('xpath', '//td[text() = "Albatross"]');
+ $this->assertSession()->elementExists('xpath', '//td[text() = "albatross"]');
// Delete the added entity using the operations link.
$this->assertSession()->linkByHrefExists('admin/structure/config_test/manage/albatross/delete');
@@ -235,8 +235,8 @@ public function testListUI() {
// Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page).
- $this->assertNoFieldByXpath('//td', 'Albatross', "No label found for deleted 'Albatross' entity.");
- $this->assertNoFieldByXpath('//td', 'albatross', "No machine name found for deleted 'Albatross' entity.");
+ $this->assertSession()->elementNotExists('xpath', '//td[text() = "Albatross"]');
+ $this->assertSession()->elementNotExists('xpath', '//td[text() = "albatross"]');
// Delete the original entity using the operations link.
$this->clickLink('Delete');
@@ -246,8 +246,8 @@ public function testListUI() {
// Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page).
- $this->assertNoFieldByXpath('//td', 'Default', "No label found for deleted 'Default' entity.");
- $this->assertNoFieldByXpath('//td', 'dotted.default', "No machine name found for deleted 'Default' entity.");
+ $this->assertSession()->elementNotExists('xpath', '//td[text() = "Default"]');
+ $this->assertSession()->elementNotExists('xpath', '//td[text() = "dotted.default"]');
// Confirm that the empty text is displayed.
$this->assertText('There are no test configuration entities yet.');
diff --git a/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php b/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php
index 1f3ae8fe25..60cd67689e 100644
--- a/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php
+++ b/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php
@@ -243,8 +243,10 @@ public function testImportSimpleConfiguration() {
public function testExport() {
$this->drupalLogin($this->drupalCreateUser(['export configuration']));
+ // Verify that the simple configuration option is selected when specified
+ // in the URL.
$this->drupalGet('admin/config/development/configuration/single/export/system.simple');
- $this->assertFieldByXPath('//select[@name="config_type"]//option[@selected="selected"]', t('Simple configuration'), 'The simple configuration option is selected when specified in the URL.');
+ $this->assertTrue($this->assertSession()->optionExists("config_type", 'Simple configuration')->isSelected());
// Spot check several known simple configuration files.
$element = $this->xpath('//select[@name="config_name"]')[0];
$options = $element->findAll('css', 'option');
@@ -257,12 +259,15 @@ public function testExport() {
$this->drupalGet('admin/config/development/configuration/single/export/system.simple/system.image');
$this->assertEquals("toolkit: gd\n_core:\n default_config_hash: durWHaKeBaq4d9Wpi4RqwADj1OufDepcnJuhVLmKN24\n", $this->xpath('//textarea[@name="export"]')[0]->getValue(), 'The expected system configuration is displayed.');
+ // Verify that the date format entity type is selected when specified in
+ // the URL.
$this->drupalGet('admin/config/development/configuration/single/export/date_format');
- $this->assertFieldByXPath('//select[@name="config_type"]//option[@selected="selected"]', t('Date format'), 'The date format entity type is selected when specified in the URL.');
+ $this->assertTrue($this->assertSession()->optionExists("config_type", 'Date format')->isSelected());
+ // Verify that the fallback date format config entity is selected when
+ // specified in the URL.
$this->drupalGet('admin/config/development/configuration/single/export/date_format/fallback');
- $this->assertFieldByXPath('//select[@name="config_name"]//option[@selected="selected"]', t('Fallback date format (fallback)'), 'The fallback date format config entity is selected when specified in the URL.');
-
+ $this->assertTrue($this->assertSession()->optionExists("config_name", 'Fallback date format (fallback)')->isSelected());
$fallback_date = \Drupal::entityTypeManager()->getStorage('date_format')->load('fallback');
$yaml_text = $this->xpath('//textarea[@name="export"]')[0]->getValue();
$this->assertEquals(Yaml::decode($yaml_text), $fallback_date->toArray(), 'The fallback date format config entity export code is displayed.');
diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
index 65f9be8fab..2bfba1d82f 100644
--- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
+++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
@@ -535,8 +535,7 @@ public function testAccountSettingsConfigurationTranslation() {
$this->drupalGet('admin/config/people/accounts/translate/fr/edit');
foreach ($edit as $key => $value) {
// Check the translations appear in the right field type as well.
- $xpath = '//' . (strpos($key, '[body]') ? 'textarea' : 'input') . '[@name="' . $key . '"]';
- $this->assertFieldByXPath($xpath, $value);
+ $this->assertSession()->fieldValueEquals($key, $value);
}
// Check that labels for email settings appear.
$this->assertText(t('Account cancellation confirmation'));
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php
index 3ee7c289f6..ec8ab1f872 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php
@@ -283,7 +283,7 @@ public function testFieldTranslatableSettingsUI() {
// translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.field_article_text';
$this->drupalGet($path);
- $this->assertFieldByXPath('//input[@id="edit-translatable" and @disabled="disabled"]');
+ $this->assertSession()->fieldDisabled('edit-translatable');
$this->assertText('To configure translation for this field, enable language support for this type.', 'No translatable setting for field.');
// Tests that field has translatable setting if bundle is translatable.
@@ -296,7 +296,7 @@ public function testFieldTranslatableSettingsUI() {
];
$this->assertSettings('node', 'article', TRUE, $edit);
$this->drupalGet($path);
- $this->assertFieldByXPath('//input[@id="edit-translatable" and not(@disabled) and @checked="checked"]');
+ $this->assertSession()->checkboxChecked('edit-translatable');
$this->assertNoText('To enable translation of this field, enable language support for this type.', 'Translatable setting for field available.');
}
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationStandardFieldsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationStandardFieldsTest.php
index 727d597014..489fc9d0be 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationStandardFieldsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationStandardFieldsTest.php
@@ -58,18 +58,18 @@ public function testFieldTranslatableArticle() {
$this->drupalGet($path);
// Check content block fields.
- $this->assertFieldByXPath("//input[@id='edit-settings-block-content-basic-fields-body' and @checked='checked']");
+ $this->assertSession()->checkboxChecked('edit-settings-block-content-basic-fields-body');
// Check comment fields.
- $this->assertFieldByXPath("//input[@id='edit-settings-comment-comment-fields-comment-body' and @checked='checked']");
+ $this->assertSession()->checkboxChecked('edit-settings-comment-comment-fields-comment-body');
// Check node fields.
- $this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-comment' and @checked='checked']");
- $this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-image' and @checked='checked']");
- $this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-tags' and @checked='checked']");
+ $this->assertSession()->checkboxChecked('edit-settings-node-article-fields-comment');
+ $this->assertSession()->checkboxChecked('edit-settings-node-article-fields-field-image');
+ $this->assertSession()->checkboxChecked('edit-settings-node-article-fields-field-tags');
// Check user fields.
- $this->assertFieldByXPath("//input[@id='edit-settings-user-user-fields-user-picture' and @checked='checked']");
+ $this->assertSession()->checkboxChecked('edit-settings-user-user-fields-user-picture');
}
/**
@@ -78,7 +78,7 @@ public function testFieldTranslatableArticle() {
public function testRevisionLogNotTranslatable() {
$path = 'admin/config/regional/content-language';
$this->drupalGet($path);
- $this->assertNoFieldByXPath("//input[@id='edit-settings-node-article-fields-revision-log']");
+ $this->assertSession()->fieldNotExists('edit-settings-node-article-fields-revision-log');
}
}
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
index 162c5d1f81..f9ae86f2a3 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php
@@ -157,7 +157,8 @@ protected function doTestBasicTranslation() {
}
if ($this->testLanguageSelector) {
- $this->assertNoFieldByXPath('//select[@id="edit-langcode-0-value"]', NULL, 'Language selector correctly disabled on translations.');
+ // Verify that language selector is correctly disabled on translations.
+ $this->assertSession()->fieldNotExists('edit-langcode-0-value');
}
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
@@ -178,7 +179,7 @@ protected function doTestBasicTranslation() {
// This does not save anything, it merely reloads the form and fills in the
// fields with the values from the different source language.
$this->drupalPostForm($add_url, $edit, t('Change'));
- $this->assertFieldByXPath("//input[@name=\"{$this->fieldName}[0][value]\"]", $values[$source_langcode][$this->fieldName][0]['value'], 'Source language correctly switched.');
+ $this->assertSession()->fieldValueEquals("{$this->fieldName}[0][value]", $values[$source_langcode][$this->fieldName][0]['value']);
// Add another translation and mark the other ones as outdated.
$values[$langcode] = $this->getNewEntityValues($langcode);
@@ -256,16 +257,19 @@ protected function doTestOutdatedStatus() {
$url = $entity->toUrl('edit-form', ['language' => ConfigurableLanguage::load($added_langcode)]);
$this->drupalGet($url);
if ($added_langcode == $langcode) {
- $this->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is not checked by default.');
+ // 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.');
}
else {
- $this->assertFieldByXPath('//input[@name="content_translation[outdated]"]', TRUE, 'The translate flag is checked by default.');
+ // 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.');
$edit = ['content_translation[outdated]' => FALSE];
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $added_langcode));
$this->drupalGet($url);
- $this->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is now shown.');
+ // Verify that retranslate flag is now shown.
+ $this->assertSession()->fieldValueEquals('content_translation[retranslate]', FALSE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
@@ -300,7 +304,8 @@ protected function doTestPublishedStatus() {
// Check that the last published translation cannot be unpublished.
$this->drupalGet($entity->toUrl('edit-form'));
- $this->assertFieldByXPath('//input[@name="content_translation[status]" and @disabled="disabled"]', TRUE, 'The last translation is published and cannot be unpublished.');
+ $this->assertSession()->fieldDisabled('content_translation[status]');
+ $this->assertSession()->fieldValueEquals('content_translation[status]', TRUE);
}
/**
diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
index c214765b43..9183e69dd6 100644
--- a/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
+++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationWorkflowsTest.php
@@ -416,7 +416,7 @@ protected function doTestWorkflows(UserInterface $user, $expected_status) {
*/
protected function assertNoSharedElements() {
$language_none = LanguageInterface::LANGCODE_NOT_SPECIFIED;
- return $this->assertNoFieldByXPath("//input[@name='field_test_text[$language_none][0][value]']", NULL, 'Shared elements are not available on the translation form.');
+ return $this->assertSession()->fieldNotExists("field_test_text[$language_none][0][value]");
}
}
diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
index 4ca06b5457..ba0b2d315b 100644
--- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
+++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
@@ -55,10 +55,11 @@ public function testDateField() {
// Display creation form.
$this->drupalGet('entity_test/add');
$this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
- $this->assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class,"js-form-required")]', TRUE, 'Required markup found');
+ $this->assertSession()->elementExists('xpath', '//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class,"js-form-required")]');
$this->assertSession()->fieldNotExists("{$field_name}[0][value][time]");
- $this->assertFieldByXPath('//input[@aria-describedby="edit-' . $field_name . '-0-value--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0-value--description"]', NULL, 'ARIA description found');
+ // ARIA described-by.
+ $this->assertSession()->elementExists('xpath', '//input[@aria-describedby="edit-' . $field_name . '-0-value--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0-value--description"]');
// Build up a date in the UTC timezone. Note that using this will also
// mimic the user in a different timezone simply entering '2012-12-31' via
@@ -249,9 +250,9 @@ public function testDatetimeField() {
$this->drupalGet('entity_test/add');
$this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
$this->assertSession()->fieldValueEquals("{$field_name}[0][value][time]", '');
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
- $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
+ $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
+ $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');
// Build up a date in the UTC timezone.
$value = '2012-12-31 00:00:00';
@@ -413,13 +414,13 @@ public function testDatelistWidget() {
// Display creation form.
$this->drupalGet('entity_test/add');
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
- $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
+ $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
+ $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');
// Assert that Hour and Minute Elements do not appear on Date Only
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-minute\"]", NULL, 'Minute element not found on Date Only.');
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-hour\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-minute\"]");
// Go to the form display page to assert that increment option does not appear on Date Only
$fieldEditUrl = 'entity_test/structure/entity_test/form-display';
@@ -428,7 +429,7 @@ public function testDatelistWidget() {
// Click on the widget settings button to open the widget settings form.
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
$xpathIncr = "//select[starts-with(@id, \"edit-fields-$field_name-settings-edit-form-settings-increment\")]";
- $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.');
+ $this->assertSession()->elementNotExists('xpath', $xpathIncr);
// Change the field to a datetime field.
$this->fieldStorage->setSetting('datetime_type', 'datetime');
@@ -453,28 +454,35 @@ public function testDatelistWidget() {
// Click on the widget settings button to open the widget settings form.
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
- $this->assertFieldByXPath($xpathIncr, NULL, 'Increment element found for Date and time.');
+ $this->assertSession()->elementExists('xpath', $xpathIncr);
// Display creation form.
$this->drupalGet('entity_test/add');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-year\"]", NULL, 'Year element found.');
+ // Year element.
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-year\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-year", '')->isSelected());
$this->assertSession()->optionExists("edit-$field_name-0-value-year", 'Year');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-month\"]", NULL, 'Month element found.');
+ // Month element.
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-month\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-month", '')->isSelected());
$this->assertSession()->optionExists("edit-$field_name-0-value-month", 'Month');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-day\"]", NULL, 'Day element found.');
+ // Day element.
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-day\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-day", '')->isSelected());
$this->assertSession()->optionExists("edit-$field_name-0-value-day", 'Day');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element found.');
+ // Hour element.
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-hour\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-hour", '')->isSelected());
$this->assertSession()->optionExists("edit-$field_name-0-value-hour", 'Hour');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-minute\"]", NULL, 'Minute element found.');
+ // Minute element.
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-minute\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-minute", '')->isSelected());
$this->assertSession()->optionExists("edit-$field_name-0-value-minute", 'Minute');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-second\"]", NULL, 'Second element not found.');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-ampm\"]", NULL, 'AMPM element found.');
+ // No Second element.
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-second\"]");
+ // AMPM element.
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-ampm\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-ampm", '')->isSelected());
$this->assertSession()->optionExists("edit-$field_name-0-value-ampm", 'AM/PM');
@@ -517,9 +525,9 @@ public function testDatelistWidget() {
$this->drupalGet('entity_test/add');
// Other elements are unaffected by the changed settings.
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element found.');
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-hour\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-hour", '')->isSelected());
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-ampm\"]", NULL, 'AMPM element not found.');
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-ampm\"]");
// Submit a valid date and ensure it is accepted.
$date_value = ['year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 17, 'minute' => 15];
diff --git a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
index c4fc4af12b..4d9fde69d8 100644
--- a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
+++ b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
@@ -68,12 +68,12 @@ public function testDateRangeField() {
$this->drupalGet('entity_test/add');
$this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
$this->assertSession()->fieldValueEquals("{$field_name}[0][end_value][date]", '');
- $this->assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]', TRUE, 'Required markup found');
+ $this->assertSession()->elementExists('xpath', '//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]');
$this->assertSession()->fieldNotExists("{$field_name}[0][value][time]");
$this->assertSession()->fieldNotExists("{$field_name}[0][end_value][time]");
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
- $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
+ $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
+ $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');
// Build up dates in the UTC timezone.
$value = '2012-12-31 00:00:00';
@@ -160,7 +160,7 @@ public function testDateRangeField() {
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//div[@data-field-item-attr="foobar"]');
+ $this->assertSession()->elementExists('xpath', '//div[@data-field-item-attr="foobar"]');
// Verify that the plain formatter works.
$this->displayOptions['type'] = 'daterange_plain';
@@ -250,7 +250,7 @@ public function testDateRangeField() {
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//time[@data-field-item-attr="foobar"]');
+ $this->assertSession()->elementExists('xpath', '//time[@data-field-item-attr="foobar"]');
$this->displayOptions['type'] = 'daterange_plain';
$this->displayOptions['settings'] = $this->defaultSettings;
@@ -298,9 +298,9 @@ public function testDatetimeRangeField() {
$this->assertSession()->fieldValueEquals("{$field_name}[0][value][time]", '');
$this->assertSession()->fieldValueEquals("{$field_name}[0][end_value][date]", '');
$this->assertSession()->fieldValueEquals("{$field_name}[0][end_value][time]", '');
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
- $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
+ $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
+ $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');
// Build up dates in the UTC timezone.
$value = '2012-12-31 00:00:00';
@@ -357,7 +357,7 @@ public function testDatetimeRangeField() {
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//div[@data-field-item-attr="foobar"]');
+ $this->assertSession()->elementExists('xpath', '//div[@data-field-item-attr="foobar"]');
// Verify that the plain formatter works.
$this->displayOptions['type'] = 'daterange_plain';
@@ -435,7 +435,7 @@ public function testDatetimeRangeField() {
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//time[@data-field-item-attr="foobar"]');
+ $this->assertSession()->elementExists('xpath', '//time[@data-field-item-attr="foobar"]');
$this->displayOptions['type'] = 'daterange_plain';
$this->displayOptions['settings'] = $this->defaultSettings;
@@ -474,12 +474,12 @@ public function testAlldayRangeField() {
$this->drupalGet('entity_test/add');
$this->assertSession()->fieldValueEquals("{$field_name}[0][value][date]", '');
$this->assertSession()->fieldValueEquals("{$field_name}[0][end_value][date]", '');
- $this->assertFieldByXPath('//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]', TRUE, 'Required markup found');
+ $this->assertSession()->elementExists('xpath', '//*[@id="edit-' . $field_name . '-wrapper"]//label[contains(@class, "js-form-required")]');
$this->assertSession()->fieldNotExists("{$field_name}[0][value][time]");
$this->assertSession()->fieldNotExists("{$field_name}[0][end_value][time]");
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
- $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
+ $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
+ $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');
// Build up dates in the proper timezone.
$value = '2012-12-31 00:00:00';
@@ -530,7 +530,7 @@ public function testAlldayRangeField() {
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//div[@data-field-item-attr="foobar"]');
+ $this->assertSession()->elementExists('xpath', '//div[@data-field-item-attr="foobar"]');
// Verify that the plain formatter works.
$this->displayOptions['type'] = 'daterange_plain';
@@ -611,7 +611,7 @@ public function testAlldayRangeField() {
// Verify that hook_entity_prepare_view can add attributes.
// @see entity_test_entity_prepare_view()
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//div[@data-field-item-attr="foobar"]');
+ $this->assertSession()->elementExists('xpath', '//div[@data-field-item-attr="foobar"]');
$this->displayOptions['type'] = 'daterange_plain';
$this->container->get('entity_display.repository')
@@ -662,15 +662,15 @@ public function testDatelistWidget() {
// Display creation form.
$this->drupalGet('entity_test/add');
- $this->assertFieldByXPath('//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label, 'Fieldset and label found');
- $this->assertFieldByXPath('//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]', NULL, 'ARIA described-by found');
- $this->assertFieldByXPath('//div[@id="edit-' . $field_name . '-0--description"]', NULL, 'ARIA description found');
+ $this->assertSession()->elementTextContains('xpath', '//fieldset[@id="edit-' . $field_name . '-0"]/legend', $field_label);
+ $this->assertSession()->elementExists('xpath', '//fieldset[@aria-describedby="edit-' . $field_name . '-0--description"]');
+ $this->assertSession()->elementExists('xpath', '//div[@id="edit-' . $field_name . '-0--description"]');
// Assert that Hour and Minute Elements do not appear on Date Only.
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-minute\"]", NULL, 'Minute element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-end-value-hour\"]", NULL, 'Hour element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-end-value-minute\"]", NULL, 'Minute element not found on Date Only.');
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-hour\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-minute\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-end-value-hour\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-end-value-minute\"]");
// Go to the form display page to assert that increment option does not
// appear on Date Only.
@@ -680,7 +680,7 @@ public function testDatelistWidget() {
// Click on the widget settings button to open the widget settings form.
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
$xpathIncr = "//select[starts-with(@id, \"edit-fields-$field_name-settings-edit-form-settings-increment\")]";
- $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.');
+ $this->assertSession()->elementNotExists('xpath', $xpathIncr);
// Change the field is set to an all day field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_ALLDAY);
@@ -701,10 +701,10 @@ public function testDatelistWidget() {
$this->drupalGet('entity_test/add');
// Assert that Hour and Minute Elements do not appear on Date Only.
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-minute\"]", NULL, 'Minute element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-end-value-hour\"]", NULL, 'Hour element not found on Date Only.');
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-end-value-minute\"]", NULL, 'Minute element not found on Date Only.');
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-hour\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-minute\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-end-value-hour\"]");
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-end-value-minute\"]");
// Go to the form display page to assert that increment option does not
// appear on Date Only.
@@ -714,7 +714,7 @@ public function testDatelistWidget() {
// Click on the widget settings button to open the widget settings form.
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
$xpathIncr = "//select[starts-with(@id, \"edit-fields-$field_name-settings-edit-form-settings-increment\")]";
- $this->assertNoFieldByXPath($xpathIncr, NULL, 'Increment element not found for Date Only.');
+ $this->assertSession()->elementNotExists('xpath', $xpathIncr);
// Change the field to a datetime field.
$this->fieldStorage->setSetting('datetime_type', DateRangeItem::DATETIME_TYPE_DATETIME);
@@ -740,14 +740,14 @@ public function testDatelistWidget() {
// Click on the widget settings button to open the widget settings form.
$this->drupalPostForm(NULL, [], $field_name . "_settings_edit");
- $this->assertFieldByXPath($xpathIncr, NULL, 'Increment element found for Date and time.');
+ $this->assertSession()->elementExists('xpath', $xpathIncr);
// Display creation form.
$this->drupalGet('entity_test/add');
foreach (['value', 'end-value'] as $column) {
foreach (['year', 'month', 'day', 'hour', 'minute', 'ampm'] as $element) {
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-$column-$element\"]", NULL, $element . ' element found.');
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-$column-$element\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-$column-$element", '')->isSelected());
}
}
@@ -803,12 +803,12 @@ public function testDatelistWidget() {
$this->drupalGet('entity_test/add');
// Other elements are unaffected by the changed settings.
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-value-hour\"]", NULL, 'Hour element found.');
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-value-hour\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-value-hour", '')->isSelected());
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-value-ampm\"]", NULL, 'AMPM element not found.');
- $this->assertFieldByXPath("//*[@id=\"edit-$field_name-0-end-value-hour\"]", NULL, 'Hour element found.');
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-value-ampm\"]");
+ $this->assertSession()->elementExists('xpath', "//*[@id=\"edit-$field_name-0-end-value-hour\"]");
$this->assertTrue($this->assertSession()->optionExists("edit-$field_name-0-end-value-hour", '')->isSelected());
- $this->assertNoFieldByXPath("//*[@id=\"edit-$field_name-0-end-value-ampm\"]", NULL, 'AMPM element not found.');
+ $this->assertSession()->elementNotExists('xpath', "//*[@id=\"edit-$field_name-0-end-value-ampm\"]");
// Submit a valid date and ensure it is accepted.
$start_date_value = ['year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 17, 'minute' => 15];
diff --git a/core/modules/editor/tests/src/Functional/EditorLoadingTest.php b/core/modules/editor/tests/src/Functional/EditorLoadingTest.php
index 5455251d5e..1cdf63b074 100644
--- a/core/modules/editor/tests/src/Functional/EditorLoadingTest.php
+++ b/core/modules/editor/tests/src/Functional/EditorLoadingTest.php
@@ -234,7 +234,8 @@ public function testLoading() {
$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->assertFieldByXPath('//textarea[@id="edit-body-0-value" and @disabled="disabled"]', t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+ $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->assertCount(0, $format_selector, 'No text format selector exists on the page.');
$hidden_input = $this->xpath('//input[@type="hidden" and contains(@class, "editor")]');
$this->assertCount(0, $hidden_input, 'A single text format hidden input does not exist on the page.');
diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php
index dfcce6981d..ba551d1aea 100644
--- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php
+++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAdminTest.php
@@ -323,8 +323,8 @@ public function testMultipleTargetBundles() {
$this->drupalPostForm($path, $edit, 'Save settings');
$this->drupalGet($path);
// Expect a select element with the two vocabularies as options.
- $this->assertFieldByXPath("//select[@name='settings[handler_settings][auto_create_bundle]']/option[@value='" . $vocabularies[0]->id() . "']");
- $this->assertFieldByXPath("//select[@name='settings[handler_settings][auto_create_bundle]']/option[@value='" . $vocabularies[1]->id() . "']");
+ $this->assertSession()->optionExists('settings[handler_settings][auto_create_bundle]', $vocabularies[0]->id());
+ $this->assertSession()->optionExists('settings[handler_settings][auto_create_bundle]', $vocabularies[1]->id());
$edit = [
'settings[handler_settings][auto_create]' => TRUE,
diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php
index 6f2754ad44..b10468b8e9 100644
--- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php
+++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceAutoCreateTest.php
@@ -105,7 +105,7 @@ protected function setUp(): void {
*/
public function testAutoCreate() {
$this->drupalGet('node/add/' . $this->referencingType);
- $this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.');
+ $this->assertSession()->elementExists('xpath', '//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]');
$new_title = $this->randomMachineName();
diff --git a/core/modules/field/tests/src/Functional/FormTest.php b/core/modules/field/tests/src/Functional/FormTest.php
index 133eff05fb..b943148395 100644
--- a/core/modules/field/tests/src/Functional/FormTest.php
+++ b/core/modules/field/tests/src/Functional/FormTest.php
@@ -202,7 +202,7 @@ public function testFieldFormDefaultValue() {
// Display creation form.
$this->drupalGet('entity_test/add');
// Test that the default value is displayed correctly.
- $this->assertFieldByXpath("//input[@name='{$field_name}[0][value]' and @value='$default']");
+ $this->assertSession()->fieldValueEquals("{$field_name}[0][value]", $default);
// Try to submit an empty value.
$edit = [
@@ -413,7 +413,7 @@ public function testFieldFormMultivalueWithRequiredRadio() {
$this->drupalPostForm(NULL, [], t('Add another item'));
// Verify that no error is thrown by the radio element.
- $this->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed.');
+ $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "error")]');
// Verify that the widget is added.
$this->assertSession()->fieldValueEquals("{$field_name}[0][value]", '');
diff --git a/core/modules/field/tests/src/Functional/Number/NumberFieldTest.php b/core/modules/field/tests/src/Functional/Number/NumberFieldTest.php
index 9cbe7c00f6..6073273ed0 100644
--- a/core/modules/field/tests/src/Functional/Number/NumberFieldTest.php
+++ b/core/modules/field/tests/src/Functional/Number/NumberFieldTest.php
@@ -252,7 +252,9 @@ public function testNumberIntegerField() {
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
$this->assertRaw($valid_entry);
- $this->assertNoFieldByXpath('//div[@content="' . $valid_entry . '"]', NULL, 'The "content" attribute is not present since the Prefix is not being displayed');
+ // Verify that the "content" attribute is not present since the Prefix is
+ // not being displayed.
+ $this->assertSession()->elementNotExists('xpath', '//div[@content="' . $valid_entry . '"]');
}
// Test for the content attribute when a Prefix is displayed. Presumably this also tests for the attribute when a Suffix is displayed.
@@ -274,7 +276,9 @@ public function testNumberIntegerField() {
$id = $match[1];
$this->assertText(t('entity_test @id has been created.', ['@id' => $id]), 'Entity was created');
$this->drupalGet('entity_test/' . $id);
- $this->assertFieldByXPath('//div[@content="' . $integer_value . '"]', 'ThePrefix' . $integer_value, 'The "content" attribute has been set to the value of the field, and the prefix is being displayed.');
+ // Verify that the "content" attribute has been set to the value of the
+ // field, and the prefix is being displayed.
+ $this->assertSession()->elementTextContains('xpath', '//div[@content="' . $integer_value . '"]', 'ThePrefix' . $integer_value);
}
/**
diff --git a/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php b/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php
index 6efc3232a4..cef67d975c 100644
--- a/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php
+++ b/core/modules/field/tests/src/FunctionalJavascript/EntityReference/EntityReferenceAdminTest.php
@@ -145,11 +145,11 @@ public function testFieldAdminHandler() {
$this->assertTrue($sorted, 'The "sort by" options are sorted.');
// Test that a non-translatable base field is a sort option.
- $this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='nid']");
+ $this->assertSession()->optionExists('settings[handler_settings][sort][field]', 'nid');
// Test that a translatable base field is a sort option.
- $this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='title']");
+ $this->assertSession()->optionExists('settings[handler_settings][sort][field]', 'title');
// Test that a configurable field is a sort option.
- $this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='body.value']");
+ $this->assertSession()->optionExists('settings[handler_settings][sort][field]', 'body.value');
// Set back to no sort.
$sort_by->setValue('_none');
@@ -162,7 +162,7 @@ public function testFieldAdminHandler() {
], t('Save settings'));
// Check that the field appears in the overview form.
- $this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="field-test"]/td[1]', 'Test', 'Field was created and appears in the overview page.');
+ $this->assertSession()->elementExists('xpath', '//table[@id="field-overview"]//tr[@id="field-test"]/td[1 and text() = "Test"]');
// Check that the field settings form can be submitted again, even when the
// field is required.
diff --git a/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
index 4f8eeafef2..b0a1b6d74f 100644
--- a/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
+++ b/core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php
@@ -287,8 +287,8 @@ public function cardinalitySettings() {
$this->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
$this->assertText('Updated field Body field settings.');
$this->drupalGet($field_edit_path);
- $this->assertFieldByXPath("//select[@name='cardinality']", 'number');
- $this->assertFieldByXPath("//input[@name='cardinality_number']", 6);
+ $this->assertSession()->fieldValueEquals('cardinality', 'number');
+ $this->assertSession()->fieldValueEquals('cardinality_number', 6);
// Check that tabs displayed.
$this->assertSession()->linkExists('Edit');
@@ -320,8 +320,8 @@ public function cardinalitySettings() {
$this->drupalPostForm($field_edit_path, $edit, t('Save field settings'));
$this->assertText('Updated field Body field settings.');
$this->drupalGet($field_edit_path);
- $this->assertFieldByXPath("//select[@name='cardinality']", FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
- $this->assertFieldByXPath("//input[@name='cardinality_number']", 1);
+ $this->assertSession()->fieldValueEquals('cardinality', FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
+ $this->assertSession()->fieldValueEquals('cardinality_number', 1);
// Assert that you can't set the cardinality to a lower number then the
// highest delta of this field but can set it to the same.
@@ -635,7 +635,7 @@ public function testHiddenFields() {
// Check that the newly added field appears on the 'Manage Fields'
// screen.
$this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields');
- $this->assertFieldByXPath('//table[@id="field-overview"]//tr[@id="hidden-test-field"]//td[1]', $field['label'], 'Field was created and appears in the overview page.');
+ $this->assertSession()->elementExists('xpath', '//table[@id="field-overview"]//tr[@id="hidden-test-field"]//td[1 and text() = "' . $field['label'] . '"]');
// Check that the field does not appear in the 're-use existing field' row
// on other bundles.
diff --git a/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php b/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php
index 86b92df295..f091e52e67 100644
--- a/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php
+++ b/core/modules/field_ui/tests/src/Traits/FieldUiTestTrait.php
@@ -58,7 +58,7 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $fi
$this->assertRaw(t('Saved %label configuration.', ['%label' => $label]));
// Check that the field appears in the overview form.
- $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
+ $this->assertSession()->elementExists('xpath', "//table[@id=\"field-overview\"]//tr/td[1 and text()=\"$label\"]");
}
/**
@@ -95,7 +95,7 @@ public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $l
$this->assertRaw(t('Saved %label configuration.', ['%label' => $label]));
// Check that the field appears in the overview form.
- $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
+ $this->assertSession()->elementExists('xpath', "//table[@id=\"field-overview\"]//tr/td[1 and text()=\"$label\"]");
}
/**
@@ -123,7 +123,7 @@ public function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_la
$this->assertRaw(t('The field %label has been deleted from the %type content type.', ['%label' => $label, '%type' => $bundle_label]));
// Check that the field does not appear in the overview form.
- $this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, 'Field does not appear in the overview page.');
+ $this->assertSession()->elementNotExists('xpath', '//table[@id="field-overview"]//span[@class="label-field" and text()="' . $label . '"]');
}
}
diff --git a/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
index 79684571c4..38e18649b1 100644
--- a/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
+++ b/core/modules/file/tests/src/Functional/FileFieldDisplayTest.php
@@ -143,8 +143,8 @@ public function testDefaultFileFieldDisplay() {
$nid = $this->uploadNodeFile($test_file, $field_name, $type_name);
$this->drupalGet('node/' . $nid . '/edit');
- $this->assertFieldByXPath('//input[@type="checkbox" and @name="' . $field_name . '[0][display]"]', NULL, 'Default file display checkbox field exists.');
- $this->assertFieldByXPath('//input[@type="checkbox" and @name="' . $field_name . '[0][display]" and not(@checked)]', NULL, 'Default file display is off.');
+ $this->assertSession()->fieldExists($field_name . '[0][display]');
+ $this->assertSession()->checkboxNotChecked($field_name . '[0][display]');
}
/**
@@ -218,7 +218,7 @@ public function testDescriptionDefaultFileFieldDisplay() {
// Test default formatter.
$this->drupalGet('node/' . $nid);
- $this->assertFieldByXPath('//a[@href="' . $node->{$field_name}->entity->createFileUrl(FALSE) . '"]', $description);
+ $this->assertSession()->elementTextContains('xpath', '//a[@href="' . $node->{$field_name}->entity->createFileUrl(FALSE) . '"]', $description);
// Change formatter to "Table of files".
$display = \Drupal::entityTypeManager()->getStorage('entity_view_display')->load('node.' . $type_name . '.default');
@@ -228,7 +228,7 @@ public function testDescriptionDefaultFileFieldDisplay() {
])->save();
$this->drupalGet('node/' . $nid);
- $this->assertFieldByXPath('//a[@href="' . $node->{$field_name}->entity->createFileUrl(FALSE) . '"]', $description);
+ $this->assertSession()->elementTextContains('xpath', '//a[@href="' . $node->{$field_name}->entity->createFileUrl(FALSE) . '"]', $description);
}
}
diff --git a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
index 156326713c..4cfba900ae 100644
--- a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
+++ b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
@@ -97,13 +97,13 @@ public function testSingleValuedWidget() {
// Ensure the edit page has a remove button instead of an upload button.
$this->drupalGet("node/$nid/edit");
- $this->assertNoFieldByXPath('//input[@type="submit"]', t('Upload'), 'Node with file does not display the "Upload" button.');
- $this->assertFieldByXpath('//input[@type="submit"]', t('Remove'), 'Node with file displays the "Remove" button.');
+ $this->assertSession()->buttonNotExists('Upload');
+ $this->assertSession()->buttonExists('Remove');
$this->drupalPostForm(NULL, [], t('Remove'));
// Ensure the page now has an upload button instead of a remove button.
- $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'After clicking the "Remove" button, it is no longer displayed.');
- $this->assertFieldByXpath('//input[@type="submit"]', t('Upload'), 'After clicking the "Remove" button, the "Upload" button is displayed.');
+ $this->assertSession()->buttonNotExists('Remove');
+ $this->assertSession()->buttonExists('Upload');
// Test label has correct 'for' attribute.
$input = $this->xpath('//input[@name="files[' . $field_name . '_0]"]');
$label = $this->xpath('//label[@for="' . $input[0]->getAttribute('id') . '"]');
@@ -149,7 +149,7 @@ public function testMultiValuedWidget() {
$this->drupalPostForm(NULL, $edit, t('Upload'));
}
}
- $this->assertNoFieldByXpath('//input[@type="submit"]', t('Upload'), 'After uploading 3 files for each field, the "Upload" button is no longer displayed.');
+ $this->assertSession()->buttonNotExists('Upload');
$num_expected_remove_buttons = 6;
@@ -197,7 +197,7 @@ public function testMultiValuedWidget() {
}
// Ensure the page now has no Remove buttons.
- $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), 'After removing all files, there is no "Remove" button displayed.');
+ $this->assertSession()->buttonNotExists('Remove');
// Save the node and ensure it does not have any files.
$this->drupalPostForm(NULL, ['title[0][value]' => $this->randomMachineName()], t('Save'));
@@ -272,12 +272,12 @@ public function testPrivateFileSetting() {
// Ensure we can't change 'uri_scheme' field settings while there are some
// entities with uploaded files.
$this->drupalGet("admin/structure/types/manage/$type_name/fields/$field_id/storage");
- $this->assertFieldByXpath('//input[@id="edit-settings-uri-scheme-public" and @disabled="disabled"]', 'public', 'Upload destination setting disabled.');
+ $this->assertSession()->fieldDisabled("edit-settings-uri-scheme-public");
// Delete node and confirm that setting could be changed.
$node->delete();
$this->drupalGet("admin/structure/types/manage/$type_name/fields/$field_id/storage");
- $this->assertFieldByXpath('//input[@id="edit-settings-uri-scheme-public" and not(@disabled)]', 'public', 'Upload destination setting enabled.');
+ $this->assertSession()->fieldEnabled("edit-settings-uri-scheme-public");
}
/**
diff --git a/core/modules/file/tests/src/Functional/FileManagedFileElementTest.php b/core/modules/file/tests/src/Functional/FileManagedFileElementTest.php
index 8b2176f446..c9f5a2dccb 100644
--- a/core/modules/file/tests/src/Functional/FileManagedFileElementTest.php
+++ b/core/modules/file/tests/src/Functional/FileManagedFileElementTest.php
@@ -24,7 +24,7 @@ class FileManagedFileElementTest extends FileFieldTestBase {
public function testManagedFile() {
// Check that $element['#size'] is passed to the child upload element.
$this->drupalGet('file/test');
- $this->assertFieldByXpath('//input[@name="files[nested_file]" and @size="13"]', NULL, 'The custom #size attribute is passed to the child upload element.');
+ $this->assertSession()->elementExists('xpath', '//input[@name="files[nested_file]" and @size="13"]');
// Perform the tests with all permutations of $form['#tree'],
// $element['#extended'], and $element['#multiple'].
@@ -115,12 +115,12 @@ public function testManagedFile() {
// Add a single file to the upload field.
$this->drupalPostForm(NULL, $edit, t('Upload'));
$fid_list[] = $this->getLastFileId();
- $this->assertFieldByXpath('//input[@name="nested[file][file_' . $fid_list[0] . '][selected]"]', NULL, 'First file successfully uploaded to multiple file element.');
+ $this->assertSession()->fieldExists("nested[file][file_{$fid_list[0]}][selected]");
// Add another file to the same upload field.
$this->drupalPostForm(NULL, $edit, t('Upload'));
$fid_list[] = $this->getLastFileId();
- $this->assertFieldByXpath('//input[@name="nested[file][file_' . $fid_list[1] . '][selected]"]', NULL, 'Second file successfully uploaded to multiple file element.');
+ $this->assertSession()->fieldExists("nested[file][file_{$fid_list[1]}][selected]");
// Save the entire form.
$this->drupalPostForm(NULL, [], t('Save'));
@@ -134,8 +134,8 @@ public function testManagedFile() {
$this->drupalPostForm($path . '/' . implode(',', $fid_list), $edit, t('Remove selected'));
// Check that the first file has been deleted but not the second.
- $this->assertNoFieldByXpath('//input[@name="nested[file][file_' . $fid_list[0] . '][selected]"]', NULL, 'An individual file can be deleted from a multiple file element.');
- $this->assertFieldByXpath('//input[@name="nested[file][file_' . $fid_list[1] . '][selected]"]', NULL, 'Second individual file not deleted when the first file is deleted from a multiple file element.');
+ $this->assertSession()->fieldNotExists("nested[file][file_{$fid_list[0]}][selected]");
+ $this->assertSession()->fieldExists("nested[file][file_{$fid_list[1]}][selected]");
}
/**
diff --git a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
index 1d23e945e0..3a0fedae7d 100644
--- a/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
+++ b/core/modules/filter/tests/src/Functional/FilterFormatAccessTest.php
@@ -235,7 +235,8 @@ public function testFormatWidgetPermissions() {
$this->clickLink(t('Edit'));
// Verify that body field is read-only and contains replacement value.
- $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+ $this->assertSession()->fieldDisabled($body_value_key);
+ $this->assertSession()->fieldValueEquals($body_value_key, 'This field has been disabled because you do not have sufficient permissions to edit it.');
// Verify that title can be changed, but preview displays original body.
$new_edit = [];
@@ -256,7 +257,8 @@ public function testFormatWidgetPermissions() {
// else.)
$this->drupalLogin($this->filterAdminUser);
$this->drupalGet('node/' . $node->id() . '/edit');
- $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+ $this->assertSession()->fieldDisabled($body_value_key);
+ $this->assertSession()->fieldValueEquals($body_value_key, 'This field has been disabled because you do not have sufficient permissions to edit it.');
// Disable the text format used above.
$this->disallowedFormat->disable()->save();
@@ -267,14 +269,15 @@ public function testFormatWidgetPermissions() {
// edit content that does not have an assigned format.
$this->drupalLogin($this->webUser);
$this->drupalGet('node/' . $node->id() . '/edit');
- $this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), 'Text format access denied message found.');
+ $this->assertSession()->fieldDisabled($body_value_key);
+ $this->assertSession()->fieldValueEquals($body_value_key, 'This field has been disabled because you do not have sufficient permissions to edit it.');
// Log back in as the filter administrator and verify that the body field
// can be edited.
$this->drupalLogin($this->filterAdminUser);
$this->drupalGet('node/' . $node->id() . '/edit');
- $this->assertNoFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", NULL, 'Text format access denied message not found.');
- $this->assertFieldByXPath("//select[@name='$body_format_key']", NULL, 'Text format selector found.');
+ $this->assertSession()->fieldEnabled($body_value_key);
+ $this->assertSession()->fieldExists($body_format_key);
// Verify that trying to save the node without selecting a new text format
// produces an error message, and does not result in the node being saved.
diff --git a/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php b/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php
index 3e2bce273a..b04726a101 100644
--- a/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php
+++ b/core/modules/image/tests/src/Functional/ImageFieldDefaultImagesTest.php
@@ -129,46 +129,18 @@ public function testDefaultImages() {
// form.
$field_id = $field->id();
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field_storage']->id(),
- new FormattableMarkup(
- 'Article image field storage default equals expected file ID of @fid.',
- ['@fid' => $default_images['field_storage']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage']->id());
// Confirm the defaults are present on the article field edit form.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field']->id(),
- new FormattableMarkup(
- 'Article image field default equals expected file ID of @fid.',
- ['@fid' => $default_images['field']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field']->id());
// Confirm the defaults are present on the page field storage settings form.
$this->drupalGet("admin/structure/types/manage/page/fields/$field_id/storage");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field_storage']->id(),
- new FormattableMarkup(
- 'Page image field storage default equals expected file ID of @fid.',
- ['@fid' => $default_images['field_storage']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage']->id());
// Confirm the defaults are present on the page field edit form.
$field2_id = $field2->id();
$this->drupalGet("admin/structure/types/manage/page/fields/$field2_id");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field2']->id(),
- new FormattableMarkup(
- 'Page image field default equals expected file ID of @fid.',
- ['@fid' => $default_images['field2']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field2']->id());
// Confirm that the image default is shown for a new article node.
$article = $this->drupalCreateNode(['type' => 'article']);
@@ -210,14 +182,7 @@ public function testDefaultImages() {
// Confirm that the new default is used on the article field storage
// settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field_storage_new']->id(),
- new FormattableMarkup(
- 'Updated image field storage default equals expected file ID of @fid.',
- ['@fid' => $default_images['field_storage_new']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage_new']->id());
// Reload the nodes and confirm the field defaults are used.
$node_storage->resetCache([$article->id(), $page->id()]);
@@ -248,14 +213,7 @@ public function testDefaultImages() {
// Confirm the new field default is used on the article field admin form.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field_new']->id(),
- new FormattableMarkup(
- 'Updated article image field default equals expected file ID of @fid.',
- ['@fid' => $default_images['field_new']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_new']->id());
// Reload the nodes.
$node_storage->resetCache([$article->id(), $page->id()]);
@@ -294,11 +252,7 @@ public function testDefaultImages() {
// Confirm the article field default has been removed.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- '',
- 'Updated article image field default has been successfully removed.'
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', '');
// Reload the nodes.
$node_storage->resetCache([$article->id(), $page->id()]);
@@ -344,14 +298,7 @@ public function testDefaultImages() {
// Confirm that the new default is used on the article field storage
// settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field_storage_private']->id(),
- new FormattableMarkup(
- 'Updated image field storage default equals expected file ID of @fid.',
- ['@fid' => $default_images['field_storage_private']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_storage_private']->id());
// Upload a new default for the article's field after setting the field
// storage upload destination to 'private'.
@@ -363,14 +310,7 @@ public function testDefaultImages() {
// Confirm the new field field default is used on the article field
// admin form.
$this->drupalGet("admin/structure/types/manage/article/fields/$field_id");
- $this->assertFieldByXpath(
- '//input[@name="settings[default_image][uuid][fids]"]',
- $default_images['field_private']->id(),
- new FormattableMarkup(
- 'Updated article image field default equals expected file ID of @fid.',
- ['@fid' => $default_images['field_private']->id()]
- )
- );
+ $this->assertSession()->hiddenFieldValueEquals('settings[default_image][uuid][fids]', $default_images['field_private']->id());
}
/**
diff --git a/core/modules/language/tests/src/Functional/LanguageBlockSettingsVisibilityTest.php b/core/modules/language/tests/src/Functional/LanguageBlockSettingsVisibilityTest.php
index 968957c899..64d9b241c7 100644
--- a/core/modules/language/tests/src/Functional/LanguageBlockSettingsVisibilityTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageBlockSettingsVisibilityTest.php
@@ -27,10 +27,10 @@ public function testUnnecessaryLanguageSettingsVisibility() {
$this->drupalLogin($admin_user);
$this->drupalPostForm('admin/config/regional/language/add', ['predefined_langcode' => 'hu'], t('Add language'));
$this->drupalGet('admin/structure/block/add/system_menu_block:admin/stark');
- $this->assertNoFieldByXPath('//input[@id="edit-visibility-language-langcodes-und"]', NULL, '\'Not specified\' option does not appear at block config, language settings section.');
- $this->assertNoFieldByXpath('//input[@id="edit-visibility-language-langcodes-zxx"]', NULL, '\'Not applicable\' option does not appear at block config, language settings section.');
- $this->assertFieldByXPath('//input[@id="edit-visibility-language-langcodes-en"]', NULL, '\'English\' option appears at block config, language settings section.');
- $this->assertFieldByXpath('//input[@id="edit-visibility-language-langcodes-hu"]', NULL, '\'Hungarian\' option appears at block config, language settings section.');
+ $this->assertSession()->fieldNotExists("edit-visibility-language-langcodes-und");
+ $this->assertSession()->fieldNotExists("edit-visibility-language-langcodes-zxx");
+ $this->assertSession()->fieldExists("edit-visibility-language-langcodes-en");
+ $this->assertSession()->fieldExists("edit-visibility-language-langcodes-hu");
}
}
diff --git a/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php b/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php
index c0f417a350..16d782031d 100644
--- a/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageConfigurationTest.php
@@ -44,11 +44,12 @@ public function testLanguageConfiguration() {
// Check if the Default English language has no path prefix.
$this->drupalGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
+ $this->assertSession()->fieldValueEquals("prefix[en]", '');
// Check that Add language is a primary button.
$this->drupalGet('admin/config/regional/language/add');
- $this->assertFieldByXPath('//input[contains(@class, "button--primary")]', 'Add language', 'Add language is a primary button');
+ $button = $this->assertSession()->buttonExists('Add language');
+ $this->assertTrue($button->hasClass("button--primary"));
// Add predefined language.
$edit = [
@@ -63,10 +64,10 @@ public function testLanguageConfiguration() {
// Check if the Default English language has no path prefix.
$this->drupalGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[en]"]', '', 'Default English has no path prefix.');
+ $this->assertSession()->fieldValueEquals("prefix[en]", '');
// Check if French has a path prefix.
$this->drupalGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French has a path prefix.');
+ $this->assertSession()->fieldValueEquals("prefix[fr]", 'fr');
// Check if we can change the default language.
$this->drupalGet('admin/config/regional/language');
@@ -84,17 +85,17 @@ public function testLanguageConfiguration() {
// Check if a valid language prefix is added after changing the default
// language.
$this->drupalGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[en]"]', 'en', 'A valid path prefix has been added to the previous default language.');
+ $this->assertSession()->fieldValueEquals("prefix[en]", 'en');
// Check if French still has a path prefix.
$this->drupalGet('admin/config/regional/language/detection/url');
- $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'fr', 'French still has a path prefix.');
+ $this->assertSession()->fieldValueEquals("prefix[fr]", 'fr');
// Check that prefix can be changed.
$edit = [
'prefix[fr]' => 'french',
];
$this->drupalPostForm(NULL, $edit, t('Save configuration'));
- $this->assertFieldByXPath('//input[@name="prefix[fr]"]', 'french', 'French path prefix has changed.');
+ $this->assertSession()->fieldValueEquals("prefix[fr]", 'french');
// Check that the prefix can be removed.
$edit = [
diff --git a/core/modules/locale/tests/src/Functional/LocaleContentTest.php b/core/modules/locale/tests/src/Functional/LocaleContentTest.php
index 1aa2219439..a70c16a565 100644
--- a/core/modules/locale/tests/src/Functional/LocaleContentTest.php
+++ b/core/modules/locale/tests/src/Functional/LocaleContentTest.php
@@ -43,7 +43,8 @@ public function testMachineNameLTR() {
// Verify that the machine name field is LTR for a new content type.
$this->drupalGet('admin/structure/types/add');
- $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.');
+ $type = $this->assertSession()->fieldExists('type');
+ $this->assertSame('ltr', $type->getAttribute('dir'));
// Install the Arabic language (which is RTL) and configure as the default.
$edit = [];
@@ -57,7 +58,8 @@ public function testMachineNameLTR() {
// Verify that the machine name field is still LTR for a new content type.
$this->drupalGet('admin/structure/types/add');
- $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.');
+ $type = $this->assertSession()->fieldExists('type');
+ $this->assertSame('ltr', $type->getAttribute('dir'));
}
/**
diff --git a/core/modules/node/tests/src/Functional/NodeSyndicateBlockTest.php b/core/modules/node/tests/src/Functional/NodeSyndicateBlockTest.php
index 2cf6e8bbc8..4fd853ad67 100644
--- a/core/modules/node/tests/src/Functional/NodeSyndicateBlockTest.php
+++ b/core/modules/node/tests/src/Functional/NodeSyndicateBlockTest.php
@@ -36,7 +36,7 @@ public function testSyndicateBlock() {
// Place the "Syndicate" block and confirm that it is rendered.
$this->drupalPlaceBlock('node_syndicate_block', ['id' => 'test_syndicate_block']);
$this->drupalGet('');
- $this->assertFieldByXPath('//div[@id="block-test-syndicate-block"]/*', NULL, 'Syndicate block found.');
+ $this->assertSession()->elementExists('xpath', '//div[@id="block-test-syndicate-block"]/*');
}
}
diff --git a/core/modules/path/tests/src/Functional/PathAliasTest.php b/core/modules/path/tests/src/Functional/PathAliasTest.php
index 3772e2b7ed..4cc46c3dc1 100644
--- a/core/modules/path/tests/src/Functional/PathAliasTest.php
+++ b/core/modules/path/tests/src/Functional/PathAliasTest.php
@@ -402,7 +402,8 @@ public function testDuplicateNodeAlias() {
$node_two = $this->drupalCreateNode();
$this->drupalPostForm('node/' . $node_two->id() . '/edit', $edit, t('Save'));
$this->assertSession()->pageTextContains("The alias {$edit['path[0][alias]']} is already in use in this language.");
- $this->assertFieldByXPath("//input[@name='path[0][alias]' and contains(@class, 'error')]", $edit['path[0][alias]'], 'Textfield exists and has the error class.');
+ $path_alias = $this->assertSession()->fieldValueEquals('path[0][alias]', $edit['path[0][alias]']);
+ $this->assertTrue($path_alias->hasClass('error'));
// Behavior here differs with the inline_form_errors module enabled.
// Enable the inline_form_errors module and try this again. This module
diff --git a/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php b/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php
index e1fb108139..af829eab8f 100644
--- a/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php
+++ b/core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php
@@ -135,7 +135,7 @@ public function testUserPermissions() {
// permission to in-place edit.
$this->assertNoRaw('data-quickedit-entity-id="node/1"');
$this->assertNoRaw('data-quickedit-field-id="node/1/body/en/full"');
- $this->assertNoFieldByXPath('//h1[contains(@class, "js-quickedit-page-title")]');
+ $this->assertSession()->elementNotExists('xpath', '//h1[contains(@class, "js-quickedit-page-title")]');
$assert->linkNotExists('Quick edit');
// Tests the loading of Quick Edit when a user does have access to it.
diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
index d493413dee..e577547c65 100644
--- a/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutSetsTest.php
@@ -151,7 +151,7 @@ public function testShortcutSetSwitchNoSetName() {
$this->assertText(t('The new set label is required.'));
$current_set = shortcut_current_displayed_set($this->adminUser);
$this->assertEqual($current_set->id(), $this->set->id(), 'Attempting to switch to a new shortcut set without providing a set name does not succeed.');
- $this->assertFieldByXPath("//input[@name='label' and contains(concat(' ', normalize-space(@class), ' '), ' error ')]", NULL, 'The new set label field has the error class');
+ $this->assertSession()->elementExists('xpath', "//input[@name='label' and contains(concat(' ', normalize-space(@class), ' '), ' error ')]");
}
/**
diff --git a/core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php b/core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php
index 8367fd28c0..8a4e56f0f0 100644
--- a/core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php
+++ b/core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php
@@ -31,7 +31,7 @@ public function testConfirmForm() {
$site_name = $this->config('system.site')->get('name');
$this->assertSession()->titleEquals("ConfirmFormTestForm::getQuestion(). | $site_name");
$this->assertText(t('ConfirmFormTestForm::getDescription().'), 'The description was used.');
- $this->assertFieldByXPath('//input[@id="edit-submit"]', t('ConfirmFormTestForm::getConfirmText().'), 'The confirm text was used.');
+ $this->assertSession()->fieldValueEquals("edit-submit", 'ConfirmFormTestForm::getConfirmText().');
// Test cancelling the form.
$this->clickLink(t('ConfirmFormTestForm::getCancelText().'));
diff --git a/core/modules/system/tests/src/Functional/Form/FormTest.php b/core/modules/system/tests/src/Functional/Form/FormTest.php
index 256cc67e19..d5ce849583 100644
--- a/core/modules/system/tests/src/Functional/Form/FormTest.php
+++ b/core/modules/system/tests/src/Functional/Form/FormTest.php
@@ -232,7 +232,9 @@ public function testRequiredCheckboxesRadio() {
'radios' => 'bar',
];
$this->drupalPostForm(NULL, $edit, 'Submit');
- $this->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed when all required fields are filled.');
+ // Verify that no error message is displayed when all required fields are
+ // filled.
+ $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "error")]');
$this->assertRaw("The form_test_validate_required_form form was submitted successfully.");
}
@@ -259,7 +261,9 @@ public function testInputWithInvalidToken() {
'radios' => 'foo',
];
$this->drupalPostForm(NULL, $edit, 'Submit');
- $this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
+ // Verify that error message is displayed with invalid token even when
+ // required fields are filled.
+ $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]');
$assert = $this->assertSession();
$element = $assert->fieldExists('textfield');
@@ -283,7 +287,9 @@ public function testInputWithInvalidToken() {
'textarea' => $this->randomString() . "\n",
];
$this->drupalPostForm(NULL, $edit, 'Submit');
- $this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
+ // Verify that the error message is displayed with invalid token even when
+ // required fields are filled.
+ $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]');
$this->assertText('The form has become outdated.');
$this->assertSession()->fieldValueEquals('textfield', '');
$this->assertSession()->fieldValueEquals('textarea', '');
@@ -299,7 +305,9 @@ public function testInputWithInvalidToken() {
'integer_step' => mt_rand(6, 100),
];
$this->drupalPostForm(NULL, $edit, 'Submit');
- $this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
+ // Verify that the error message is displayed with invalid token even when
+ // required fields are filled.'
+ $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]');
$this->assertText('The form has become outdated.');
$this->assertSession()->fieldValueEquals('integer_step', 5);
@@ -312,7 +320,9 @@ public function testInputWithInvalidToken() {
'url' => $this->randomString(),
];
$this->drupalPostForm(NULL, $edit, 'Submit');
- $this->assertFieldByXpath('//div[contains(@class, "error")]', NULL, 'Error message is displayed with invalid token even when required fields are filled.');
+ // Verift that the error message is displayed with invalid token even when
+ // required fields are filled.
+ $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]');
$this->assertText('The form has become outdated.');
$this->assertSession()->fieldValueEquals('url', '');
}
@@ -346,10 +356,10 @@ public function testRequiredTextfieldNoTitle() {
$this->assertNoRaw("The form_test_validate_required_form_no_title form was submitted successfully.");
// Check the page for the error class on the textfield.
- $this->assertFieldByXPath('//input[contains(@class, "error")]', FALSE, 'Error input form element class found.');
+ $this->assertSession()->elementExists('xpath', '//input[contains(@class, "error")]');
// Check the page for the aria-invalid attribute on the textfield.
- $this->assertFieldByXPath('//input[contains(@aria-invalid, "true")]', FALSE, 'Aria invalid attribute found.');
+ $this->assertSession()->elementExists('xpath', '//input[contains(@aria-invalid, "true")]');
// Submit again with required fields set and verify that there are no
// error messages.
@@ -357,7 +367,8 @@ public function testRequiredTextfieldNoTitle() {
'textfield' => $this->randomString(),
];
$this->drupalPostForm(NULL, $edit, 'Submit');
- $this->assertNoFieldByXpath('//input[contains(@class, "error")]', FALSE, 'No error input form element class found.');
+ // Verify that no error input form element class is present.
+ $this->assertSession()->elementNotExists('xpath', '//input[contains(@class, "error")]');
$this->assertRaw("The form_test_validate_required_form_no_title form was submitted successfully.");
}
@@ -474,8 +485,8 @@ public function testSelect() {
*/
public function testEmptySelect() {
$this->drupalGet('form-test/empty-select');
- $this->assertFieldByXPath("//select[1]", NULL, 'Select element found.');
- $this->assertNoFieldByXPath("//select[1]/option", NULL, 'No option element found.');
+ $this->assertSession()->elementExists('xpath', "//select[1]");
+ $this->assertSession()->elementNotExists('xpath', "//select[1]/option");
}
/**
@@ -674,7 +685,8 @@ public function testRange() {
$this->assertEqual($values->offset, 6.9);
$this->drupalPostForm('form-test/range/invalid', [], 'Submit');
- $this->assertFieldByXPath('//input[@type="range" and contains(@class, "error")]', NULL, 'Range element has the error class.');
+ // Verify that the 'range' element has the error class.
+ $this->assertSession()->elementExists('xpath', '//input[@type="range" and contains(@class, "error")]');
}
/**
diff --git a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php
index a32a3f939c..1814bdab51 100644
--- a/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php
+++ b/core/modules/system/tests/src/Functional/Form/ModulesListFormWebTest.php
@@ -41,13 +41,13 @@ public function testModuleListForm() {
$this->drupalGet('admin/modules');
// Check that system_test's configure link was rendered correctly.
- $this->assertFieldByXPath("//a[contains(@href, '/system-test/configure/bar') and text()='Configure ']/span[contains(@class, 'visually-hidden') and text()='the System test module']");
+ $this->assertSession()->elementExists('xpath', "//a[contains(@href, '/system-test/configure/bar') and text()='Configure ']/span[contains(@class, 'visually-hidden') and text()='the System test module']");
// Check that system_test's permissions link was rendered correctly.
- $this->assertFieldByXPath("//a[contains(@href, '/admin/people/permissions#module-system_test') and @title='Configure permissions']");
+ $this->assertSession()->elementExists('xpath', "//a[contains(@href, '/admin/people/permissions#module-system_test') and @title='Configure permissions']");
// Check that system_test's help link was rendered correctly.
- $this->assertFieldByXPath("//a[contains(@href, '/admin/help/system_test') and @title='Help']");
+ $this->assertSession()->elementExists('xpath', "//a[contains(@href, '/admin/help/system_test') and @title='Help']");
// Ensure that the Database Logging module's machine name is printed. This
// module is used because its machine name is different than its human
diff --git a/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php b/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php
index 5ddba8bfe0..72258cdb98 100644
--- a/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php
+++ b/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php
@@ -159,7 +159,7 @@ public function testUninstall() {
$this->drupalGet('admin/modules/uninstall/entity/entity_test_no_label');
$this->assertText('There are 0 entity test without label entities to delete.');
$button_xpath = '//input[@type="submit"][@value="Delete all entity test without label entities"]';
- $this->assertNoFieldByXPath($button_xpath, NULL, 'Button with value "Delete all entity test without label entities" not found');
+ $this->assertSession()->elementNotExists('xpath', $button_xpath);
// Test an entity type without a label.
/** @var \Drupal\Core\Entity\EntityStorageInterface $storage */
@@ -171,7 +171,7 @@ public function testUninstall() {
])->save();
$this->drupalGet('admin/modules/uninstall/entity/entity_test_no_label');
$this->assertText('This will delete 1 entity test without label.');
- $this->assertFieldByXPath($button_xpath, NULL, 'Button with value "Delete all entity test without label entities" found');
+ $this->assertSession()->elementExists('xpath', $button_xpath);
$storage->create([
'id' => mb_strtolower($this->randomMachineName()),
'name' => $this->randomMachineName(),
diff --git a/core/modules/user/tests/src/Functional/UserCreateTest.php b/core/modules/user/tests/src/Functional/UserCreateTest.php
index f9037d9aed..896a3f8c3e 100644
--- a/core/modules/user/tests/src/Functional/UserCreateTest.php
+++ b/core/modules/user/tests/src/Functional/UserCreateTest.php
@@ -78,7 +78,7 @@ public function testUserAdd() {
$this->drupalGet('admin/people/create');
$this->assertSession()->fieldValueEquals('edit-status-0', '1');
$this->assertSession()->fieldValueEquals('edit-status-1', '1');
- $this->assertFieldByXPath('//input[@type="radio" and @id="edit-status-1" and @checked="checked"]', NULL, 'Default setting for user status is active.');
+ $this->assertSession()->elementExists('xpath', '//input[@type="radio" and @id="edit-status-1" and @checked="checked"]');
// Test that browser autocomplete behavior does not occur.
$this->assertNoRaw('data-user-info-from-browser');
diff --git a/core/modules/user/tests/src/Functional/UserLoginTest.php b/core/modules/user/tests/src/Functional/UserLoginTest.php
index eafa70d7d5..890510d245 100644
--- a/core/modules/user/tests/src/Functional/UserLoginTest.php
+++ b/core/modules/user/tests/src/Functional/UserLoginTest.php
@@ -172,7 +172,7 @@ public function assertFailedLogin($account, $flood_trigger = NULL) {
'pass' => $account->passRaw,
];
$this->drupalPostForm('user/login', $edit, t('Log in'));
- $this->assertNoFieldByXPath("//input[@name='pass' and @value!='']", NULL, 'Password value attribute is blank.');
+ $this->assertSession()->elementNotExists('xpath', "//input[@name='pass' and @value!='']");
if (isset($flood_trigger)) {
$this->assertSession()->statusCodeEquals(403);
$last_log = $database->select('watchdog', 'w')
diff --git a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
index aa0cd470ff..70ad4236a3 100644
--- a/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/ExposedFormTest.php
@@ -236,10 +236,10 @@ public function testExposedBlock() {
$this->assertCount(1, $result);
// Test there is not an exposed form in the view page content area.
- $xpath = $this->assertSession()->buildXPathQuery('//div[@class="view-content"]/form/@id', [
+ $xpath = $this->assertSession()->buildXPathQuery('//div[@class="view-content"]/form/:id', [
':id' => Html::getUniqueId('block-' . $block->id()),
]);
- $this->assertNoFieldByXpath($xpath, $this->getExpectedExposedFormId($view), 'No exposed form found in views content region.');
+ $this->assertSession()->elementNotExists('xpath', $xpath);
// Test there is only one views exposed form on the page.
$elements = $this->xpath('//form[@id=:id]', [':id' => $this->getExpectedExposedFormId($view)]);
diff --git a/core/modules/views/tests/src/Functional/Plugin/PagerTest.php b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php
index 1c83495754..3c7b7c933d 100644
--- a/core/modules/views/tests/src/Functional/Plugin/PagerTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/PagerTest.php
@@ -66,26 +66,55 @@ public function testStorePagerSettings() {
];
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/pager', $edit, t('Apply'));
- $this->assertFieldByXPath('//input[@name="pager_options[items_per_page]" and @type="number" and @min="0"]', 10, '"Items per page" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
+ $items_per_page = $this->assertSession()->fieldExists("pager_options[items_per_page]");
+ $this->assertSession()->fieldValueEquals("pager_options[items_per_page]", 10);
+ $this->assertSame('number', $items_per_page->getAttribute('type'));
+ $this->assertEquals(0, $items_per_page->getAttribute('min'));
+
+ $offset = $this->assertSession()->fieldExists("pager_options[offset]");
+ $this->assertSession()->fieldValueEquals("pager_options[offset]", 0);
+ $this->assertSame('number', $offset->getAttribute('type'));
+ $this->assertEquals(0, $offset->getAttribute('min'));
$edit = [
'pager[type]' => 'none',
];
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/pager', $edit, t('Apply'));
- $this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
+ $offset = $this->assertSession()->fieldExists("pager_options[offset]");
+ $this->assertSession()->fieldValueEquals("pager_options[offset]", 0);
+ $this->assertSame('number', $offset->getAttribute('type'));
+ $this->assertEquals(0, $offset->getAttribute('min'));
$edit = [
'pager[type]' => 'full',
];
$this->drupalPostForm('admin/structure/views/nojs/display/test_view/default/pager', $edit, t('Apply'));
- $this->assertFieldByXPath('//input[@name="pager_options[items_per_page]" and @type="number" and @min="0"]', 10, '"Items to display" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[id]" and @type="number" and @min="0"]', 0, '"Pager ID" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[total_pages]" and @type="number" and @min="0"]', '', '"Number of pages" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[quantity]" and @type="number" and @min="0"]', 9, '"Number of pager links" field was found.');
+ $items_per_page = $this->assertSession()->fieldExists("pager_options[items_per_page]");
+ $this->assertSession()->fieldValueEquals("pager_options[items_per_page]", 10);
+ $this->assertSame('number', $items_per_page->getAttribute('type'));
+ $this->assertEquals(0, $items_per_page->getAttribute('min'));
+
+ $offset = $this->assertSession()->fieldExists("pager_options[offset]");
+ $this->assertSession()->fieldValueEquals("pager_options[offset]", 0);
+ $this->assertSame('number', $offset->getAttribute('type'));
+ $this->assertEquals(0, $offset->getAttribute('min'));
+
+ $id = $this->assertSession()->fieldExists("pager_options[id]");
+ $this->assertSession()->fieldValueEquals("pager_options[id]", 0);
+ $this->assertSame('number', $id->getAttribute('type'));
+ $this->assertEquals(0, $id->getAttribute('min'));
+
+ $total_pages = $this->assertSession()->fieldExists("pager_options[total_pages]");
+ $this->assertSession()->fieldValueEquals("pager_options[total_pages]", '');
+ $this->assertSame('number', $total_pages->getAttribute('type'));
+ $this->assertEquals(0, $total_pages->getAttribute('min'));
+
+ $quantity = $this->assertSession()->fieldExists("pager_options[quantity]");
+ $this->assertSession()->fieldValueEquals("pager_options[quantity]", 9);
+ $this->assertSame('number', $quantity->getAttribute('type'));
+ $this->assertEquals(0, $quantity->getAttribute('min'));
$edit = [
'pager_options[items_per_page]' => 20,
@@ -152,10 +181,25 @@ public function testStorePagerSettings() {
$this->drupalGet('admin/structure/views/nojs/display/test_store_pager_settings/page_1/pager_options');
$this->assertSession()->fieldNotExists('override[dropdown]');
- $this->assertFieldByXPath('//input[@name="pager_options[items_per_page]" and @type="number" and @min="0"]', 20, '"Items per page" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[offset]" and @type="number" and @min="0"]', 0, '"Offset" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[id]" and @type="number" and @min="0"]', 0, '"Pager ID" field was found.');
- $this->assertFieldByXPath('//input[@name="pager_options[total_pages]" and @type="number" and @min="0"]', '', '"Number of pages" field was found.');
+ $items_per_page = $this->assertSession()->fieldExists("pager_options[items_per_page]");
+ $this->assertSession()->fieldValueEquals("pager_options[items_per_page]", 20);
+ $this->assertSame('number', $items_per_page->getAttribute('type'));
+ $this->assertEquals(0, $items_per_page->getAttribute('min'));
+
+ $offset = $this->assertSession()->fieldExists("pager_options[offset]");
+ $this->assertSession()->fieldValueEquals("pager_options[offset]", 0);
+ $this->assertSame('number', $offset->getAttribute('type'));
+ $this->assertEquals(0, $offset->getAttribute('min'));
+
+ $id = $this->assertSession()->fieldExists("pager_options[id]");
+ $this->assertSession()->fieldValueEquals("pager_options[id]", 0);
+ $this->assertSame('number', $id->getAttribute('type'));
+ $this->assertEquals(0, $id->getAttribute('min'));
+
+ $total_pages = $this->assertSession()->fieldExists("pager_options[total_pages]");
+ $this->assertSession()->fieldValueEquals("pager_options[total_pages]", '');
+ $this->assertSame('number', $total_pages->getAttribute('type'));
+ $this->assertEquals(0, $total_pages->getAttribute('min'));
}
/**
diff --git a/core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php b/core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php
index 53c12604c9..bcf42f274b 100644
--- a/core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php
+++ b/core/modules/views/tests/src/Functional/Wizard/TaggedWithTest.php
@@ -193,15 +193,14 @@ public function testTaggedWithByNodeType() {
// by default (when the wizard is configured to display all content) and
// also when the node type that has the tagging field is selected, but not
// when the node type that doesn't have the tagging field is selected.
- $tags_xpath = '//input[@name="show[tagged_with]"]';
$this->drupalGet('admin/structure/views/add');
- $this->assertFieldByXpath($tags_xpath);
+ $this->assertSession()->fieldExists("show[tagged_with]");
$view['show[type]'] = $this->nodeTypeWithTags->id();
$this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
- $this->assertFieldByXpath($tags_xpath);
+ $this->assertSession()->fieldExists("show[tagged_with]");
$view['show[type]'] = $this->nodeTypeWithoutTags->id();
$this->drupalPostForm(NULL, $view, t('Update "of type" choice (2)'));
- $this->assertNoFieldByXpath($tags_xpath);
+ $this->assertSession()->fieldNotExists("show[tagged_with]");
// If we add an instance of the tagging field to the second node type, the
// "tagged with" form element should not appear for it too.
@@ -228,10 +227,10 @@ public function testTaggedWithByNodeType() {
$view['show[type]'] = $this->nodeTypeWithTags->id();
$this->drupalPostForm('admin/structure/views/add', $view, t('Update "of type" choice'));
- $this->assertFieldByXpath($tags_xpath);
+ $this->assertSession()->fieldExists("show[tagged_with]");
$view['show[type]'] = $this->nodeTypeWithoutTags->id();
$this->drupalPostForm(NULL, $view, t('Update "of type" choice (2)'));
- $this->assertFieldByXpath($tags_xpath);
+ $this->assertSession()->fieldExists("show[tagged_with]");
}
}
diff --git a/core/modules/views_ui/tests/src/Functional/DisplayFeedTest.php b/core/modules/views_ui/tests/src/Functional/DisplayFeedTest.php
index b796b7d587..f5de2f003b 100644
--- a/core/modules/views_ui/tests/src/Functional/DisplayFeedTest.php
+++ b/core/modules/views_ui/tests/src/Functional/DisplayFeedTest.php
@@ -77,12 +77,12 @@ protected function checkFeedViewUi($view_name) {
$this->assertNoRaw('Page');
$this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
- $this->assertFieldByXpath('//*[@id="views-feed-1-displays"]', 'Page');
+ $this->assertSession()->elementTextContains('xpath', '//*[@id="views-feed-1-displays"]', 'Page');
// Add the default display, so there should now be multiple displays.
$this->drupalPostForm('admin/structure/views/nojs/display/' . $view_name . '/feed_1/displays', ['displays[default]' => 'default'], t('Apply'));
$this->drupalGet('admin/structure/views/view/' . $view_name . '/edit/feed_1');
- $this->assertFieldByXpath('//*[@id="views-feed-1-displays"]', 'Multiple displays');
+ $this->assertSession()->elementTextContains('xpath', '//*[@id="views-feed-1-displays"]', 'Multiple displays');
}
}
diff --git a/core/modules/views_ui/tests/src/Functional/DisplayTest.php b/core/modules/views_ui/tests/src/Functional/DisplayTest.php
index 5233cc2194..acc2c37657 100644
--- a/core/modules/views_ui/tests/src/Functional/DisplayTest.php
+++ b/core/modules/views_ui/tests/src/Functional/DisplayTest.php
@@ -247,15 +247,15 @@ public function testActionLinks() {
$this->assertNoRaw($display_title);
// Ensure that the dropdown buttons are displayed correctly.
- $this->assertFieldByXpath('//input[@type="submit"]', 'Duplicate ' . $display_title);
- $this->assertFieldByXpath('//input[@type="submit"]', 'Delete ' . $display_title);
- $this->assertFieldByXpath('//input[@type="submit"]', 'Disable ' . $display_title);
- $this->assertNoFieldByXpath('//input[@type="submit"]', 'Enable ' . $display_title);
+ $this->assertSession()->buttonExists('Duplicate ' . $display_title);
+ $this->assertSession()->buttonExists('Delete ' . $display_title);
+ $this->assertSession()->buttonExists('Disable ' . $display_title);
+ $this->assertSession()->buttonNotExists('Enable ' . $display_title);
// Disable the display so we can test the rendering of the "Enable" button.
$this->drupalPostForm(NULL, NULL, 'Disable ' . $display_title);
- $this->assertFieldByXpath('//input[@type="submit"]', 'Enable ' . $display_title);
- $this->assertNoFieldByXpath('//input[@type="submit"]', 'Disable ' . $display_title);
+ $this->assertSession()->buttonExists('Enable ' . $display_title);
+ $this->assertSession()->buttonNotExists('Disable ' . $display_title);
// Ensure that the title is escaped as expected.
$this->assertSession()->assertEscaped($display_title);
diff --git a/core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php b/core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php
index beece8ce2b..4d955dad89 100644
--- a/core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php
+++ b/core/modules/views_ui/tests/src/Functional/ExposedFormUITest.php
@@ -126,11 +126,11 @@ public function testExposedAdminUi() {
$view_id = $this->randomView()['id'];
$this->drupalGet("admin/structure/views/nojs/add-handler/$view_id/default/sort");
$this->drupalPostForm(NULL, ['name[node_field_data.created]' => 1], t('Add and configure @handler', ['@handler' => t('sort criteria')]));
- $this->assertFieldByXPath('//input[@name="options[order]" and @checked="checked"]', 'ASC', 'The default order is set.');
+ $this->assertSession()->fieldValueEquals('options[order]', 'ASC');
// Change the order and expose the sort.
$this->drupalPostForm(NULL, ['options[order]' => 'DESC'], t('Apply'));
$this->drupalPostForm("admin/structure/views/nojs/handler/$view_id/default/sort/created", [], t('Expose sort'));
- $this->assertFieldByXPath('//input[@name="options[order]" and @checked="checked"]', 'DESC');
+ $this->assertSession()->fieldValueEquals('options[order]', 'DESC');
$this->assertSession()->fieldValueEquals('options[expose][label]', 'Authored on');
// Change the label and save the view.
$edit = ['options[expose][label]' => $this->randomString()];
diff --git a/core/modules/views_ui/tests/src/Functional/ViewEditTest.php b/core/modules/views_ui/tests/src/Functional/ViewEditTest.php
index e6c4440f17..a1aeca6b1a 100644
--- a/core/modules/views_ui/tests/src/Functional/ViewEditTest.php
+++ b/core/modules/views_ui/tests/src/Functional/ViewEditTest.php
@@ -115,7 +115,8 @@ public function testOtherOptions() {
$this->drupalPostForm('admin/structure/views/nojs/rearrange/test_view/default/field', $fields, t('Apply'));
$this->drupalPostForm(NULL, [], 'Save');
$this->drupalPostForm(NULL, [], t('Cancel'));
- $this->assertNoFieldByXpath('//div[contains(@class, "error")]', FALSE, 'No error message is displayed.');
+ // Verify that no error message is displayed.
+ $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "error")]');
// Verify page was redirected to the view listing.
$this->assertSession()->addressEquals('admin/structure/views');
}
diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
index ae701b4945..1defb72cdc 100644
--- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
+++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
@@ -335,27 +335,27 @@ public function testXpathAsserts() {
$this->drupalGet('test-field-xpath');
$this->assertFieldsByValue($this->xpath("//h1[@class = 'page-title']"), NULL);
$this->assertFieldsByValue($this->xpath('//table/tbody/tr[2]/td[1]'), 'one');
- $this->assertFieldByXPath('//table/tbody/tr[2]/td[1]', 'one');
+ $this->assertSession()->elementTextContains('xpath', '//table/tbody/tr[2]/td[1]', 'one');
$this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'Test name');
- $this->assertFieldByXPath("//input[@id = 'edit-name']", 'Test name');
+ $this->assertSession()->fieldValueEquals('edit-name', 'Test name');
$this->assertFieldsByValue($this->xpath("//select[@id = 'edit-options']"), '2');
- $this->assertFieldByXPath("//select[@id = 'edit-options']", '2');
+ $this->assertSession()->fieldValueEquals('edit-options', '2');
- $this->assertNoFieldByXPath('//notexisting');
- $this->assertNoFieldByXPath("//input[@id = 'edit-name']", 'wrong value');
+ $this->assertSession()->elementNotExists('xpath', '//notexisting');
+ $this->assertSession()->fieldValueNotEquals('edit-name', 'wrong value');
// Test that the assertion fails correctly.
try {
- $this->assertFieldByXPath("//input[@id = 'notexisting']");
+ $this->assertSession()->fieldExists('notexisting');
$this->fail('The "notexisting" field was found.');
}
- catch (ExpectationFailedException $e) {
+ catch (ExpectationException $e) {
// Expected exception; just continue testing.
}
try {
- $this->assertNoFieldByXPath("//input[@id = 'edit-name']");
+ $this->assertSession()->fieldNotExists('edit-name');
$this->fail('The "edit-name" field was not found.');
}
catch (ExpectationException $e) {
diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
index 250b184df6..828da13b06 100644
--- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -130,8 +130,6 @@ public static function getSkippedDeprecations() {
'AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertNoRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738',
- 'AssertLegacyTrait::assertFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and check the values directly in the test. See https://www.drupal.org/node/3129738',
- 'AssertLegacyTrait::assertNoFieldByXPath() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use $this->xpath() instead and assert that the result is empty. See https://www.drupal.org/node/3129738',
'AssertLegacyTrait::assertFieldsByValue() is deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use iteration over the fields yourself instead and directly check the values in the test. See https://www.drupal.org/node/3129738',
];
}