From 43fdb595f9032d63e2f34f1573ff13b5fc0b5e61 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 1 Sep 2020 17:33:58 +0100
Subject: [PATCH] Issue #3129002 by mondrake, longwave, sja112, martin107,
 jungle: Replace usages of deprecated AssertLegacyTrait::assert()

---
 .../Functional/AggregatorRenderingTest.php    |  7 +--
 .../src/Functional/AggregatorTestBase.php     |  3 +-
 .../src/Functional/UpdateFeedItemTest.php     |  3 +-
 .../tests/src/Functional/UpdateFeedTest.php   |  3 +-
 .../src/Functional/ConfigExportUITest.php     |  2 +-
 .../src/Functional/ContactSitewideTest.php    |  6 +--
 .../tests/src/Kernel/EntityDisplayTest.php    |  5 +-
 .../forum/tests/src/Functional/ForumTest.php  |  8 ++-
 .../src/Functional/LocaleContentTest.php      |  6 ++-
 .../tests/src/Kernel/MigrateTestBase.php      |  2 +-
 .../tests/src/Functional/NodeCreationTest.php |  6 +--
 .../src/Functional/NodeTranslationUITest.php  | 14 +++--
 .../NodeTypeInitialLanguageTest.php           | 10 ++--
 .../src/Functional/ShortcutLinksTest.php      |  5 +-
 .../Entity/EntityTranslationFormTest.php      |  3 +-
 .../tests/src/Functional/TermTest.php         |  3 +-
 .../Functional/VocabularyPermissionsTest.php  |  6 +--
 .../tests/src/Functional/DefaultViewsTest.php |  1 -
 .../src/Functional/Handler/HandlerTest.php    |  5 +-
 .../src/Functional/SearchIntegrationTest.php  | 11 ++--
 .../Drupal/KernelTests/AssertContentTrait.php | 52 +++++++++++--------
 .../Cache/GenericCacheBackendUnitTestBase.php | 14 ++---
 .../Entity/EntityDefinitionUpdateTest.php     |  4 +-
 .../Drupal/KernelTests/KernelTestBaseTest.php | 10 ++++
 .../Listeners/DeprecationListenerTrait.php    |  1 -
 25 files changed, 101 insertions(+), 89 deletions(-)

diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php b/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php
index 5ffce1f062a5..5d2fc211ad5b 100644
--- a/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php
+++ b/core/modules/aggregator/tests/src/Functional/AggregatorRenderingTest.php
@@ -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.
diff --git a/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php b/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php
index 5d36dd270fee..505ed0093e3c 100644
--- a/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php
+++ b/core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php
@@ -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.');
diff --git a/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php b/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php
index 4c5a3d3ab3cb..6181d8d41473 100644
--- a/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php
+++ b/core/modules/aggregator/tests/src/Functional/UpdateFeedItemTest.php
@@ -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]);
diff --git a/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php b/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php
index 86f4bf2750de..0e633009f9e5 100644
--- a/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php
+++ b/core/modules/aggregator/tests/src/Functional/UpdateFeedTest.php
@@ -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'));
diff --git a/core/modules/config/tests/src/Functional/ConfigExportUITest.php b/core/modules/config/tests/src/Functional/ConfigExportUITest.php
index 9bb771eb6b76..e822e378cb92 100644
--- a/core/modules/config/tests/src/Functional/ConfigExportUITest.php
+++ b/core/modules/config/tests/src/Functional/ConfigExportUITest.php
@@ -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().
diff --git a/core/modules/contact/tests/src/Functional/ContactSitewideTest.php b/core/modules/contact/tests/src/Functional/ContactSitewideTest.php
index aa52887e57b3..f40f3332ccfe 100644
--- a/core/modules/contact/tests/src/Functional/ContactSitewideTest.php
+++ b/core/modules/contact/tests/src/Functional/ContactSitewideTest.php
@@ -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');
diff --git a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
index 2bc6f1f37b96..d92d5d6ecd5b 100644
--- a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
+++ b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
@@ -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;
   }
 
 }
diff --git a/core/modules/forum/tests/src/Functional/ForumTest.php b/core/modules/forum/tests/src/Functional/ForumTest.php
index eb718db663a3..28ceb971809b 100644
--- a/core/modules/forum/tests/src/Functional/ForumTest.php
+++ b/core/modules/forum/tests/src/Functional/ForumTest.php
@@ -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.
diff --git a/core/modules/locale/tests/src/Functional/LocaleContentTest.php b/core/modules/locale/tests/src/Functional/LocaleContentTest.php
index a97834491fbe..9f93136c0dc7 100644
--- a/core/modules/locale/tests/src/Functional/LocaleContentTest.php
+++ b/core/modules/locale/tests/src/Functional/LocaleContentTest.php
@@ -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();
   }
diff --git a/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php b/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php
index 8fcef4a60ed1..38e290819cd9 100644
--- a/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php
+++ b/core/modules/migrate/tests/src/Kernel/MigrateTestBase.php
@@ -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);
     }
   }
 
diff --git a/core/modules/node/tests/src/Functional/NodeCreationTest.php b/core/modules/node/tests/src/Functional/NodeCreationTest.php
index ba9b49274020..9c7ba2702ddc 100644
--- a/core/modules/node/tests/src/Functional/NodeCreationTest.php
+++ b/core/modules/node/tests/src/Functional/NodeCreationTest.php
@@ -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/")]');
   }
 
   /**
diff --git a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php
index fd4203b91548..9c64abe555db 100644
--- a/core/modules/node/tests/src/Functional/NodeTranslationUITest.php
+++ b/core/modules/node/tests/src/Functional/NodeTranslationUITest.php
@@ -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);
           }
         }
       }
diff --git a/core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php b/core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php
index 2056f7da0914..79d50cf36fa5 100644
--- a/core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php
+++ b/core/modules/node/tests/src/Functional/NodeTypeInitialLanguageTest.php
@@ -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());
 
diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
index 1b1f52a41b2a..8525b7c0aec6 100644
--- a/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
+++ b/core/modules/shortcut/tests/src/Functional/ShortcutLinksTest.php
@@ -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;
   }
 
 }
diff --git a/core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php b/core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php
index 6975d1dd1216..4d2372daa1eb 100644
--- a/core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php
+++ b/core/modules/system/tests/src/Functional/Entity/EntityTranslationFormTest.php
@@ -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]']);
diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php
index 27c0fcf647b4..ced3e92ff73b 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php
@@ -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.');
diff --git a/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php b/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
index 3482a0b95078..b7c32e3ab223 100644
--- a/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/VocabularyPermissionsTest.php
@@ -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');
diff --git a/core/modules/views/tests/src/Functional/DefaultViewsTest.php b/core/modules/views/tests/src/Functional/DefaultViewsTest.php
index b202e10d2b66..906a36f7b9ce 100644
--- a/core/modules/views/tests/src/Functional/DefaultViewsTest.php
+++ b/core/modules/views/tests/src/Functional/DefaultViewsTest.php
@@ -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];
diff --git a/core/modules/views/tests/src/Functional/Handler/HandlerTest.php b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
index 5911b1548eb7..79b6ed8c1585 100644
--- a/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
+++ b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
@@ -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;
   }
 
   /**
diff --git a/core/modules/views/tests/src/Functional/SearchIntegrationTest.php b/core/modules/views/tests/src/Functional/SearchIntegrationTest.php
index a2a95d9fb46e..f348e5ac18e6 100644
--- a/core/modules/views/tests/src/Functional/SearchIntegrationTest.php
+++ b/core/modules/views/tests/src/Functional/SearchIntegrationTest.php
@@ -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;
   }
 
 }
diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php
index e1fd22e2659f..f45977984880 100644
--- a/core/tests/Drupal/KernelTests/AssertContentTrait.php
+++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php
@@ -291,14 +291,15 @@ protected function getAllOptions(\SimpleXMLElement $element) {
    *   this default.
    *
    * @return bool
-   *   TRUE if the assertion succeeded, FALSE otherwise.
+   *   TRUE if the assertion succeeded.
    */
   protected function assertLink($label, $index = 0, $message = '', $group = 'Other') {
     // Cast MarkupInterface objects to string.
     $label = (string) $label;
     $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]);
     $message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label]));
-    return $this->assert(isset($links[$index]), $message, $group);
+    $this->assertArrayHasKey($index, $links, $message);
+    return TRUE;
   }
 
   /**
@@ -318,14 +319,15 @@ protected function assertLink($label, $index = 0, $message = '', $group = 'Other
    *   this default.
    *
    * @return bool
-   *   TRUE if the assertion succeeded, FALSE otherwise.
+   *   TRUE if the assertion succeeded.
    */
   protected function assertNoLink($label, $message = '', $group = 'Other') {
     // Cast MarkupInterface objects to string.
     $label = (string) $label;
     $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]);
     $message = ($message ? $message : new FormattableMarkup('Link with label %label not found.', ['%label' => $label]));
-    return $this->assert(empty($links), $message, $group);
+    $this->assertEmpty($links, $message);
+    return TRUE;
   }
 
   /**
@@ -347,12 +349,13 @@ protected function assertNoLink($label, $message = '', $group = 'Other') {
    *   this default.
    *
    * @return bool
-   *   TRUE if the assertion succeeded, FALSE otherwise.
+   *   TRUE if the assertion succeeded.
    */
   protected function assertLinkByHref($href, $index = 0, $message = '', $group = 'Other') {
     $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $href]);
     $message = ($message ? $message : new FormattableMarkup('Link containing href %href found.', ['%href' => $href]));
-    return $this->assert(isset($links[$index]), $message, $group);
+    $this->assertArrayHasKey($index, $links, $message);
+    return TRUE;
   }
 
   /**
@@ -372,12 +375,13 @@ protected function assertLinkByHref($href, $index = 0, $message = '', $group = '
    *   this default.
    *
    * @return bool
-   *   TRUE if the assertion succeeded, FALSE otherwise.
+   *   TRUE if the assertion succeeded.
    */
   protected function assertNoLinkByHref($href, $message = '', $group = 'Other') {
     $links = $this->xpath('//a[contains(@href, :href)]', [':href' => $href]);
     $message = ($message ? $message : new FormattableMarkup('No link containing href %href found.', ['%href' => $href]));
-    return $this->assert(empty($links), $message, $group);
+    $this->assertEmpty($links, $message);
+    return TRUE;
   }
 
   /**
@@ -397,12 +401,13 @@ protected function assertNoLinkByHref($href, $message = '', $group = 'Other') {
    *   this default.
    *
    * @return bool
-   *   TRUE if the assertion succeeded, FALSE otherwise.
+   *   TRUE if the assertion succeeded.
    */
   protected function assertNoLinkByHrefInMainRegion($href, $message = '', $group = 'Other') {
     $links = $this->xpath('//main//a[contains(@href, :href)]', [':href' => $href]);
     $message = ($message ? $message : new FormattableMarkup('No link containing href %href found.', ['%href' => $href]));
-    return $this->assert(empty($links), $message, $group);
+    $this->assertEmpty($links, $message);
+    return TRUE;
   }
 
   /**
@@ -686,7 +691,7 @@ protected function assertNoUniqueText($text, $message = '', $group = 'Other') {
    *   should be found more than once. Defaults to FALSE.
    *
    * @return bool
-   *   TRUE on pass, FALSE on fail.
+   *   TRUE on pass.
    */
   protected function assertUniqueTextHelper($text, $message = '', $group = 'Other', $be_unique = FALSE) {
     // Cast MarkupInterface objects to string.
@@ -696,11 +701,12 @@ protected function assertUniqueTextHelper($text, $message = '', $group = 'Other'
     }
     $first_occurrence = strpos($this->getTextContent(), $text);
     if ($first_occurrence === FALSE) {
-      return $this->assert(FALSE, $message, $group);
+      $this->fail($message);
     }
     $offset = $first_occurrence + strlen($text);
     $second_occurrence = strpos($this->getTextContent(), $text, $offset);
-    return $this->assert($be_unique == ($second_occurrence === FALSE), $message, $group);
+    $this->assertEquals($be_unique, $second_occurrence === FALSE, $message);
+    return TRUE;
   }
 
   /**
@@ -720,13 +726,14 @@ protected function assertUniqueTextHelper($text, $message = '', $group = 'Other'
    *   this default.
    *
    * @return bool
-   *   TRUE on pass, FALSE on fail.
+   *   TRUE on pass.
    */
   protected function assertPattern($pattern, $message = '', $group = 'Other') {
     if (!$message) {
       $message = new FormattableMarkup('Pattern "@pattern" found', ['@pattern' => $pattern]);
     }
-    return $this->assert((bool) preg_match($pattern, $this->getRawContent()), $message, $group);
+    $this->assertRegExp($pattern, $this->getRawContent(), $message);
+    return TRUE;
   }
 
   /**
@@ -746,13 +753,14 @@ protected function assertPattern($pattern, $message = '', $group = 'Other') {
    *   this default.
    *
    * @return bool
-   *   TRUE on pass, FALSE on fail.
+   *   TRUE on pass.
    */
   protected function assertNoPattern($pattern, $message = '', $group = 'Other') {
     if (!$message) {
       $message = new FormattableMarkup('Pattern "@pattern" not found', ['@pattern' => $pattern]);
     }
-    return $this->assert(!preg_match($pattern, $this->getRawContent()), $message, $group);
+    $this->assertNotRegExp($pattern, $this->getRawContent(), $message);
+    return TRUE;
   }
 
   /**
@@ -769,13 +777,14 @@ protected function assertNoPattern($pattern, $message = '', $group = 'Other') {
    *   this default.
    *
    * @return bool
-   *   TRUE on pass, FALSE on failure.
+   *   TRUE on pass.
    */
   protected function assertTextPattern($pattern, $message = NULL, $group = 'Other') {
     if (!isset($message)) {
       $message = new FormattableMarkup('Pattern "@pattern" found', ['@pattern' => $pattern]);
     }
-    return $this->assert((bool) preg_match($pattern, $this->getTextContent()), $message, $group);
+    $this->assertRegExp($pattern, $this->getTextContent(), $message);
+    return TRUE;
   }
 
   /**
@@ -1461,7 +1470,7 @@ protected function assertNoField($field, $message = '', $group = 'Other') {
    *   issue that is working to fix that legacy bug.
    *
    * @return bool
-   *   TRUE on pass, FALSE on fail.
+   *   TRUE on pass.
    */
   protected function assertNoDuplicateIds($message = '', $group = 'Other', $ids_to_skip = []) {
     $status = TRUE;
@@ -1473,7 +1482,8 @@ protected function assertNoDuplicateIds($message = '', $group = 'Other', $ids_to
       }
       $seen_ids[$id] = TRUE;
     }
-    return $this->assert($status, $message, $group);
+    $this->assertTrue($status, $message);
+    return TRUE;
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
index 4074a2b64c1c..48d446febd73 100644
--- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
+++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
@@ -311,10 +311,10 @@ public function testGetMultiple() {
     $cids = $reference;
     $ret = $backend->getMultiple($cids);
     // Test return - ensure it contains existing cache ids.
-    $this->assert(isset($ret['test2']), "Existing cache id test2 is set.");
-    $this->assert(isset($ret['test3']), "Existing cache id test3 is set.");
-    $this->assert(isset($ret['test6']), "Existing cache id test6 is set.");
-    $this->assert(isset($ret['test7']), "Existing cache id test7 is set.");
+    $this->assertArrayHasKey('test2', $ret, "Existing cache id test2 is set.");
+    $this->assertArrayHasKey('test3', $ret, "Existing cache id test3 is set.");
+    $this->assertArrayHasKey('test6', $ret, "Existing cache id test6 is set.");
+    $this->assertArrayHasKey('test7', $ret, "Existing cache id test7 is set.");
     // Test return - ensure that objects has expected properties.
     $this->assertTrue($ret['test2']->valid, 'Item is marked as valid.');
     $this->assertTrue($ret['test2']->created >= REQUEST_TIME && $ret['test2']->created <= round(microtime(TRUE), 3), 'Created time is correct.');
@@ -345,9 +345,9 @@ public function testGetMultiple() {
     $cids = $reference;
     $ret = $backend->getMultiple($cids);
     // Test return - ensure it contains existing cache ids.
-    $this->assert(isset($ret['test2']), "Existing cache id test2 is set");
-    $this->assert(isset($ret['test7']), "Existing cache id test7 is set");
-    $this->assert(isset($ret['test19']), "Added cache id test19 is set");
+    $this->assertArrayHasKey('test2', $ret, "Existing cache id test2 is set");
+    $this->assertArrayHasKey('test7', $ret, "Existing cache id test7 is set");
+    $this->assertArrayHasKey('test19', $ret, "Added cache id test19 is set");
     // Test return - ensure it does not contain nonexistent cache ids.
     $this->assertFalse(isset($ret['test3']), "Deleted cache id test3 is not set");
     $this->assertFalse(isset($ret['test6']), "Deleted cache id test6 is not set");
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
index 234c256e4859..76014c6e8f14 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityDefinitionUpdateTest.php
@@ -418,8 +418,8 @@ public function testBaseFieldCreateDeleteWithExistingEntities() {
     $entity->delete();
     $this->removeBaseField();
     $this->applyEntityUpdates();
-    $assert = !$schema_handler->fieldExists('entity_test_update', 'new_base_field__shape') && !$schema_handler->fieldExists('entity_test_update', 'new_base_field__color');
-    $this->assert($assert, 'Columns removed from the shared table for new_base_field.');
+    $this->assertFalse($schema_handler->fieldExists('entity_test_update', 'new_base_field__shape'), 'Shape column should be removed from the shared table for new_base_field.');
+    $this->assertFalse($schema_handler->fieldExists('entity_test_update', 'new_base_field__color'), 'Color column should be removed from the shared table for new_base_field.');
     $this->addBaseField('shape_required');
     $this->applyEntityUpdates();
     $assert = $schema_handler->fieldExists('entity_test_update', 'new_base_field__shape') && $schema_handler->fieldExists('entity_test_update', 'new_base_field__color');
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index 8a00387e70e0..e1c5711e7e7e 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -318,6 +318,16 @@ public function testProfileModules() {
     );
   }
 
+  /**
+   * Tests the deprecation of AssertLegacyTrait::assert.
+   *
+   * @group legacy
+   * @expectedDeprecation AssertLegacyTrait::assert() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertTrue() instead. See https://www.drupal.org/node/3129738
+   */
+  public function testAssert() {
+    $this->assert(TRUE);
+  }
+
   /**
    * Tests the deprecation of AssertLegacyTrait::assertIdenticalObject.
    *
diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
index cf83ea429cfc..1ab62580559d 100644
--- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -120,7 +120,6 @@ public static function getSkippedDeprecations() {
       "The \"Drupal\Tests\Listeners\DrupalListener\" class uses \"PHPUnit\Framework\TestListenerDefaultImplementation\" that is deprecated The `TestListener` interface is deprecated.",
       "The \"PHPUnit\Framework\TestSuite\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\TestSuites\TestSuiteBase\".",
       // Simpletest's legacy assertion methods.
-      'AssertLegacyTrait::assert() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertTrue() instead. See https://www.drupal.org/node/3129738',
       'AssertLegacyTrait::assertEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738',
       'AssertLegacyTrait::assertNotEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotEquals() instead. See https://www.drupal.org/node/3129738',
       'AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738',
-- 
GitLab