Commit 43fdb595 authored by catch's avatar catch
Browse files

Issue #3129002 by mondrake, longwave, sja112, martin107, jungle: Replace...

Issue #3129002 by mondrake, longwave, sja112, martin107, jungle: Replace usages of deprecated AssertLegacyTrait::assert()
parent e91ccdd5
......@@ -61,13 +61,10 @@ public function testBlockLinks() {
// Confirm items appear as links.
$items = $this->container->get('entity_type.manager')->getStorage('aggregator_item')->loadByFeed($feed->id(), 1);
$links = $this->xpath('//a[@href = :href]', [':href' => reset($items)->getLink()]);
$this->assert(isset($links[0]), 'Item link found.');
$this->assertSession()->linkByHrefExists(reset($items)->getLink());
// Find the expected read_more link.
$href = $feed->toUrl()->toString();
$links = $this->xpath('//a[@href = :href]', [':href' => $href]);
$this->assert(isset($links[0]), new FormattableMarkup('Link to href %href found.', ['%href' => $href]));
$this->assertSession()->linkByHrefExists($feed->toUrl()->toString());
$this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed->id());
// Visit that page.
......
......@@ -78,8 +78,7 @@ public function createFeed($feed_url = NULL, array $edit = []) {
$this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
// Verify that the creation message contains a link to a feed.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
$this->assert(isset($view_link), 'The message area contains a link to a feed');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
$fids = \Drupal::entityQuery('aggregator_feed')->condition('title', $edit['title[0][value]'])->condition('url', $edit['url[0][value]'])->execute();
$this->assertNotEmpty($fids, 'The feed found in database.');
......
......@@ -47,8 +47,7 @@ public function testUpdateFeedItem() {
$this->assertText(t('The feed @name has been added.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed @name has been added.', ['@name' => $edit['title[0][value]']]));
// Verify that the creation message contains a link to a feed.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
$this->assert(isset($view_link), 'The message area contains a link to a feed');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
$fids = \Drupal::entityQuery('aggregator_feed')->condition('url', $edit['url[0][value]'])->execute();
$feed = Feed::load(array_values($fids)[0]);
......
......@@ -35,8 +35,7 @@ public function testUpdateFeed() {
$this->assertText(t('The feed @name has been updated.', ['@name' => $edit['title[0][value]']]), new FormattableMarkup('The feed %name has been updated.', ['%name' => $edit['title[0][value]']]));
// Verify that the creation message contains a link to a feed.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'aggregator/sources/']);
$this->assert(isset($view_link), 'The message area contains a link to a feed');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "aggregator/sources/")]');
// Check feed data.
$this->assertUrl($feed->toUrl('canonical'));
......
......@@ -67,7 +67,7 @@ public function testExport() {
$file_path = $temp_directory . '/config.tar.gz';
$archiver = new Tar($file_path);
$archive_contents = $archiver->listContents();
$this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
$this->assertNotEmpty($archive_contents, 'Downloaded archive file is not empty.');
// Prepare the list of config files from active storage, see
// \Drupal\config\Controller\ConfigController::downloadExport().
......
......@@ -171,16 +171,14 @@ public function testSiteWideContact() {
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
// Verify that the creation message contains a link to a contact form.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'contact/']);
$this->assert(isset($view_link), 'The message area contains a link to a contact form.');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "contact/")]');
// Create first valid form.
$this->addContactForm($id = mb_strtolower($this->randomMachineName(16)), $label = $this->randomMachineName(16), implode(',', [$recipients[0]]), '', TRUE);
$this->assertText(t('Contact form @label has been added.', ['@label' => $label]));
// Verify that the creation message contains a link to a contact form.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'contact/']);
$this->assert(isset($view_link), 'The message area contains a link to a contact form.');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "contact/")]');
// Check that the form was created in site default language.
$langcode = $this->config('contact.form.' . $id)->get('langcode');
......
......@@ -694,7 +694,7 @@ protected function assertNoDependency($type, $key, EntityDisplayInterface $displ
* The entity display object to get dependencies from.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
* TRUE if the assertion succeeded.
*/
protected function assertDependencyHelper($assertion, $type, $key, EntityDisplayInterface $display) {
$all_dependencies = $display->getDependencies();
......@@ -703,7 +703,8 @@ protected function assertDependencyHelper($assertion, $type, $key, EntityDisplay
$value = $assertion ? in_array($key, $dependencies) : !in_array($key, $dependencies);
$args = ['@context' => $context, '@id' => $display->id(), '@type' => $type, '@key' => $key];
$message = $assertion ? new FormattableMarkup("@context display '@id' depends on @type '@key'.", $args) : new FormattableMarkup("@context display '@id' do not depend on @type '@key'.", $args);
return $this->assert($value, $message);
$this->assertTrue($value, $message);
return TRUE;
}
}
......@@ -449,8 +449,7 @@ public function createForum($type, $parent = 0) {
);
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "term/")]');
/** @var \Drupal\taxonomy\TermStorageInterface $taxonomy_term_storage */
$taxonomy_term_storage = $this->container->get('entity_type.manager')->getStorage('taxonomy_term');
......@@ -589,9 +588,8 @@ public function createForumTopic($forum, $container = FALSE) {
$this->assertText(t('@type @title has been created.', ['@type' => $type, '@title' => $title]), 'Forum topic was created');
$this->assertNoRaw(t('The item %title is a forum container, not a forum.', ['%title' => $forum['name']]), 'No error message was shown');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
// Verify that the creation message contains a link to a node.
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
}
// Retrieve node object, ensure that the topic was created and in the proper forum.
......
......@@ -140,8 +140,10 @@ public function testContentTypeLanguageConfiguration() {
$this->assertText(t('@title has been updated.', ['@title' => $node_title]));
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/' . $node->id()]);
$this->assert(isset($view_link), 'The message area contains the link to the edited node');
$xpath = $this->assertSession()->buildXPathQuery('//div[@data-drupal-messages]//a[contains(@href, :href)]', [
':href' => 'node/' . $node->id(),
]);
$this->assertSession()->elementExists('xpath', $xpath);
$this->drupalLogout();
}
......
......@@ -205,7 +205,7 @@ public function display($message, $type = 'status') {
$this->migrateMessages[$type][] = $message;
}
else {
$this->assert($type == 'status', $message, 'migrate');
$this->assertEquals('status', $type, $message);
}
}
......
......@@ -63,8 +63,7 @@ public function testNodeCreation() {
$this->assertText(t('@post @title has been created.', ['@post' => 'Basic page', '@title' => $edit['title[0][value]']]), 'Basic page created.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
$this->assert(isset($view_link), 'The message area contains a link to a node');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
// Check that the node exists in the database.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
......@@ -154,8 +153,7 @@ public function testUnpublishedNodeCreation() {
$this->assertText(t('@post @title has been created.', ['@post' => 'Basic page', '@title' => $edit['title[0][value]']]));
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
$this->assert(isset($view_link), 'The message area contains a link to a node');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
}
/**
......
......@@ -418,13 +418,19 @@ protected function doTestAlternateHreflangLinks(Node $node) {
$this->drupalGet($urls[$langcode]);
foreach ($urls as $alternate_langcode => $language_url) {
// Retrieve desired link elements from the HTML head.
$links = $this->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]',
[':href' => $language_url->toString(), ':hreflang' => $alternate_langcode]);
$xpath = $this->assertSession()->buildXPathQuery('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]', [
':href' => $language_url->toString(),
':hreflang' => $alternate_langcode,
]);
if ($translations[$alternate_langcode]->isPublished()) {
$this->assert(isset($links[0]), new FormattableMarkup('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', ['%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString()]));
// Verify that the node translation has the correct alternate
// hreflang link for the alternate langcode.
$this->assertSession()->elementExists('xpath', $xpath);
}
else {
$this->assertFalse(isset($links[0]), new FormattableMarkup('The %langcode node translation has an hreflang link for unpublished %alternate_langcode translation: %link.', ['%langcode' => $langcode, '%alternate_langcode' => $alternate_langcode, '%link' => $url->toString()]));
// Verify that the node translation does not have an alternate
// hreflang link for the alternate langcode.
$this->assertSession()->elementNotExists('xpath', $xpath);
}
}
}
......
......@@ -50,8 +50,7 @@ public function testNodeTypeInitialLanguageDefaults() {
// Tests if the language field cannot be rearranged on the manage fields tab.
$this->drupalGet('admin/structure/types/manage/article/fields');
$language_field = $this->xpath('//*[@id="field-overview"]/*[@id="language"]');
$this->assert(empty($language_field), 'Language field is not visible on manage fields tab.');
$this->assertSession()->elementNotExists('xpath', '//*[@id="field-overview"]/*[@id="language"]');
// Verify that language is not selectable on node add page by default.
$this->drupalGet('node/add/article');
......@@ -82,13 +81,12 @@ public function testNodeTypeInitialLanguageDefaults() {
// Tests if the language field can be rearranged on the manage form display
// tab.
$this->drupalGet('admin/structure/types/manage/article/form-display');
$language_field = $this->xpath('//*[@id="langcode"]');
$this->assert(!empty($language_field), 'Language field is visible on manage form display tab.');
$this->assertSession()->elementExists('xpath', '//*[@id="langcode"]');
// Tests if the language field can be rearranged on the manage display tab.
$this->drupalGet('admin/structure/types/manage/article/display');
$language_display = $this->xpath('//*[@id="langcode"]');
$this->assert(!empty($language_display), 'Language field is visible on manage display tab.');
$this->assertSession()->elementExists('xpath', '//*[@id="langcode"]');
// Tests if the language field is hidden by default.
$this->assertTrue($this->assertSession()->optionExists('edit-fields-langcode-region', 'hidden')->isSelected());
......
......@@ -465,12 +465,13 @@ public function testShortcutBlockAccess() {
* this default.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
* TRUE if the assertion succeeded.
*/
protected function assertShortcutQuickLink($label, $index = 0, $message = '', $group = 'Other') {
$links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]);
$message = ($message ? $message : new FormattableMarkup('Shortcut quick link with label %label found.', ['%label' => $label]));
return $this->assert(isset($links[$index]), $message, $group);
$this->assertArrayHasKey($index, $links, $message);
return TRUE;
}
}
......@@ -99,8 +99,7 @@ public function testEntityFormLanguage() {
$this->assertText(t('Basic page @title has been created.', ['@title' => $edit['title[0][value]']]), 'Basic page created.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
$this->assert(isset($view_link), 'The message area contains a link to a node');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
// Check to make sure the node was created.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
......
......@@ -277,8 +277,7 @@ public function testNodeTermCreationAndDeletion() {
$this->assertText(t('@type @title has been created.', ['@type' => t('Article'), '@title' => $edit['title[0][value]']]), 'The node was created successfully.');
// Verify that the creation message contains a link to a node.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'node/']);
$this->assert(isset($view_link), 'The message area contains a link to a node');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "node/")]');
foreach ($terms as $term) {
$this->assertText($term, 'The term was saved and appears on the node page.');
......
......@@ -246,8 +246,7 @@ public function testVocabularyPermissionsTaxonomyTerm() {
$this->assertText(t('Created new term @name.', ['@name' => $edit['name[0][value]']]), 'Term created successfully.');
// Verify that the creation message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "term/")]');
$terms = \Drupal::entityTypeManager()
->getStorage('taxonomy_term')
......@@ -321,8 +320,7 @@ public function testVocabularyPermissionsTaxonomyTerm() {
$this->assertText(t('Updated term @name.', ['@name' => $edit['name[0][value]']]), 'Term updated successfully.');
// Verify that the update message contains a link to a term.
$view_link = $this->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [':href' => 'term/']);
$this->assert(isset($view_link), 'The message area contains a link to a term');
$this->assertSession()->elementExists('xpath', '//div[@data-drupal-messages]//a[contains(@href, "term/")]');
// Ensure the term cannot be deleted.
$this->drupalGet('taxonomy/term/' . $term->id() . '/delete');
......
......@@ -150,7 +150,6 @@ public function testDefaultViews() {
$view->preExecute($this->viewArgMap[$name]);
}
$this->assert(TRUE, new FormattableMarkup('View @view will be executed.', ['@view' => $view->storage->id()]));
$view->execute();
$tokens = ['@name' => $name, '@display_id' => $display_id];
......
......@@ -234,14 +234,15 @@ public function testHandlerWeights() {
* The type of assertion - examples are "Browser", "PHP".
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
* TRUE if the assertion succeeded.
*/
protected function assertEqualValue($expected, $handler, $message = '', $group = 'Other') {
if (empty($message)) {
$message = t('Comparing @first and @second', ['@first' => implode(',', $expected), '@second' => implode(',', $handler->value)]);
}
return $this->assert($expected == $handler->value, $message, $group);
$this->assertEquals($expected, $handler->value, $message);
return TRUE;
}
/**
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\views\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\Traits\Core\CronRunTrait;
/**
......@@ -146,12 +145,14 @@ public function testSearchIntegration() {
* Link label to assert.
*
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
* TRUE if the assertion succeeded.
*/
protected function assertOneLink($label) {
$links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]);
$message = new FormattableMarkup('Link with label %label found once.', ['%label' => $label]);
return $this->assert(isset($links[0]) && !isset($links[1]), $message);
$xpath = $this->assertSession()->buildXPathQuery('//a[normalize-space(text())=:label]', [
':label' => $label,
]);
$this->assertSession()->elementsCount('xpath', $xpath, 1);
return TRUE;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment