Commit 9c2bfa8d authored by catch's avatar catch
Browse files

Issue #3203476 by mondrake, longwave, alexpott: Convert assertions involving...

Issue #3203476 by mondrake, longwave, alexpott: Convert assertions involving use of xpath on divs to WebAssert
parent 20205709
...@@ -272,8 +272,8 @@ public function testBlockThemeSelector() { ...@@ -272,8 +272,8 @@ public function testBlockThemeSelector() {
// Set the default theme and ensure the block is placed. // Set the default theme and ensure the block is placed.
$theme_settings->set('default', $theme)->save(); $theme_settings->set('default', $theme)->save();
$this->drupalGet(''); $this->drupalGet('');
$elements = $this->xpath('//div[@id = :id]', [':id' => Html::getUniqueId('block-' . $block['id'])]); $block_id = Html::getUniqueId('block-' . $block['id']);
$this->assertTrue(!empty($elements), 'The block was found.'); $this->assertSession()->elementExists('xpath', "//div[@id = '$block_id']");
} }
} }
......
...@@ -93,8 +93,7 @@ public function testBlockDemoUiPage() { ...@@ -93,8 +93,7 @@ public function testBlockDemoUiPage() {
$this->drupalPlaceBlock('help_block', ['region' => 'help']); $this->drupalPlaceBlock('help_block', ['region' => 'help']);
$this->drupalGet('admin/structure/block'); $this->drupalGet('admin/structure/block');
$this->clickLink(t('Demonstrate block regions (@theme)', ['@theme' => 'Classy'])); $this->clickLink(t('Demonstrate block regions (@theme)', ['@theme' => 'Classy']));
$elements = $this->xpath('//div[contains(@class, "region-highlighted")]/div[contains(@class, "block-region") and contains(text(), :title)]', [':title' => 'Highlighted']); $this->assertSession()->elementExists('xpath', '//div[contains(@class, "region-highlighted")]/div[contains(@class, "block-region") and contains(text(), "Highlighted")]');
$this->assertTrue(!empty($elements), 'Block demo regions are shown.');
// Ensure that other themes can use the block demo page. // Ensure that other themes can use the block demo page.
\Drupal::service('theme_installer')->install(['test_theme']); \Drupal::service('theme_installer')->install(['test_theme']);
...@@ -201,16 +200,10 @@ public function testCandidateBlockList() { ...@@ -201,16 +200,10 @@ public function testCandidateBlockList() {
* Tests the behavior of unsatisfied context-aware blocks. * Tests the behavior of unsatisfied context-aware blocks.
*/ */
public function testContextAwareUnsatisfiedBlocks() { public function testContextAwareUnsatisfiedBlocks() {
$arguments = [
':category' => 'Block test',
':href' => 'admin/structure/block/add/test_context_aware_unsatisfied/classy',
':text' => 'Test context-aware unsatisfied block',
];
$this->drupalGet('admin/structure/block'); $this->drupalGet('admin/structure/block');
$this->clickLink('Place block'); $this->clickLink('Place block');
$elements = $this->xpath('//tr[.//td/div[text()=:text] and .//td[text()=:category] and .//td//a[contains(@href, :href)]]', $arguments); // Verify that the context-aware test block does not appear.
$this->assertTrue(empty($elements), 'The context-aware test block does not appear.'); $this->assertSession()->elementNotExists('xpath', '//tr[.//td/div[text()="Test context-aware unsatisfied block"] and .//td[text()="Block test"] and .//td//a[contains(@href, "admin/structure/block/add/test_context_aware_unsatisfied/classy")]]');
$definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware_unsatisfied'); $definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware_unsatisfied');
$this->assertTrue(!empty($definition), 'The context-aware test block does not exist.'); $this->assertTrue(!empty($definition), 'The context-aware test block does not exist.');
......
...@@ -262,8 +262,7 @@ public function testBlockRendering() { ...@@ -262,8 +262,7 @@ public function testBlockRendering() {
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']); $block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']);
$this->drupalGet(''); $this->drupalGet('');
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2'); $this->assertSession()->elementTextEquals('xpath', '//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2', 'Custom title');
$this->assertEqual('Custom title', $result[0]->getText());
// Don't override the title anymore. // Don't override the title anymore.
$plugin = $block->getPlugin(); $plugin = $block->getPlugin();
...@@ -271,16 +270,14 @@ public function testBlockRendering() { ...@@ -271,16 +270,14 @@ public function testBlockRendering() {
$block->save(); $block->save();
$this->drupalGet(''); $this->drupalGet('');
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2'); $this->assertSession()->elementTextEquals('xpath', '//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2', 'test_view_block');
$this->assertEqual('test_view_block', $result[0]->getText());
// Hide the title. // Hide the title.
$block->getPlugin()->setConfigurationValue('label_display', FALSE); $block->getPlugin()->setConfigurationValue('label_display', FALSE);
$block->save(); $block->save();
$this->drupalGet(''); $this->drupalGet('');
$result = $this->xpath('//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2'); $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "region-sidebar-first")]/div[contains(@class, "block-views")]/h2');
$this->assertTrue(empty($result), 'The title is not visible.');
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block', 'http_response', 'rendered'])); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:system.site', 'config:views.view.test_view_block', 'http_response', 'rendered']));
} }
...@@ -298,14 +295,14 @@ public function testBlockEmptyRendering() { ...@@ -298,14 +295,14 @@ public function testBlockEmptyRendering() {
$block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']); $block = $this->drupalPlaceBlock('views_block:test_view_block-block_1', ['label' => 'test_view_block-block_1:1', 'views_label' => 'Custom title']);
$this->drupalGet(''); $this->drupalGet('');
$this->assertCount(1, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')); $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "block-views-blocktest-view-block-block-1")]', 1);
$display = &$view->getDisplay('block_1'); $display = &$view->getDisplay('block_1');
$display['display_options']['block_hide_empty'] = TRUE; $display['display_options']['block_hide_empty'] = TRUE;
$view->save(); $view->save();
$this->drupalGet($url); $this->drupalGet($url);
$this->assertCount(0, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')); $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "block-views-blocktest-view-block-block-1")]');
// Ensure that the view cacheability metadata is propagated even, for an // Ensure that the view cacheability metadata is propagated even, for an
// empty block. // empty block.
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered'])); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
...@@ -325,7 +322,7 @@ public function testBlockEmptyRendering() { ...@@ -325,7 +322,7 @@ public function testBlockEmptyRendering() {
$view->save(); $view->save();
$this->drupalGet($url); $this->drupalGet($url);
$this->assertCount(1, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')); $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "block-views-blocktest-view-block-block-1")]', 1);
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered'])); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
$this->assertCacheContexts(['url.query_args:_wrapper_format']); $this->assertCacheContexts(['url.query_args:_wrapper_format']);
...@@ -343,7 +340,7 @@ public function testBlockEmptyRendering() { ...@@ -343,7 +340,7 @@ public function testBlockEmptyRendering() {
$view->save(); $view->save();
$this->drupalGet($url); $this->drupalGet($url);
$this->assertCount(0, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')); $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "block-views-blocktest-view-block-block-1")]');
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered'])); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
$this->assertCacheContexts(['url.query_args:_wrapper_format']); $this->assertCacheContexts(['url.query_args:_wrapper_format']);
...@@ -360,7 +357,7 @@ public function testBlockEmptyRendering() { ...@@ -360,7 +357,7 @@ public function testBlockEmptyRendering() {
$view->save(); $view->save();
$this->drupalGet($url); $this->drupalGet($url);
$this->assertCount(1, $this->xpath('//div[contains(@class, "block-views-blocktest-view-block-block-1")]')); $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "block-views-blocktest-view-block-block-1")]', 1);
$this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered'])); $this->assertCacheTags(array_merge($block->getCacheTags(), ['block_view', 'config:block_list', 'config:views.view.test_view_block', 'http_response', 'rendered']));
$this->assertCacheContexts(['url.query_args:_wrapper_format']); $this->assertCacheContexts(['url.query_args:_wrapper_format']);
} }
......
...@@ -41,18 +41,14 @@ public function testListing() { ...@@ -41,18 +41,14 @@ public function testListing() {
$this->assertSession()->titleEquals('Custom block library | Drupal'); $this->assertSession()->titleEquals('Custom block library | Drupal');
// Test for the table. // Test for the table.
$element = $this->xpath('//div[@class="layout-content"]//table'); $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//table');
$this->assertNotEmpty($element, 'Configuration entity list table found.');
// Test the table header. // Test the table header, two cells should be present.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 2);
$this->assertCount(2, $elements, 'Correct number of table header cells found.');
// Test the contents of each th cell. // Test the contents of each th cell.
$expected_items = [t('Block description'), t('Operations')]; $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Block description');
foreach ($elements as $key => $element) { $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Operations');
$this->assertEqual($expected_items[$key], $element->getText());
}
$label = 'Antelope'; $label = 'Antelope';
$new_label = 'Albatross'; $new_label = 'Albatross';
...@@ -71,12 +67,11 @@ public function testListing() { ...@@ -71,12 +67,11 @@ public function testListing() {
$this->assertSession()->elementTextContains('xpath', '//td', $label); $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'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td', 2);
$this->assertCount(2, $elements, 'Correct number of table row cells found.');
// Check the contents of each row cell. The first cell contains the label, // Check the contents of each row cell. The first cell contains the label,
// the second contains the machine name, and the third contains the // the second contains the machine name, and the third contains the
// operations list. // operations list.
$this->assertSame($label, $elements[0]->getText()); $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td[1]', $label);
// Edit the entity using the operations link. // Edit the entity using the operations link.
$blocks = $this->container $blocks = $this->container
......
...@@ -48,23 +48,16 @@ public function testListing() { ...@@ -48,23 +48,16 @@ public function testListing() {
$this->assertSession()->fieldExists('type'); $this->assertSession()->fieldExists('type');
// Test for the table. // Test for the table.
$element = $this->xpath('//div[@class="layout-content"]//table'); $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//table');
$this->assertNotEmpty($element, 'Views table found.');
// Test the table header. // Test the table header, four cells should be present.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 4);
$this->assertCount(4, $elements, 'Correct number of table header cells found.');
// Test the contents of each th cell. // Test the contents of each th cell.
$expected_items = ['Block description', 'Block type', 'Updated Sort ascending', 'Operations']; $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Block description');
foreach ($elements as $key => $element) { $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Block type');
if ($element->find('xpath', 'a')) { $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[3]', 'Updated Sort ascending');
$this->assertSame($expected_items[$key], trim($element->find('xpath', 'a')->getText())); $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[4]', 'Operations');
}
else {
$this->assertSame($expected_items[$key], trim($element->getText()));
}
}
$label = 'Antelope'; $label = 'Antelope';
$new_label = 'Albatross'; $new_label = 'Albatross';
...@@ -83,12 +76,11 @@ public function testListing() { ...@@ -83,12 +76,11 @@ public function testListing() {
$this->assertSession()->elementTextContains('xpath', '//td/a', $label); $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'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/tbody/tr/td', 4);
$this->assertCount(4, $elements, 'Correct number of table row cells found.');
// Check the contents of each row cell. The first cell contains the label, // Check the contents of each row cell. The first cell contains the label,
// the second contains the machine name, and the third contains the // the second contains the machine name, and the third contains the
// operations list. // operations list.
$this->assertSame($label, $elements[0]->find('xpath', 'a')->getText()); $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/tbody/tr/td/a', $label);
// Edit the entity using the operations link. // Edit the entity using the operations link.
$blocks = $this->container $blocks = $this->container
......
...@@ -168,29 +168,25 @@ public function testListUI() { ...@@ -168,29 +168,25 @@ public function testListUI() {
$this->assertSession()->titleEquals('Test configuration | Drupal'); $this->assertSession()->titleEquals('Test configuration | Drupal');
// Test for the table. // Test for the table.
$element = $this->xpath('//div[@class="layout-content"]//table'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table', 1);
$this->assertCount(1, $element, 'Configuration entity list table found.');
// Test the table header. // Test the table header.
$elements = $this->xpath('//div[@class="layout-content"]//table/thead/tr/th'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 3);
$this->assertCount(3, $elements, 'Correct number of table header cells found.');
// Test the contents of each th cell. // Test the contents of each th cell.
$expected_items = ['Label', 'Machine name', 'Operations']; $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Label');
foreach ($elements as $key => $element) { $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Machine name');
$this->assertSame($expected_items[$key], $element->getText()); $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[3]', 'Operations');
}
// 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'); $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td', 3);
$this->assertCount(3, $elements, 'Correct number of table row cells found.');
// Check the contents of each row cell. The first cell contains the label, // Check the contents of each row cell. The first cell contains the label,
// the second contains the machine name, and the third contains the // the second contains the machine name, and the third contains the
// operations list. // operations list.
$this->assertSame('Default', $elements[0]->getText()); $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td[1]', 'Default');
$this->assertSame('dotted.default', $elements[1]->getText()); $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td[2]', 'dotted.default');
$this->assertNotEmpty($elements[2]->find('xpath', '//ul'), 'Operations list found.'); $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//table/tbody/tr[@class="odd"]/td[3]//ul');
// Add a new entity using the operations link. // Add a new entity using the operations link.
$this->assertSession()->linkExists('Add test configuration'); $this->assertSession()->linkExists('Add test configuration');
......
...@@ -380,8 +380,8 @@ public function testSiteWideContact() { ...@@ -380,8 +380,8 @@ public function testSiteWideContact() {
$field_name . '[0][value]' => $this->randomMachineName(), $field_name . '[0][value]' => $this->randomMachineName(),
]; ];
$this->submitForm($edit, 'Send message'); $this->submitForm($edit, 'Send message');
$result = $this->xpath('//div[@role=:role]', [':role' => 'contentinfo']); // Verify that messages are not found.
$this->assertCount(0, $result, 'Messages not found.'); $this->assertSession()->elementNotExists('xpath', '//div[@role="contentinfo"]');
$this->assertSession()->addressEquals('user/' . $admin_user->id()); $this->assertSession()->addressEquals('user/' . $admin_user->id());
// Test preview and visibility of the message field and label. Submit the // Test preview and visibility of the message field and label. Submit the
......
...@@ -100,13 +100,10 @@ public function testContactLink() { ...@@ -100,13 +100,10 @@ public function testContactLink() {
* Users which should have contact links. * Users which should have contact links.
*/ */
public function assertContactLinks(array $accounts, array $names) { public function assertContactLinks(array $accounts, array $names) {
$result = $this->xpath('//div[contains(@class, "views-field-contact")]//a'); $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "views-field-contact")]//a', count($names));
$this->assertSame(count($names), count($result));
foreach ($names as $name) { foreach ($names as $name) {
$account = $accounts[$name]; $account_url = $accounts[$name]->toUrl('contact-form')->toString();
$this->assertSession()->elementExists('xpath', "//div[contains(@class, 'views-field-contact')]//a[contains(@href, '$account_url')]");
$result = $this->xpath('//div[contains(@class, "views-field-contact")]//a[contains(@href, :url)]', [':url' => $account->toUrl('contact-form')->toString()]);
$this->assertGreaterThan(0, count($result));
} }
} }
......
...@@ -122,8 +122,7 @@ public function testImageFieldSync() { ...@@ -122,8 +122,7 @@ public function testImageFieldSync() {
'settings[entity_test_mul][entity_test_mul][columns][field_test_et_ui_image][title]' => TRUE, 'settings[entity_test_mul][entity_test_mul][columns][field_test_et_ui_image][title]' => TRUE,
]; ];
$this->drupalPostForm('admin/config/regional/content-language', $edit, 'Save configuration'); $this->drupalPostForm('admin/config/regional/content-language', $edit, 'Save configuration');
$errors = $this->xpath('//div[contains(@class, "messages--error")]'); $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "messages--error")]');
$this->assertEmpty($errors, 'Settings correctly stored.');
$this->assertSession()->checkboxChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-alt'); $this->assertSession()->checkboxChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-alt');
$this->assertSession()->checkboxChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-title'); $this->assertSession()->checkboxChecked('edit-settings-entity-test-mul-entity-test-mul-columns-field-test-et-ui-image-title');
$this->drupalLogin($this->translator); $this->drupalLogin($this->translator);
......
...@@ -351,7 +351,7 @@ protected function doTestAuthoringInfo() { ...@@ -351,7 +351,7 @@ protected function doTestAuthoringInfo() {
'content_translation[created]' => '19/11/1978', 'content_translation[created]' => '19/11/1978',
]; ];
$this->drupalPostForm($entity->toUrl('edit-form'), $edit, $this->getFormSubmitAction($entity, $langcode)); $this->drupalPostForm($entity->toUrl('edit-form'), $edit, $this->getFormSubmitAction($entity, $langcode));
$this->assertNotEmpty($this->xpath('//div[contains(@class, "error")]//ul'), 'Invalid values generate a list of form errors.'); $this->assertSession()->elementExists('xpath', '//div[contains(@class, "error")]//ul');
$metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode)); $metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
$this->assertEqual($values[$langcode]['uid'], $metadata->getAuthor()->id(), 'Translation author correctly kept.'); $this->assertEqual($values[$langcode]['uid'], $metadata->getAuthor()->id(), 'Translation author correctly kept.');
$this->assertEqual($values[$langcode]['created'], $metadata->getCreatedTime(), 'Translation date correctly kept.'); $this->assertEqual($values[$langcode]['created'], $metadata->getCreatedTime(), 'Translation date correctly kept.');
......
...@@ -130,11 +130,8 @@ public function testBooleanFormatterSettings() { ...@@ -130,11 +130,8 @@ public function testBooleanFormatterSettings() {
// Test that the settings summary are present in the correct format. // Test that the settings summary are present in the correct format.
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display'); $this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/display');
$result = $this->xpath('//div[contains(@class, :class) and contains(text(), :text)]', [ $this->assertSession()->elementExists('xpath', "//div[contains(@class, 'field-plugin-summary')]");
':class' => 'field-plugin-summary', $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'field-plugin-summary')]", "Display: {$values[0]} / {$values[1]}");
':text' => (string) t('Display: @true_label / @false_label', ['@true_label' => $values[0], '@false_label' => $values[1]]),
]);
$this->assertCount(1, $result, "Boolean formatter settings summary exist.");
} }
} }
......
...@@ -305,8 +305,7 @@ public function testFilterAdmin() { ...@@ -305,8 +305,7 @@ public function testFilterAdmin() {
$this->assertText('Basic page ' . $edit['title[0][value]'] . ' has been created.'); $this->assertText('Basic page ' . $edit['title[0][value]'] . ' has been created.');
// Verify that the creation message contains a link to a node. // Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[contains(@class, "messages")]//a[contains(@href, :href)]', [':href' => 'node/']); $this->assertSession()->elementExists('xpath', '//div[contains(@class, "messages")]//a[contains(@href, "node/")]');
$this->assertNotEmpty($view_link, 'The message area contains a link to a node');
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']); $node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertNotEmpty($node, 'Node found in database.'); $this->assertNotEmpty($node, 'Node found in database.');
......
...@@ -31,7 +31,8 @@ public function testWidgetElement() { ...@@ -31,7 +31,8 @@ public function testWidgetElement() {
]; ];
$this->createImageField($field_name, 'article', [], $field_settings, [], [], 'Image test on [site:name]'); $this->createImageField($field_name, 'article', [], $field_settings, [], [], 'Image test on [site:name]');
$this->drupalGet('node/add/article'); $this->drupalGet('node/add/article');
$this->assertNotCount(0, $this->xpath('//div[contains(@class, "field--widget-image-image")]'), 'Image field widget found on add/node page', NULL); // Verify that the image field widget is found on add/node page.
$this->assertSession()->elementExists('xpath', '//div[contains(@class, "field--widget-image-image")]');
// Verify that the image field widget limits accepted files. // Verify that the image field widget limits accepted files.
$this->assertSession()->elementExists('xpath', '//input[contains(@accept, "image/*")]'); $this->assertSession()->elementExists('xpath', '//input[contains(@accept, "image/*")]');
$this->assertNoText('Image test on [site:name]'); $this->assertNoText('Image test on [site:name]');
......
...@@ -33,10 +33,8 @@ public function testAJAXValidationMessage() { ...@@ -33,10 +33,8 @@ public function testAJAXValidationMessage() {
$field->attachFile($this->container->get('file_system')->realpath($text_file->uri)); $field->attachFile($this->container->get('file_system')->realpath($text_file->uri));
$this->assertSession()->waitForElement('css', '.messages--error'); $this->assertSession()->waitForElement('css', '.messages--error');
$elements = $this->xpath('//div[contains(@class, :class)]', [ // Verify that Ajax validation messages are displayed only once.
':class' => 'messages--error', $this->assertSession()->elementsCount('xpath', '//div[contains(@class, "messages--error")]', 1);
]);
$this->assertCount(1, $elements, 'Ajax validation messages are displayed once.');
} }
/** /**
......
...@@ -223,20 +223,12 @@ public function testLanguageBlockWithDomain() { ...@@ -223,20 +223,12 @@ public function testLanguageBlockWithDomain() {
$generator = $this->container->get('url_generator'); $generator = $this->container->get('url_generator');
// Verify the English URL is correct // Verify the English URL is correct
list($english_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', [
':id' => 'block-test-language-block',
':hreflang' => 'en',
]);
$english_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['en']]); $english_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['en']]);
$this->assertEqual($english_link->getAttribute('href'), $english_url); $this->assertSession()->elementAttributeContains('xpath', '//div[@id="block-test-language-block"]/ul/li/a[@hreflang="en"]', 'href', $english_url);
// Verify the Italian URL is correct // Verify the Italian URL is correct
list($italian_link) = $this->xpath('//div[@id=:id]/ul/li/a[@hreflang=:hreflang]', [
':id' => 'block-test-language-block',
':hreflang' => 'it',
]);
$italian_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['it']]); $italian_url = $generator->generateFromRoute('entity.user.canonical', ['user' => 2], ['language' => $languages['it']]);
$this->assertEqual($italian_link->getAttribute('href'), $italian_url); $this->assertSession()->elementAttributeContains('xpath', '//div[@id="block-test-language-block"]/ul/li/a[@hreflang="it"]', 'href', $italian_url);
} }
/** /**
......
...@@ -463,13 +463,11 @@ public function testUrlLanguageFallback() { ...@@ -463,13 +463,11 @@ public function testUrlLanguageFallback() {
// Check that the language switcher active link matches the given browser // Check that the language switcher active link matches the given browser
// language. // language.
$args = [':id' => 'block-test-language-block', ':url' => Url::fromRoute('<front>')->toString() . $langcode_browser_fallback]; $href = Url::fromRoute('<front>')->toString() . $langcode_browser_fallback;
$fields = $this->xpath('//div[@id=:id]//a[@class="language-link is-active" and starts-with(@href, :url)]', $args); $this->assertSession()->elementTextEquals('xpath', "//div[@id='block-test-language-block']//a[@class='language-link is-active' and starts-with(@href, '$href')]", $languages[$langcode_browser_fallback]->getName());
$this->assertSame($fields[0]->getText(), $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
// Check that URLs are rewritten using the given browser language. // Check that URLs are rewritten using the given browser language.
$fields = $this->xpath('//div[@class="site-name"]/a[@rel="home" and @href=:url]', $args); $this->assertSession()->elementTextEquals('xpath', "//div[@class='site-name']/a[@rel='home' and @href='$href']", 'Drupal');
$this->assertSame($fields[0]->getText(), 'Drupal', 'URLs are rewritten using the browser language.');
} }
/** /**
......
...@@ -19,20 +19,15 @@ public function assertButtons(array $buttons, $dropbutton = TRUE) { ...@@ -19,20 +19,15 @@ public function assertButtons(array $buttons, $dropbutton = TRUE) {
// Verify that the number of buttons passed as parameters is // Verify that the number of buttons passed as parameters is
// available in the dropbutton widget. // available in the dropbutton widget.
if ($dropbutton) { if ($dropbutton) {
$i = 0;
$count = count($buttons); $count = count($buttons);
// Assert there is no save button. // Assert there is no save button.
$this->assertSession()->buttonNotExists('Save'); $this->assertSession()->buttonNotExists('Save');
// Dropbutton elements. // Dropbutton elements.
/** @var \Behat\Mink\Element\NodeElement[] $elements */ $this->assertSession()->elementsCount('xpath', '//div[@class="dropbutton-wrapper"]//input[@type="submit"]', $count);
$elements = $this->xpath(