Commit 652efc72 authored by catch's avatar catch

Issue #3139429 by mondrake, rahulrasgon, mohrerao, siddhant.bhosale, paulocs,...

Issue #3139429 by mondrake, rahulrasgon, mohrerao, siddhant.bhosale, paulocs, longwave, jungle, cburschka, munish.kumar: Replace usages of AssertLegacyTrait::assert(No)FieldByXPath, that is deprecated
parent 7dbdbcb1
......@@ -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']);
......
......@@ -224,7 +224,7 @@ public function testBlock() {
// Check for <div id="block-my-block-instance-name"> 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);
}
/**
......
......@@ -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]"]');
}
/**
......
......@@ -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()
......
......@@ -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.'));
......
......@@ -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.');
......
......@@ -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
......
......@@ -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");
}
/**
......
......@@ -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) {
// </article>
$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) {
// </article>
$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);
}
}
......@@ -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.');
......
......@@ -243,8 +243,11 @@ 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.');
$option_node = $this->assertSession()->optionExists("config_type", 'Simple configuration');
$this->assertTrue($option_node->isSelected());
// Spot check several known simple configuration files.
$element = $this->xpath('//select[@name="config_name"]')[0];
$options = $element->findAll('css', 'option');
......@@ -257,12 +260,17 @@ 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.');
$option_node = $this->assertSession()->optionExists("config_type", 'Date format');
$this->assertTrue($option_node->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.');
$option_node = $this->assertSession()->optionExists("config_name", 'Fallback date format (fallback)');
$this->assertTrue($option_node->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.');
......
......@@ -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'));
......
......@@ -284,7 +284,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.
......@@ -297,7 +297,8 @@ 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()->fieldEnabled('edit-translatable');
$this->assertSession()->checkboxChecked('edit-translatable');
$this->assertNoText('To enable translation of this field, enable language support for this type.', 'Translatable setting for field available.');
}
......
......@@ -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');
}
}
......@@ -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);
}
/**
......
......@@ -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]");
}
}
......@@ -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];
......
......@@ -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.');
......
......@@ -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,
......
......@@ -105,7 +105,8 @@ 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.');
$target = $this->assertSession()->fieldExists("edit-test-field-0-target-id");
$this->assertTrue($target->hasClass("form-autocomplete"));
$new_title = $this->randomMachineName();
......
......@@ -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]", '');
......
......@@ -252,7 +252,9 @@ public function testNumberIntegerField() {
$id = $match[1];