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() { ...@@ -45,7 +45,7 @@ public function testHtml() {
// Ensure that a block's ID is converted to an HTML valid ID, and that // 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. // 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. // 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']); $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() { ...@@ -224,7 +224,7 @@ public function testBlock() {
// Check for <div id="block-my-block-instance-name"> if the machine name // Check for <div id="block-my-block-instance-name"> if the machine name
// is my_block_instance_name. // is my_block_instance_name.
$xpath = $this->assertSession()->buildXPathQuery('//div[@id=:id]/*', [':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))]); $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. // Test deleting the block from the edit form.
$this->drupalGet('admin/structure/block/manage/' . $block['id']); $this->drupalGet('admin/structure/block/manage/' . $block['id']);
...@@ -352,7 +352,7 @@ public function moveBlockToRegion(array $block, $region) { ...@@ -352,7 +352,7 @@ public function moveBlockToRegion(array $block, $region) {
':region-class' => 'region region-' . Html::getClass($region), ':region-class' => 'region region-' . Html::getClass($region),
':block-id' => 'block-' . str_replace('_', '-', strtolower($block['id'])), ':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() { ...@@ -270,7 +270,7 @@ public function testContextAwareBlocks() {
// Tests that conditions with missing context are not displayed. // Tests that conditions with missing context are not displayed.
$this->drupalGet('admin/structure/block/manage/testcontextawareblock'); $this->drupalGet('admin/structure/block/manage/testcontextawareblock');
$this->assertNoRaw('No existing type'); $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() { ...@@ -65,7 +65,7 @@ public function testBlockContentCreation() {
])); ]));
// Check that the view mode setting is hidden because only one exists. // 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. // Check that the block exists in the database.
$blocks = \Drupal::entityTypeManager() $blocks = \Drupal::entityTypeManager()
...@@ -140,7 +140,7 @@ public function testBlockContentCreationMultipleViewModes() { ...@@ -140,7 +140,7 @@ public function testBlockContentCreationMultipleViewModes() {
// Check that the view mode setting is shown because more than one exists. // Check that the view mode setting is shown because more than one exists.
$this->drupalGet('admin/structure/block/manage/testblock'); $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. // Change the view mode.
$view_mode['region'] = 'content'; $view_mode['region'] = 'content';
...@@ -149,7 +149,7 @@ public function testBlockContentCreationMultipleViewModes() { ...@@ -149,7 +149,7 @@ public function testBlockContentCreationMultipleViewModes() {
// Go to the configure page and verify the view mode has changed. // Go to the configure page and verify the view mode has changed.
$this->drupalGet('admin/structure/block/manage/testblock'); $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. // Check that the block exists in the database.
$blocks = \Drupal::entityTypeManager() $blocks = \Drupal::entityTypeManager()
......
...@@ -68,7 +68,7 @@ public function testListing() { ...@@ -68,7 +68,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label // Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page). // (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. // Check the number of table row cells.
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td'); $elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td');
...@@ -98,7 +98,7 @@ public function testListing() { ...@@ -98,7 +98,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label // Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page). // (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. // Delete the added entity using the operations link.
$this->assertSession()->linkByHrefExists('block/' . $block->id() . '/delete'); $this->assertSession()->linkByHrefExists('block/' . $block->id() . '/delete');
...@@ -110,7 +110,7 @@ public function testListing() { ...@@ -110,7 +110,7 @@ public function testListing() {
// Verify that the text of the label and machine name does not appear in // Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page). // 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. // Confirm that the empty text is displayed.
$this->assertText(t('There are no custom blocks yet.')); $this->assertText(t('There are no custom blocks yet.'));
......
...@@ -80,7 +80,7 @@ public function testListing() { ...@@ -80,7 +80,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label // Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page). // (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. // Check the number of table row cells.
$elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td'); $elements = $this->xpath('//div[@class="layout-content"]//table/tbody/tr/td');
...@@ -110,7 +110,7 @@ public function testListing() { ...@@ -110,7 +110,7 @@ public function testListing() {
// Confirm that once the user returns to the listing, the text of the label // Confirm that once the user returns to the listing, the text of the label
// (versus elsewhere on the page). // (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. // Delete the added entity using the operations link.
$this->assertSession()->linkByHrefExists('block/' . $block->id() . '/delete'); $this->assertSession()->linkByHrefExists('block/' . $block->id() . '/delete');
...@@ -122,7 +122,7 @@ public function testListing() { ...@@ -122,7 +122,7 @@ public function testListing() {
// Verify that the text of the label and machine name does not appear in // Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page). // 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. // Confirm that the empty text is displayed.
$this->assertText('There are no custom blocks available.'); $this->assertText('There are no custom blocks available.');
......
...@@ -140,7 +140,7 @@ public function testExistingFormat() { ...@@ -140,7 +140,7 @@ public function testExistingFormat() {
// Ensure the styles textarea exists and is initialized empty. // Ensure the styles textarea exists and is initialized empty.
$styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]'); $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.'); $this->assertCount(1, $styles_textarea, 'The "styles" textarea exists.');
// Submit the form to save the selection of CKEditor as the chosen editor. // Submit the form to save the selection of CKEditor as the chosen editor.
...@@ -284,7 +284,7 @@ public function testNewFormat() { ...@@ -284,7 +284,7 @@ public function testNewFormat() {
// Ensure the styles textarea exists and is initialized empty. // Ensure the styles textarea exists and is initialized empty.
$styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]'); $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.'); $this->assertCount(1, $styles_textarea, 'The "styles" textarea exists.');
// Submit the form to create both a new text format and an associated text // Submit the form to create both a new text format and an associated text
......
...@@ -76,7 +76,7 @@ public function testCommentPreview() { ...@@ -76,7 +76,7 @@ public function testCommentPreview() {
$this->assertSession()->fieldValueEquals('comment_body[0][value]', $edit['comment_body[0][value]']); $this->assertSession()->fieldValueEquals('comment_body[0][value]', $edit['comment_body[0][value]']);
// Check that the user picture is displayed. // 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 @@ ...@@ -2,7 +2,6 @@
namespace Drupal\Tests\comment\Functional; namespace Drupal\Tests\comment\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\comment\CommentManagerInterface; use Drupal\comment\CommentManagerInterface;
/** /**
...@@ -143,13 +142,7 @@ protected function assertParentLink($cid, $pid) { ...@@ -143,13 +142,7 @@ protected function assertParentLink($cid, $pid) {
// </article> // </article>
$pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]//a[contains(@href, 'comment-$pid')]"; $pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]//a[contains(@href, 'comment-$pid')]";
$this->assertFieldByXpath($pattern, NULL, new FormattableMarkup( $this->assertSession()->elementExists('xpath', $pattern);
'Comment %cid has a link to parent %pid.',
[
'%cid' => $cid,
'%pid' => $pid,
]
));
} }
/** /**
...@@ -166,12 +159,7 @@ protected function assertNoParentLink($cid) { ...@@ -166,12 +159,7 @@ protected function assertNoParentLink($cid) {
// </article> // </article>
$pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]"; $pattern = "//article[@id='comment-$cid']//p[contains(@class, 'parent')]";
$this->assertNoFieldByXpath($pattern, NULL, new FormattableMarkup( $this->assertSession()->elementNotExists('xpath', $pattern);
'Comment %cid does not have a link to a parent.',
[
'%cid' => $cid,
]
));
} }
} }
...@@ -209,8 +209,8 @@ public function testListUI() { ...@@ -209,8 +209,8 @@ public function testListUI() {
// Confirm that the user is returned to the listing, and verify that the // 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 // text of the label and machine name appears in the list (versus elsewhere
// on the page). // on the page).
$this->assertFieldByXpath('//td', 'Antelope', "Label found for added 'Antelope' entity."); $this->assertSession()->elementExists('xpath', '//td[text() = "Antelope"]');
$this->assertFieldByXpath('//td', 'antelope', "Machine name found for added 'Antelope' entity."); $this->assertSession()->elementExists('xpath', '//td[text() = "antelope"]');
// Edit the entity using the operations link. // Edit the entity using the operations link.
$this->assertSession()->linkByHrefExists('admin/structure/config_test/manage/antelope'); $this->assertSession()->linkByHrefExists('admin/structure/config_test/manage/antelope');
...@@ -223,8 +223,8 @@ public function testListUI() { ...@@ -223,8 +223,8 @@ public function testListUI() {
// Confirm that the user is returned to the listing, and verify that the // 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 // text of the label and machine name appears in the list (versus elsewhere
// on the page). // on the page).
$this->assertFieldByXpath('//td', 'Albatross', "Label found for updated 'Albatross' entity."); $this->assertSession()->elementExists('xpath', '//td[text() = "Albatross"]');
$this->assertFieldByXpath('//td', 'albatross', "Machine name found for updated 'Albatross' entity."); $this->assertSession()->elementExists('xpath', '//td[text() = "albatross"]');
// Delete the added entity using the operations link. // Delete the added entity using the operations link.
$this->assertSession()->linkByHrefExists('admin/structure/config_test/manage/albatross/delete'); $this->assertSession()->linkByHrefExists('admin/structure/config_test/manage/albatross/delete');
...@@ -235,8 +235,8 @@ public function testListUI() { ...@@ -235,8 +235,8 @@ public function testListUI() {
// Verify that the text of the label and machine name does not appear in // Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page). // the list (though it may appear elsewhere on the page).
$this->assertNoFieldByXpath('//td', 'Albatross', "No label found for deleted 'Albatross' entity."); $this->assertSession()->elementNotExists('xpath', '//td[text() = "Albatross"]');
$this->assertNoFieldByXpath('//td', 'albatross', "No machine name found for deleted 'Albatross' entity."); $this->assertSession()->elementNotExists('xpath', '//td[text() = "albatross"]');
// Delete the original entity using the operations link. // Delete the original entity using the operations link.
$this->clickLink('Delete'); $this->clickLink('Delete');
...@@ -246,8 +246,8 @@ public function testListUI() { ...@@ -246,8 +246,8 @@ public function testListUI() {
// Verify that the text of the label and machine name does not appear in // Verify that the text of the label and machine name does not appear in
// the list (though it may appear elsewhere on the page). // the list (though it may appear elsewhere on the page).
$this->assertNoFieldByXpath('//td', 'Default', "No label found for deleted 'Default' entity."); $this->assertSession()->elementNotExists('xpath', '//td[text() = "Default"]');
$this->assertNoFieldByXpath('//td', 'dotted.default', "No machine name found for deleted 'Default' entity."); $this->assertSession()->elementNotExists('xpath', '//td[text() = "dotted.default"]');
// Confirm that the empty text is displayed. // Confirm that the empty text is displayed.
$this->assertText('There are no test configuration entities yet.'); $this->assertText('There are no test configuration entities yet.');
......
...@@ -243,8 +243,11 @@ public function testImportSimpleConfiguration() { ...@@ -243,8 +243,11 @@ public function testImportSimpleConfiguration() {
public function testExport() { public function testExport() {
$this->drupalLogin($this->drupalCreateUser(['export configuration'])); $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->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. // Spot check several known simple configuration files.
$element = $this->xpath('//select[@name="config_name"]')[0]; $element = $this->xpath('//select[@name="config_name"]')[0];
$options = $element->findAll('css', 'option'); $options = $element->findAll('css', 'option');
...@@ -257,12 +260,17 @@ public function testExport() { ...@@ -257,12 +260,17 @@ public function testExport() {
$this->drupalGet('admin/config/development/configuration/single/export/system.simple/system.image'); $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.'); $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->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->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'); $fallback_date = \Drupal::entityTypeManager()->getStorage('date_format')->load('fallback');
$yaml_text = $this->xpath('//textarea[@name="export"]')[0]->getValue(); $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.'); $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() { ...@@ -535,8 +535,7 @@ public function testAccountSettingsConfigurationTranslation() {
$this->drupalGet('admin/config/people/accounts/translate/fr/edit'); $this->drupalGet('admin/config/people/accounts/translate/fr/edit');
foreach ($edit as $key => $value) { foreach ($edit as $key => $value) {
// Check the translations appear in the right field type as well. // Check the translations appear in the right field type as well.
$xpath = '//' . (strpos($key, '[body]') ? 'textarea' : 'input') . '[@name="' . $key . '"]'; $this->assertSession()->fieldValueEquals($key, $value);
$this->assertFieldByXPath($xpath, $value);
} }
// Check that labels for email settings appear. // Check that labels for email settings appear.
$this->assertText(t('Account cancellation confirmation')); $this->assertText(t('Account cancellation confirmation'));
......
...@@ -284,7 +284,7 @@ public function testFieldTranslatableSettingsUI() { ...@@ -284,7 +284,7 @@ public function testFieldTranslatableSettingsUI() {
// translatable. // translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.field_article_text'; $path = 'admin/structure/types/manage/article/fields/node.article.field_article_text';
$this->drupalGet($path); $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.'); $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. // Tests that field has translatable setting if bundle is translatable.
...@@ -297,7 +297,8 @@ public function testFieldTranslatableSettingsUI() { ...@@ -297,7 +297,8 @@ public function testFieldTranslatableSettingsUI() {
]; ];
$this->assertSettings('node', 'article', TRUE, $edit); $this->assertSettings('node', 'article', TRUE, $edit);
$this->drupalGet($path); $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.'); $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() { ...@@ -58,18 +58,18 @@ public function testFieldTranslatableArticle() {
$this->drupalGet($path); $this->drupalGet($path);
// Check content block fields. // 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. // 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. // Check node fields.
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-comment' and @checked='checked']"); $this->assertSession()->checkboxChecked('edit-settings-node-article-fields-comment');
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-image' and @checked='checked']"); $this->assertSession()->checkboxChecked('edit-settings-node-article-fields-field-image');
$this->assertFieldByXPath("//input[@id='edit-settings-node-article-fields-field-tags' and @checked='checked']"); $this->assertSession()->checkboxChecked('edit-settings-node-article-fields-field-tags');
// Check user fields. // 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() { ...@@ -78,7 +78,7 @@ public function testFieldTranslatableArticle() {
public function testRevisionLogNotTranslatable() { public function testRevisionLogNotTranslatable() {
$path = 'admin/config/regional/content-language'; $path = 'admin/config/regional/content-language';
$this->drupalGet($path); $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() { ...@@ -157,7 +157,8 @@ protected function doTestBasicTranslation() {
} }
if ($this->testLanguageSelector) { 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]); $storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId); $entity = $storage->load($this->entityId);
...@@ -178,7 +179,7 @@ protected function doTestBasicTranslation() { ...@@ -178,7 +179,7 @@ protected function doTestBasicTranslation() {
// This does not save anything, it merely reloads the form and fills in the // This does not save anything, it merely reloads the form and fills in the
// fields with the values from the different source language. // fields with the values from the different source language.
$this->drupalPostForm($add_url, $edit, t('Change')); $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. // Add another translation and mark the other ones as outdated.
$values[$langcode] = $this->getNewEntityValues($langcode); $values[$langcode] = $this->getNewEntityValues($langcode);
...@@ -256,16 +257,19 @@ protected function doTestOutdatedStatus() { ...@@ -256,16 +257,19 @@ protected function doTestOutdatedStatus() {
$url = $entity->toUrl('edit-form', ['language' => ConfigurableLanguage::load($added_langcode)]); $url = $entity->toUrl('edit-form', ['language' => ConfigurableLanguage::load($added_langcode)]);
$this->drupalGet($url); $this->drupalGet($url);
if ($added_langcode == $langcode) { 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.'); $this->assertEmpty($this->xpath('//details[@id="edit-content-translation" and @open="open"]'), 'The translation tab should be collapsed by default.');
} }
else { 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.'); $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]; $edit = ['content_translation[outdated]' => FALSE];
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $added_langcode)); $this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $added_langcode));
$this->drupalGet($url); $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') $storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId); ->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]); $storage->resetCache([$this->entityId]);
...@@ -300,7 +304,8 @@ protected function doTestPublishedStatus() { ...@@ -300,7 +304,8 @@ protected function doTestPublishedStatus() {
// Check that the last published translation cannot be unpublished. // Check that the last published translation cannot be unpublished.
$this->drupalGet($entity->toUrl('edit-form')); $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) { ...@@ -416,7 +416,7 @@ protected function doTestWorkflows(UserInterface $user, $expected_status) {
*/ */
protected function assertNoSharedElements() { protected function assertNoSharedElements() {
$language_none = LanguageInterface::LANGCODE_NOT_SPECIFIED; $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]");
}