From 09795b6e93039f1704293f82eaa7c6bee96e2476 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Thu, 30 Dec 2021 13:40:35 +0000
Subject: [PATCH] Issue #3131348 by Spokje, jungle, mondrake, vsujeetkumar,
 sja112, kishor_kolekar, Hardik_Patel_12, mrinalini9, yogeshmpawar, daffie:
 Replace assertions involving calls to empty() with
 assertEmpty()/assertNotEmpty()/assertArrayNotHasKey()

---
 .../src/Functional/FeedFetcherPluginTest.php  |  4 +--
 .../Functional/FeedProcessorPluginTest.php    |  2 +-
 .../tests/src/Functional/BigPipeTest.php      | 19 ++++++++++--
 .../Functional/AssertBlockAppearsTrait.php    |  5 ++--
 .../tests/src/Functional/BlockHtmlTest.php    |  2 +-
 .../src/Functional/BlockLanguageTest.php      |  4 +--
 .../Functional/BlockSystemBrandingTest.php    | 30 +++++++++----------
 .../tests/src/Functional/BlockUiTest.php      | 14 ++++-----
 .../src/Functional/Views/DisplayBlockTest.php |  4 +--
 .../tests/src/Kernel/BlockStorageUnitTest.php |  8 ++---
 .../Kernel/Migrate/d7/MigrateBlockTest.php    |  2 +-
 .../src/Functional/BookBreadcrumbTest.php     |  2 +-
 .../book/tests/src/Functional/BookTest.php    |  8 ++---
 .../tests/src/Functional/BookTestTrait.php    |  2 +-
 .../Functional/Views/BookRelationshipTest.php |  2 +-
 .../tests/src/Kernel/CKEditorTest.php         |  2 +-
 .../src/Functional/CommentFieldsTest.php      |  2 +-
 .../src/Functional/CommentInterfaceTest.php   |  6 ++--
 .../src/Kernel/Views/CommentUserNameTest.php  |  2 +-
 .../src/Functional/ConfigImportUITest.php     |  4 +--
 .../Functional/ConfigTranslationUiTest.php    |  7 ++---
 .../src/Functional/DateTimeFieldTest.php      |  2 +-
 .../src/Functional/DateRangeFieldTest.php     |  2 +-
 .../EntityReferenceItemTest.php               |  2 +-
 .../EntityReferenceSettingsTest.php           |  2 +-
 .../src/Kernel/FieldAttachStorageTest.php     |  4 +--
 .../src/Kernel/FieldImportDeleteTest.php      |  2 +-
 .../tests/src/Kernel/FieldStorageCrudTest.php |  6 ++--
 .../tests/src/Kernel/EntityDisplayTest.php    |  6 ++--
 .../src/Functional/FileFieldWidgetTest.php    |  6 ++--
 .../file/tests/src/Kernel/DeleteTest.php      |  2 +-
 .../tests/src/Functional/ForumIndexTest.php   |  2 +-
 .../src/Functional/ForumNodeAccessTest.php    |  4 +--
 .../forum/tests/src/Functional/ForumTest.php  |  2 +-
 .../src/Functional/JsonApiFunctionalTest.php  | 10 +++----
 .../JsonApiDocumentTopLevelNormalizerTest.php |  6 ++--
 .../HttpExceptionNormalizerTest.php           |  4 +--
 .../Functional/LanguageConfigSchemaTest.php   |  2 +-
 .../src/Functional/LocaleContentTest.php      | 10 +++----
 .../src/Functional/NodeRevisionsTest.php      |  2 +-
 .../tests/src/Functional/PagePreviewTest.php  |  2 +-
 ...NodeAccessLanguageAwareCombinationTest.php |  2 +-
 .../Kernel/NodeAccessLanguageAwareTest.php    |  2 +-
 .../src/Kernel/NodeAccessLanguageTest.php     |  2 +-
 .../tests/src/Kernel/OptionsFieldTest.php     | 28 ++++++++---------
 .../tests/src/Functional/PathAliasTest.php    |  4 +--
 .../src/Functional/PathTaxonomyTermTest.php   |  4 +--
 .../tests/src/Kernel/QuickEditLoadingTest.php |  4 +--
 .../tests/src/Functional/SearchBlockTest.php  |  2 +-
 .../tests/src/Kernel/SearchExcerptTest.php    |  2 +-
 .../Common/NoJavaScriptAnonymousTest.php      |  2 +-
 .../tests/src/Functional/Form/FormTest.php    |  2 +-
 .../tests/src/Functional/Form/StorageTest.php |  4 +--
 .../Menu/AssertMenuActiveTrailTrait.php       |  8 ++---
 .../src/Functional/Session/SessionTest.php    |  4 +--
 .../src/Functional/Theme/EngineTwigTest.php   |  6 ++--
 .../tests/src/Kernel/Action/ActionTest.php    |  6 ++--
 ...ityReferenceSelectionReferenceableTest.php |  2 +-
 .../Kernel/Extension/ModuleHandlerTest.php    |  4 +--
 .../TaxonomyTermIndentationTest.php           |  2 +-
 .../src/Functional/TermAutocompleteTest.php   |  2 +-
 .../tests/src/Functional/TermTest.php         |  2 +-
 .../tests/src/Kernel/TermKernelTest.php       | 10 +++----
 .../text/tests/src/Kernel/TextSummaryTest.php |  4 +--
 .../tests/src/Functional/TourTestBase.php     |  2 +-
 .../src/Functional/UpdateContribTest.php      |  2 +-
 .../src/Functional/RestRegisterUserTest.php   | 10 +++----
 .../tests/src/Functional/UserCancelTest.php   |  2 +-
 .../src/Tests/AssertViewsCacheTagsTrait.php   |  2 +-
 .../src/Functional/Handler/HandlerTest.php    |  2 +-
 .../src/Functional/Plugin/DisplayFeedTest.php |  2 +-
 .../src/Functional/Plugin/DisplayTest.php     |  8 ++---
 .../src/Functional/Plugin/FilterTest.php      |  2 +-
 .../tests/src/Functional/Wizard/BasicTest.php |  3 +-
 .../tests/src/Functional/Wizard/PagerTest.php |  4 +--
 .../Plugin/views/Handler/FieldTest.php        |  2 +-
 .../tests/src/Kernel/FieldApiDataTest.php     |  2 +-
 .../src/Kernel/Handler/AreaEntityTest.php     |  4 +--
 .../tests/src/Kernel/Plugin/CacheTest.php     |  2 +-
 .../src/Kernel/Plugin/DisplayPageTest.php     |  4 +--
 .../tests/src/Kernel/PluginInstanceTest.php   |  2 +-
 .../Plugin/Derivative/ViewsLocalTaskTest.php  |  2 +-
 .../tests/src/Unit/PluginTypeListTest.php     |  2 +-
 .../tests/src/Functional/ViewEditTest.php     |  2 +-
 .../src/FunctionalJavascript/PreviewTest.php  |  8 ++---
 .../Ajax/DialogTest.php                       |  2 +-
 .../Cache/GenericCacheBackendUnitTestBase.php |  2 +-
 .../Core/Config/ConfigCRUDTest.php            |  5 +---
 .../Core/Config/ConfigDependencyTest.php      | 12 ++++----
 .../Core/Config/ConfigSchemaTest.php          |  2 +-
 .../KernelTests/Core/Database/SchemaTest.php  |  4 +--
 .../KernelTests/Core/Entity/EntityApiTest.php |  4 +--
 .../Core/Entity/EntityFieldTest.php           |  8 ++---
 .../KernelTests/Core/Field/FieldItemTest.php  |  2 +-
 .../Core/File/ScanDirectoryTest.php           |  4 +--
 .../KernelTests/Core/Form/FormCacheTest.php   |  2 +-
 .../DatabaseStorageExpirableTest.php          |  2 +-
 .../Core/Plugin/ContextPluginTest.php         |  2 +-
 .../Core/Theme/BaseThemeRequiredTest.php      |  2 +-
 .../Drupal/KernelTests/KernelTestBaseTest.php |  4 +--
 .../Discovery/YamlDirectoryDiscoveryTest.php  |  2 +-
 .../Enhancer/EntityRouteEnhancerTest.php      |  2 +-
 .../Core/Extension/InfoParserUnitTest.php     |  2 +-
 .../MetadataBubblingUrlGeneratorTest.php      |  2 +-
 .../Core/Render/RendererRecursionTest.php     |  2 +-
 105 files changed, 228 insertions(+), 225 deletions(-)

diff --git a/core/modules/aggregator/tests/src/Functional/FeedFetcherPluginTest.php b/core/modules/aggregator/tests/src/Functional/FeedFetcherPluginTest.php
index 8bf1244e353e..be18d4dc35cf 100644
--- a/core/modules/aggregator/tests/src/Functional/FeedFetcherPluginTest.php
+++ b/core/modules/aggregator/tests/src/Functional/FeedFetcherPluginTest.php
@@ -34,7 +34,7 @@ public function testfetch() {
     // Create feed with local url.
     $feed = $this->createFeed();
     $this->updateFeedItems($feed);
-    $this->assertFalse(empty($feed->items));
+    $this->assertNotEmpty($feed->items);
 
     // Delete items and restore checked property to 0.
     $this->deleteFeedItems($feed);
@@ -43,7 +43,7 @@ public function testfetch() {
     $feed->save();
     $this->updateFeedItems($feed);
     // Fetch should fail due to feed name.
-    $this->assertTrue(empty($feed->items));
+    $this->assertEmpty($feed->items);
   }
 
 }
diff --git a/core/modules/aggregator/tests/src/Functional/FeedProcessorPluginTest.php b/core/modules/aggregator/tests/src/Functional/FeedProcessorPluginTest.php
index fd13616ef100..5595a6a62c23 100644
--- a/core/modules/aggregator/tests/src/Functional/FeedProcessorPluginTest.php
+++ b/core/modules/aggregator/tests/src/Functional/FeedProcessorPluginTest.php
@@ -51,7 +51,7 @@ public function testDelete() {
     $this->updateAndDelete($feed, NULL);
     // Make sure the feed title is changed.
     $entities = \Drupal::entityTypeManager()->getStorage('aggregator_feed')->loadByProperties(['description' => $description]);
-    $this->assertTrue(empty($entities));
+    $this->assertEmpty($entities);
   }
 
   /**
diff --git a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
index dcb68b48430b..5624904e4a4e 100644
--- a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
+++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
@@ -188,7 +188,7 @@ public function testBigPipe() {
     $this->assertSession()->responseContains('</body>');
 
     // Verifying BigPipe assets are present.
-    $this->assertFalse(empty($this->getDrupalSettings()), 'drupalSettings present.');
+    $this->assertNotEmpty($this->getDrupalSettings());
     $this->assertContains('big_pipe/big_pipe', explode(',', $this->getDrupalSettings()['ajaxPageState']['libraries']), 'BigPipe asset library is present.');
 
     // Verify that the two expected exceptions are logged as errors.
@@ -506,12 +506,25 @@ protected function assertBigPipeNoJsMetaRefreshRedirect(): void {
     $this->assertEquals(302, $statuses[0], 'The first response was a 302 (redirect).');
     $this->assertStringStartsWith('big_pipe_nojs=1', $headers[0]['Set-Cookie'][0], 'The first response sets the big_pipe_nojs cookie.');
     $this->assertEquals($original_url, $headers[0]['Location'][0], 'The first response redirected back to the original page.');
-    $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.');
+    $this->assertEmpty(
+      array_diff([
+        'cookies:big_pipe_nojs',
+        'session.exists',
+      ], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0])),
+      'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'
+    );
     $this->assertFalse(isset($headers[0]['Surrogate-Control']), 'The first response has no "Surrogate-Control" header.');
 
     // Second response: redirect followed.
     $this->assertEquals(200, $statuses[1], 'The second response was a 200.');
-    $this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.');
+    $this->assertEmpty(
+      array_diff([
+        'cookies:big_pipe_nojs',
+        'session.exists',
+      ], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0])),
+      'The second response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.'
+    );
+
     $this->assertEquals('no-store, content="BigPipe/1.0"', $headers[1]['Surrogate-Control'][0], 'The second response has a "Surrogate-Control" header.');
 
     // Check that the <meta> refresh is absent, only one redirect ever happens.
diff --git a/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php b/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php
index ef3ebef2f605..b229c6f23c15 100644
--- a/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php
+++ b/core/modules/block/tests/src/Functional/AssertBlockAppearsTrait.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\block\Functional;
 
 use Drupal\block\Entity\Block;
-use Drupal\Component\Render\FormattableMarkup;
 
 /**
  * Provides test assertions for testing block appearance.
@@ -20,7 +19,7 @@ trait AssertBlockAppearsTrait {
    */
   protected function assertBlockAppears(Block $block) {
     $result = $this->findBlockInstance($block);
-    $this->assertTrue(!empty($result), new FormattableMarkup('The block @id appears on the page', ['@id' => $block->id()]));
+    $this->assertNotEmpty($result, sprintf('The block %s should appear on the page.', $block->id()));
   }
 
   /**
@@ -31,7 +30,7 @@ protected function assertBlockAppears(Block $block) {
    */
   protected function assertNoBlockAppears(Block $block) {
     $result = $this->findBlockInstance($block);
-    $this->assertFalse(!empty($result), new FormattableMarkup('The block @id does not appear on the page', ['@id' => $block->id()]));
+    $this->assertEmpty($result, sprintf('The block %s should not appear on the page.', $block->id()));
   }
 
   /**
diff --git a/core/modules/block/tests/src/Functional/BlockHtmlTest.php b/core/modules/block/tests/src/Functional/BlockHtmlTest.php
index f6e8a284194d..19223a887c91 100644
--- a/core/modules/block/tests/src/Functional/BlockHtmlTest.php
+++ b/core/modules/block/tests/src/Functional/BlockHtmlTest.php
@@ -49,7 +49,7 @@ public function testHtml() {
 
     // 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']);
-    $this->assertTrue(!empty($elements), 'The proper block markup was found.');
+    $this->assertNotEmpty($elements, 'The proper block markup was found.');
   }
 
 }
diff --git a/core/modules/block/tests/src/Functional/BlockLanguageTest.php b/core/modules/block/tests/src/Functional/BlockLanguageTest.php
index a55a0f47b716..a1380da619a0 100644
--- a/core/modules/block/tests/src/Functional/BlockLanguageTest.php
+++ b/core/modules/block/tests/src/Functional/BlockLanguageTest.php
@@ -116,13 +116,13 @@ public function testLanguageBlockVisibilityLanguageDelete() {
     // it is deleted.
     $block = Block::load($block->id());
     $visibility = $block->getVisibility();
-    $this->assertTrue(empty($visibility['language']['langcodes']['fr']), 'Language is no longer not set in the block configuration after deleting the block.');
+    $this->assertArrayNotHasKey('language', $visibility, 'Language is no longer not set in the block configuration after deleting the block.');
 
     // Ensure that the block visibility for language is gone from the UI.
     $this->drupalGet('admin/structure/block');
     $this->clickLink('Configure');
     $elements = $this->xpath('//details[@id="edit-visibility-language"]');
-    $this->assertTrue(empty($elements));
+    $this->assertEmpty($elements);
   }
 
   /**
diff --git a/core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php b/core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php
index 518e95717a4e..9e95d73b64a2 100644
--- a/core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php
+++ b/core/modules/block/tests/src/Functional/BlockSystemBrandingTest.php
@@ -48,9 +48,9 @@ public function testSystemBrandingSettings() {
     $site_name_element = $this->xpath($site_name_xpath);
     $site_slogan_element = $this->xpath($site_slogan_xpath);
     // Test that all branding elements are displayed.
-    $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
-    $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
-    $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
+    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
+    $this->assertNotEmpty($site_name_element, 'The branding block site name was found.');
+    $this->assertNotEmpty($site_slogan_element, 'The branding block slogan was found.');
     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
 
     // Be sure the slogan is XSS-filtered.
@@ -70,9 +70,9 @@ public function testSystemBrandingSettings() {
     $site_name_element = $this->xpath($site_name_xpath);
     $site_slogan_element = $this->xpath($site_slogan_xpath);
     // Re-test all branding elements.
-    $this->assertTrue(empty($site_logo_element), 'The branding block logo was disabled.');
-    $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
-    $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
+    $this->assertEmpty($site_logo_element, 'The branding block logo was disabled.');
+    $this->assertNotEmpty($site_name_element, 'The branding block site name was found.');
+    $this->assertNotEmpty($site_slogan_element, 'The branding block slogan was found.');
     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
 
     // Turn just the site name off.
@@ -85,9 +85,9 @@ public function testSystemBrandingSettings() {
     $site_name_element = $this->xpath($site_name_xpath);
     $site_slogan_element = $this->xpath($site_slogan_xpath);
     // Re-test all branding elements.
-    $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
-    $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
-    $this->assertTrue(!empty($site_slogan_element), 'The branding block slogan was found.');
+    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
+    $this->assertEmpty($site_name_element, 'The branding block site name was disabled.');
+    $this->assertNotEmpty($site_slogan_element, 'The branding block slogan was found.');
     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
 
     // Turn just the site slogan off.
@@ -100,9 +100,9 @@ public function testSystemBrandingSettings() {
     $site_name_element = $this->xpath($site_name_xpath);
     $site_slogan_element = $this->xpath($site_slogan_xpath);
     // Re-test all branding elements.
-    $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
-    $this->assertTrue(!empty($site_name_element), 'The branding block site name was found.');
-    $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
+    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
+    $this->assertNotEmpty($site_name_element, 'The branding block site name was found.');
+    $this->assertEmpty($site_slogan_element, 'The branding block slogan was disabled.');
     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
 
     // Turn the site name and the site slogan off.
@@ -115,9 +115,9 @@ public function testSystemBrandingSettings() {
     $site_name_element = $this->xpath($site_name_xpath);
     $site_slogan_element = $this->xpath($site_slogan_xpath);
     // Re-test all branding elements.
-    $this->assertTrue(!empty($site_logo_element), 'The branding block logo was found.');
-    $this->assertTrue(empty($site_name_element), 'The branding block site name was disabled.');
-    $this->assertTrue(empty($site_slogan_element), 'The branding block slogan was disabled.');
+    $this->assertNotEmpty($site_logo_element, 'The branding block logo was found.');
+    $this->assertEmpty($site_name_element, 'The branding block site name was disabled.');
+    $this->assertEmpty($site_slogan_element, 'The branding block slogan was disabled.');
     $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');
   }
 
diff --git a/core/modules/block/tests/src/Functional/BlockUiTest.php b/core/modules/block/tests/src/Functional/BlockUiTest.php
index 5618a05e5b7a..a7790c96ef48 100644
--- a/core/modules/block/tests/src/Functional/BlockUiTest.php
+++ b/core/modules/block/tests/src/Functional/BlockUiTest.php
@@ -114,7 +114,7 @@ public function testBlockAdminUiPage() {
     $this->drupalGet('admin/structure/block');
     // Look for the blocks table.
     $blocks_table = $this->xpath("//table[@id='blocks']");
-    $this->assertTrue(!empty($blocks_table), 'The blocks table is being rendered.');
+    $this->assertNotEmpty($blocks_table, 'The blocks table is being rendered.');
     // Look for test blocks in the table.
     foreach ($this->blockValues as $delta => $values) {
       $block = $this->blocks[$delta];
@@ -142,7 +142,7 @@ public function testBlockAdminUiPage() {
     $this->drupalPlaceBlock('system_powered_by_block', ['region' => 'header', 'id' => 'header']);
     $this->drupalGet('admin/structure/block');
     $element = $this->xpath('//tr[contains(@class, :class)]', [':class' => 'region-title-header']);
-    $this->assertTrue(!empty($element));
+    $this->assertNotEmpty($element);
 
     // Ensure hidden themes do not appear in the UI. Enable another non base
     // theme and place the local tasks block.
@@ -184,7 +184,7 @@ public function testCandidateBlockList() {
     $this->drupalGet('admin/structure/block');
     $this->clickLink('Place block');
     $elements = $this->xpath($pattern, $arguments);
-    $this->assertTrue(!empty($elements), 'The test block appears in the category for its module.');
+    $this->assertNotEmpty($elements, 'The test block appears in the category for its module.');
 
     // Trigger the custom category addition in block_test_block_alter().
     $this->container->get('state')->set('block_test_info_alter', TRUE);
@@ -194,7 +194,7 @@ public function testCandidateBlockList() {
     $this->clickLink('Place block');
     $arguments[':category'] = 'Custom category';
     $elements = $this->xpath($pattern, $arguments);
-    $this->assertTrue(!empty($elements), 'The test block appears in a custom category controlled by block_test_block_alter().');
+    $this->assertNotEmpty($elements, 'The test block appears in a custom category controlled by block_test_block_alter().');
   }
 
   /**
@@ -207,7 +207,7 @@ public function testContextAwareUnsatisfiedBlocks() {
     $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');
-    $this->assertTrue(!empty($definition), 'The context-aware test block does not exist.');
+    $this->assertNotEmpty($definition, 'The context-aware test block does not exist.');
   }
 
   /**
@@ -230,9 +230,9 @@ public function testContextAwareBlocks() {
     $this->drupalGet('admin/structure/block');
     $this->clickLink('Place block');
     $elements = $this->xpath($pattern, $arguments);
-    $this->assertTrue(!empty($elements), 'The context-aware test block appears.');
+    $this->assertNotEmpty($elements, 'The context-aware test block appears.');
     $definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware');
-    $this->assertTrue(!empty($definition), 'The context-aware test block exists.');
+    $this->assertNotEmpty($definition, 'The context-aware test block exists.');
     $edit = [
       'region' => 'content',
       'settings[context_mapping][user]' => '@block_test.multiple_static_context:userB',
diff --git a/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php
index 6d56f6bea0db..c3f0b15ac859 100644
--- a/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php
+++ b/core/modules/block/tests/src/Functional/Views/DisplayBlockTest.php
@@ -214,7 +214,7 @@ public function testViewsBlockForm() {
     $block = $storage->load('views_block__test_view_block_block_1');
     // This will only return a result if our new block has been created with the
     // expected machine name.
-    $this->assertTrue(!empty($block), 'The expected block was loaded.');
+    $this->assertNotEmpty($block, 'The expected block was loaded.');
 
     for ($i = 2; $i <= 3; $i++) {
       // Place the same block again and make sure we have a new ID.
@@ -223,7 +223,7 @@ public function testViewsBlockForm() {
       $block = $storage->load('views_block__test_view_block_block_1_' . $i);
       // This will only return a result if our new block has been created with the
       // expected machine name.
-      $this->assertTrue(!empty($block), 'The expected block was loaded.');
+      $this->assertNotEmpty($block, 'The expected block was loaded.');
     }
 
     // Tests the override capability of items per page.
diff --git a/core/modules/block/tests/src/Kernel/BlockStorageUnitTest.php b/core/modules/block/tests/src/Kernel/BlockStorageUnitTest.php
index 26b0b6354743..a32aa61a15af 100644
--- a/core/modules/block/tests/src/Kernel/BlockStorageUnitTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockStorageUnitTest.php
@@ -77,7 +77,7 @@ protected function createTests() {
 
     // Verify all of the block properties.
     $actual_properties = $this->config('block.block.test_block')->get();
-    $this->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.');
+    $this->assertNotEmpty($actual_properties['uuid'], 'The block UUID is set.');
     unset($actual_properties['uuid']);
 
     // Ensure that default values are filled in.
@@ -129,14 +129,14 @@ protected function deleteTests() {
     // Ensure that the storage isn't currently empty.
     $config_storage = $this->container->get('config.storage');
     $config = $config_storage->listAll('block.block.');
-    $this->assertFalse(empty($config), 'There are blocks in config storage.');
+    $this->assertNotEmpty($config, 'There are blocks in config storage.');
 
     // Delete the block.
     $entity->delete();
 
     // Ensure that the storage is now empty.
     $config = $config_storage->listAll('block.block.');
-    $this->assertTrue(empty($config), 'There are no blocks in config storage.');
+    $this->assertEmpty($config, 'There are no blocks in config storage.');
   }
 
   /**
@@ -145,7 +145,7 @@ protected function deleteTests() {
   public function testDefaultBlocks() {
     \Drupal::service('theme_installer')->install(['classy']);
     $entities = $this->controller->loadMultiple();
-    $this->assertTrue(empty($entities), 'There are no blocks initially.');
+    $this->assertEmpty($entities, 'There are no blocks initially.');
 
     // Install the block_test.module, so that its default config is installed.
     $this->installConfig(['block_test']);
diff --git a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
index a9f31b4ca3d8..0e0117e8b257 100644
--- a/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
+++ b/core/modules/block/tests/src/Kernel/Migrate/d7/MigrateBlockTest.php
@@ -167,7 +167,7 @@ public function testBlockMigration() {
       'seven_statistics_popular',
       'seven_block_1',
     ];
-    $this->assertTrue(empty(Block::loadMultiple($non_existent_blocks)));
+    $this->assertEmpty(Block::loadMultiple($non_existent_blocks));
   }
 
 }
diff --git a/core/modules/book/tests/src/Functional/BookBreadcrumbTest.php b/core/modules/book/tests/src/Functional/BookBreadcrumbTest.php
index 365a438363b5..0ecb7748a715 100644
--- a/core/modules/book/tests/src/Functional/BookBreadcrumbTest.php
+++ b/core/modules/book/tests/src/Functional/BookBreadcrumbTest.php
@@ -141,7 +141,7 @@ protected function createBookNode($book_nid, $parent = NULL) {
       $this->submitForm($edit, 'Save');
       // Make sure the parent was flagged as having children.
       $parent_node = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($parent);
-      $this->assertFalse(empty($parent_node->book['has_children']), 'Parent node is marked as having children');
+      $this->assertNotEmpty($parent_node->book['has_children'], 'Parent node is marked as having children');
     }
     else {
       $this->drupalGet('node/add/book');
diff --git a/core/modules/book/tests/src/Functional/BookTest.php b/core/modules/book/tests/src/Functional/BookTest.php
index 15366c4f5a07..230125f28c07 100644
--- a/core/modules/book/tests/src/Functional/BookTest.php
+++ b/core/modules/book/tests/src/Functional/BookTest.php
@@ -440,7 +440,7 @@ public function testBookDelete() {
     $this->submitForm($edit, 'Remove');
     $node_storage->resetCache([$nodes[4]->id()]);
     $node4 = $node_storage->load($nodes[4]->id());
-    $this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.');
+    $this->assertEmpty($node4->book, 'Deleting child book node properly allowed.');
 
     // $nodes[4] is stale, trying to delete it directly will cause an error.
     $node4->delete();
@@ -453,7 +453,7 @@ public function testBookDelete() {
     $this->submitForm($edit, 'Remove');
     $node_storage->resetCache([$this->book->id()]);
     $node = $node_storage->load($this->book->id());
-    $this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
+    $this->assertEmpty($node->book, 'Deleting childless top-level book node properly allowed.');
 
     // Tests directly deleting a book parent.
     $nodes = $this->createBook();
@@ -681,7 +681,7 @@ public function testHookNodeLoadAccess() {
     // @see node_access_test_node_grants().
     $this->drupalLogin($this->webUserWithoutNodeAccess);
     $book_node = $node_storage->load($this->book->id());
-    $this->assertTrue(!empty($book_node->book));
+    $this->assertNotEmpty($book_node->book);
     $this->assertEquals($this->book->id(), $book_node->book['bid']);
 
     // Reset the internal cache to retrigger the hook_node_load() call.
@@ -689,7 +689,7 @@ public function testHookNodeLoadAccess() {
 
     $this->drupalLogin($this->webUser);
     $book_node = $node_storage->load($this->book->id());
-    $this->assertTrue(!empty($book_node->book));
+    $this->assertNotEmpty($book_node->book);
     $this->assertEquals($this->book->id(), $book_node->book['bid']);
   }
 
diff --git a/core/modules/book/tests/src/Functional/BookTestTrait.php b/core/modules/book/tests/src/Functional/BookTestTrait.php
index 508fafab4c13..724feea3605e 100644
--- a/core/modules/book/tests/src/Functional/BookTestTrait.php
+++ b/core/modules/book/tests/src/Functional/BookTestTrait.php
@@ -198,7 +198,7 @@ public function createBookNode($book_nid, $parent = NULL, $edit = []) {
       $this->submitForm($edit, 'Save');
       // Make sure the parent was flagged as having children.
       $parent_node = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($parent);
-      $this->assertFalse(empty($parent_node->book['has_children']), 'Parent node is marked as having children');
+      $this->assertNotEmpty($parent_node->book['has_children'], 'Parent node is marked as having children');
     }
     else {
       $this->drupalGet('node/add/book');
diff --git a/core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php b/core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php
index 410adf3f9a11..5051f0a81eb6 100644
--- a/core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php
+++ b/core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php
@@ -128,7 +128,7 @@ protected function createBookNode($book_nid, $parent = NULL) {
       $this->submitForm($edit, 'Save');
       // Make sure the parent was flagged as having children.
       $parent_node = \Drupal::entityTypeManager()->getStorage('node')->loadUnchanged($parent);
-      $this->assertFalse(empty($parent_node->book['has_children']), 'Parent node is marked as having children');
+      $this->assertNotEmpty($parent_node->book['has_children'], 'Parent node is marked as having children');
     }
     else {
       $this->drupalGet('node/add/book');
diff --git a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
index 3f852ef8e313..aea21f6847c5 100644
--- a/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
+++ b/core/modules/ckeditor/tests/src/Kernel/CKEditorTest.php
@@ -422,7 +422,7 @@ public function testJSTranslation() {
     $this->ckeditor->getJSSettings($editor);
     $localeStorage = $this->container->get('locale.storage');
     $string = $localeStorage->findString(['source' => 'Edit Link', 'context' => '']);
-    $this->assertTrue(!empty($string), 'String from JavaScript file saved.');
+    $this->assertNotEmpty($string, 'String from JavaScript file saved.');
 
     // With locale module, CKEditor should not adhere to the language selected.
     $this->assertCKEditorLanguage();
diff --git a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
index 71780ada8786..7b005eaeb399 100644
--- a/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentFieldsTest.php
@@ -38,7 +38,7 @@ public function testCommentDefaultFields() {
 
     // Check that the 'comment_body' field is present on the comment bundle.
     $field = FieldConfig::loadByName('comment', 'comment', 'comment_body');
-    $this->assertTrue(!empty($field), 'The comment_body field is added when a comment bundle is created');
+    $this->assertNotEmpty($field, 'The comment_body field is added when a comment bundle is created');
 
     $field->delete();
 
diff --git a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
index 1440743eb19a..6631b26f9107 100644
--- a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php
@@ -92,7 +92,7 @@ public function testCommentInterface() {
     ];
     $pattern_permalink = '//footer[contains(@class,"comment__meta")]/a[contains(@href,:link) and text()="Permalink"]';
     $permalink = $this->xpath($pattern_permalink, $arguments);
-    $this->assertTrue(!empty($permalink), 'Permalink link found.');
+    $this->assertNotEmpty($permalink, 'Permalink link found.');
 
     // Set comments to have subject and preview to optional.
     $this->drupalLogout();
@@ -317,7 +317,7 @@ public function testViewMode() {
 
     // Comment displayed in 'default' display mode found and has body text.
     $comment_element = $this->cssSelect('.comment-wrapper');
-    $this->assertTrue(!empty($comment_element));
+    $this->assertNotEmpty($comment_element);
     $this->assertSession()->responseContains('<p>' . $comment_text . '</p>');
 
     // Create a new comment entity view mode.
@@ -350,7 +350,7 @@ public function testViewMode() {
     // The comment should exist but without the body text because we used $mode
     // mode this time.
     $comment_element = $this->cssSelect('.comment-wrapper');
-    $this->assertTrue(!empty($comment_element));
+    $this->assertNotEmpty($comment_element);
     $this->assertSession()->responseNotContains('<p>' . $comment_text . '</p>');
   }
 
diff --git a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
index 099db671d4eb..e65be6c6b584 100644
--- a/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
+++ b/core/modules/comment/tests/src/Kernel/Views/CommentUserNameTest.php
@@ -158,7 +158,7 @@ public function testUsername() {
     $comment_author = $this->xpath('//div[contains(@class, :class)]/span[normalize-space(text())=""]', [
       ':class' => 'views-field-subject',
     ]);
-    $this->assertTrue(!empty($comment_author));
+    $this->assertNotEmpty($comment_author);
     // When comment belongs to an anonymous user the name field has a value and
     // it is rendered correctly.
     $this->assertLink('barry (not verified)');
diff --git a/core/modules/config/tests/src/Functional/ConfigImportUITest.php b/core/modules/config/tests/src/Functional/ConfigImportUITest.php
index 5e4bdd1d13d7..a2078e6d30a8 100644
--- a/core/modules/config/tests/src/Functional/ConfigImportUITest.php
+++ b/core/modules/config/tests/src/Functional/ConfigImportUITest.php
@@ -162,7 +162,7 @@ public function testImport() {
     $uninstalled = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
     $expected = ['automated_cron', 'ban', 'text', 'options'];
     $this->assertSame($expected, $installed, 'Automated Cron, Ban, Text and Options modules installed in the correct order.');
-    $this->assertTrue(empty($uninstalled), 'No modules uninstalled during import');
+    $this->assertEmpty($uninstalled, 'No modules uninstalled during import');
 
     // Verify that the automated_cron configuration object was only written
     // once during the import process and only with the value set in the staged
@@ -218,7 +218,7 @@ public function testImport() {
     $uninstalled = \Drupal::state()->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
     $expected = ['options', 'text', 'ban', 'automated_cron'];
     $this->assertSame($expected, $uninstalled, 'Options, Text, Ban and Automated Cron modules uninstalled in the correct order.');
-    $this->assertTrue(empty($installed), 'No modules installed during import');
+    $this->assertEmpty($installed, 'No modules installed during import');
 
     $theme_info = \Drupal::service('theme_handler')->listInfo();
     $this->assertFalse(isset($theme_info['bartik']), 'Bartik theme uninstalled during import.');
diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
index 1fd76ccaff37..42d54b21efe8 100644
--- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
+++ b/core/modules/config_translation/tests/src/Functional/ConfigTranslationUiTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\config_translation\Functional;
 
 use Drupal\Component\Utility\Html;
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Language\Language;
 use Drupal\Core\Language\LanguageInterface;
 use Drupal\Core\Test\AssertMailTrait;
@@ -843,7 +842,7 @@ public function testLocaleDBStorage() {
 
     // Make sure there is no translation stored in locale storage before edit.
     $translation = $this->getTranslation('user.settings', 'anonymous', 'fr');
-    $this->assertTrue(empty($translation));
+    $this->assertEmpty($translation);
 
     // Add custom translation.
     $edit = [
@@ -1124,12 +1123,12 @@ public function testMenuTranslationWithoutChange() {
    */
   protected function getTranslation($config_name, $key, $langcode) {
     $settings_locations = $this->localeStorage->getLocations(['type' => 'configuration', 'name' => $config_name]);
-    $this->assertTrue(!empty($settings_locations), new FormattableMarkup('Configuration locations found for %config_name.', ['%config_name' => $config_name]));
+    $this->assertNotEmpty($settings_locations, "$config_name should have configuration locations.");
 
     if (!empty($settings_locations)) {
       $source = $this->container->get('config.factory')->get($config_name)->get($key);
       $source_string = $this->localeStorage->findString(['source' => $source, 'type' => 'configuration']);
-      $this->assertTrue(!empty($source_string), new FormattableMarkup('Found string for %config_name.%key.', ['%config_name' => $config_name, '%key' => $key]));
+      $this->assertNotEmpty($source_string, "$config_name.$key should have a source string.");
 
       if (!empty($source_string)) {
         $conditions = [
diff --git a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
index 17f70fc4b67c..735541441106 100644
--- a/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
+++ b/core/modules/datetime/tests/src/Functional/DateTimeFieldTest.php
@@ -776,7 +776,7 @@ public function testDefaultValue() {
       // Check if default_date has been stored successfully.
       $config_entity = $this->config('field.field.node.date_content.' . $field_name)
         ->get();
-      $this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully');
+      $this->assertEmpty($config_entity['default_value'], 'Empty default value has been stored successfully');
 
       // Clear field cache in order to avoid stale cache values.
       \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
diff --git a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
index d6c4e0cb7728..3d323450b8df 100644
--- a/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
+++ b/core/modules/datetime_range/tests/src/Functional/DateRangeFieldTest.php
@@ -1118,7 +1118,7 @@ public function testDefaultValue() {
 
     // Check if default_date has been stored successfully.
     $config_entity = $this->config('field.field.node.date_content.' . $field_name)->get();
-    $this->assertTrue(empty($config_entity['default_value']), 'Empty default value has been stored successfully');
+    $this->assertEmpty($config_entity['default_value'], 'Empty default value has been stored successfully');
 
     // Clear field cache in order to avoid stale cache values.
     \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php
index 027d0eb7640b..10fda5adc584 100644
--- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php
+++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceItemTest.php
@@ -347,7 +347,7 @@ public function testEntitySaveOrder() {
     $entity->name->value = $this->randomMachineName();
     // Now get the field value.
     $value = $entity->get('field_test_taxonomy_term');
-    $this->assertTrue(empty($value['target_id']));
+    $this->assertArrayNotHasKey('target_id', $value);
     $this->assertNull($entity->field_test_taxonomy_term->target_id);
     // And then set it.
     $entity->field_test_taxonomy_term = $value;
diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceSettingsTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceSettingsTest.php
index 715839cacc1d..6850eeae370b 100644
--- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceSettingsTest.php
+++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceSettingsTest.php
@@ -177,7 +177,7 @@ public function testCustomTargetBundleDeletion() {
     // 'target_bundles' field setting.
     $field_config = FieldConfig::loadByName('node', $this->nodeType->id(), $name);
     $handler_settings = $field_config->getSetting('handler_settings');
-    $this->assertTrue(empty($handler_settings['target_bundles']));
+    $this->assertEmpty($handler_settings['target_bundles']);
   }
 
   /**
diff --git a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php
index d46815f006d3..1ae862084064 100644
--- a/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php
+++ b/core/modules/field/tests/src/Kernel/FieldAttachStorageTest.php
@@ -365,8 +365,8 @@ public function testEntityDeleteBundle() {
     $controller->resetCache();
     $entity = $controller->load($entity->id());
 
-    $this->assertTrue(empty($entity->{$this->fieldTestData->field_name}), 'No data for first field');
-    $this->assertTrue(empty($entity->{$field_name}), 'No data for second field');
+    $this->assertEmpty($entity->{$this->fieldTestData->field_name}, 'No data for first field');
+    $this->assertEmpty($entity->{$field_name}, 'No data for second field');
 
     // Verify that the fields are gone.
     $this->assertNull(FieldConfig::load('entity_test.' . $this->fieldTestData->field->getTargetBundle() . '.' . $this->fieldTestData->field_name), "First field is deleted");
diff --git a/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php b/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php
index 85653e2d7f3d..10a972abc5ce 100644
--- a/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php
+++ b/core/modules/field/tests/src/Kernel/FieldImportDeleteTest.php
@@ -115,7 +115,7 @@ public function testImportDelete() {
     // completely removed once the data is purged.
     field_purge_batch(10);
     $deleted_storages = \Drupal::state()->get('field.storage.deleted', []);
-    $this->assertTrue(empty($deleted_storages), 'Fields are deleted');
+    $this->assertEmpty($deleted_storages, 'Fields are deleted');
   }
 
 }
diff --git a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php
index a73f22dc72dd..266f20910e07 100644
--- a/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php
+++ b/core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php
@@ -227,7 +227,7 @@ public function testRead() {
     $this->assertCount(1, $fields, 'The field was properly read.');
     $this->assertArrayHasKey($id, $fields, 'The field has the correct key.');
     $fields = $field_storage_config_storage->loadByProperties(['field_name' => $field_storage_definition['field_name'], 'type' => 'foo']);
-    $this->assertTrue(empty($fields), 'No field was found.');
+    $this->assertEmpty($fields, 'No field was found.');
 
     // Create a field from the field storage.
     $field_definition = [
@@ -337,11 +337,11 @@ public function testDeleteNoData() {
 
     // Try to load the storage normally and make sure it does not show up.
     $field_storage = FieldStorageConfig::load('entity_test.' . $field_storage_definition['field_name']);
-    $this->assertTrue(empty($field_storage), 'Field storage was deleted');
+    $this->assertEmpty($field_storage, 'Field storage was deleted');
 
     // Try to load the field normally and make sure it does not show up.
     $field = FieldConfig::load('entity_test.' . '.' . $field_definition['bundle'] . '.' . $field_definition['field_name']);
-    $this->assertTrue(empty($field), 'Field was deleted');
+    $this->assertEmpty($field, 'Field was deleted');
 
     // Make sure the other field and its storage are not deleted.
     $another_field_storage = FieldStorageConfig::load('entity_test.' . $another_field_storage_definition['field_name']);
diff --git a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
index 358c1f04e15b..e4cc74b449d0 100644
--- a/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
+++ b/core/modules/field_ui/tests/src/Kernel/EntityDisplayTest.php
@@ -595,7 +595,7 @@ public function testComponentDependencies() {
     // Reload the form display.
     $form_display = EntityFormDisplay::load($form_display->id());
     // The display exists.
-    $this->assertFalse(empty($form_display));
+    $this->assertNotEmpty($form_display);
     // The form display should not depend on $role[0] anymore.
     $this->assertNoDependency('config', $dependencies[0], $form_display);
     // The form display should depend on 'anonymous' user role.
@@ -612,7 +612,7 @@ public function testComponentDependencies() {
     // Reload the form display.
     $form_display = EntityFormDisplay::load($form_display->id());
     // The display exists.
-    $this->assertFalse(empty($form_display));
+    $this->assertNotEmpty($form_display);
     // The component is still enabled.
     $this->assertNotNull($form_display->getComponent($field_name));
     // The form display should not depend on 'color' module anymore.
@@ -624,7 +624,7 @@ public function testComponentDependencies() {
     // Reload the form display.
     $form_display = EntityFormDisplay::load($form_display->id());
     // The display exists.
-    $this->assertFalse(empty($form_display));
+    $this->assertNotEmpty($form_display);
     // The component has been disabled.
     $this->assertNull($form_display->getComponent($field_name));
     $this->assertTrue($form_display->get('hidden')[$field_name]);
diff --git a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
index bef8026c396e..49178c9f4dd8 100644
--- a/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
+++ b/core/modules/file/tests/src/Functional/FileFieldWidgetTest.php
@@ -113,7 +113,7 @@ public function testSingleValuedWidget() {
     // Save the node and ensure it does not have the file.
     $this->submitForm([], 'Save');
     $node = $node_storage->loadUnchanged($nid);
-    $this->assertTrue(empty($node->{$field_name}->target_id), 'File was successfully removed from the node.');
+    $this->assertEmpty($node->{$field_name}->target_id, 'File was successfully removed from the node.');
   }
 
   /**
@@ -204,7 +204,7 @@ public function testMultiValuedWidget() {
     preg_match('/node\/([0-9])/', $this->getUrl(), $matches);
     $nid = $matches[1];
     $node = $node_storage->loadUnchanged($nid);
-    $this->assertTrue(empty($node->{$field_name}->target_id), 'Node was successfully saved without any files.');
+    $this->assertEmpty($node->{$field_name}->target_id, 'Node was successfully saved without any files.');
 
     // Try to upload more files than allowed on revision.
     $upload_files_node_revision = [$test_file, $test_file, $test_file, $test_file];
@@ -575,7 +575,7 @@ protected function doTestTemporaryFileRemovalExploit(UserInterface $victim_user,
     $victim_tmp_file = $this->createTemporaryFile('some text', $victim_user);
     $victim_tmp_file = File::load($victim_tmp_file->id());
     $this->assertTrue($victim_tmp_file->isTemporary(), 'New file saved to disk is temporary.');
-    $this->assertFalse(empty($victim_tmp_file->id()), 'New file has an fid.');
+    $this->assertNotEmpty($victim_tmp_file->id(), 'New file has an fid.');
     $this->assertEquals($victim_user->id(), $victim_tmp_file->getOwnerId(), 'New file belongs to the victim.');
 
     // Have attacker create a new node with a different uploaded file and
diff --git a/core/modules/file/tests/src/Kernel/DeleteTest.php b/core/modules/file/tests/src/Kernel/DeleteTest.php
index 59b0ea405388..e3ca3f5e3c0a 100644
--- a/core/modules/file/tests/src/Kernel/DeleteTest.php
+++ b/core/modules/file/tests/src/Kernel/DeleteTest.php
@@ -52,7 +52,7 @@ public function testInUse() {
     $file_usage->delete($file, 'testing', 'test', 1);
     $usage = $file_usage->listUsage($file);
     $this->assertFileHooksCalled(['load', 'update']);
-    $this->assertTrue(empty($usage), 'File usage data was removed.');
+    $this->assertEmpty($usage, 'File usage data was removed.');
     $this->assertFileExists($file->getFileUri());
     $file = File::load($file->id());
     $this->assertNotEmpty($file, 'File still exists in the database.');
diff --git a/core/modules/forum/tests/src/Functional/ForumIndexTest.php b/core/modules/forum/tests/src/Functional/ForumIndexTest.php
index d90c73d31ce6..8be1ca651f8b 100644
--- a/core/modules/forum/tests/src/Functional/ForumIndexTest.php
+++ b/core/modules/forum/tests/src/Functional/ForumIndexTest.php
@@ -59,7 +59,7 @@ public function testForumIndexStatus() {
 
     // Check that the node exists in the database.
     $node = $this->drupalGetNodeByTitle($title);
-    $this->assertTrue(!empty($node), 'New forum node found in database.');
+    $this->assertNotEmpty($node, 'New forum node found in database.');
 
     // Create a child forum.
     $edit = [
diff --git a/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php b/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php
index 1ca15cb687c7..bbc0efe1314d 100644
--- a/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php
+++ b/core/modules/forum/tests/src/Functional/ForumNodeAccessTest.php
@@ -68,7 +68,7 @@ public function testForumNodeAccess() {
     $this->drupalGet('node/add/forum', ['query' => ['forum_id' => 1]]);
     $this->submitForm($edit, 'Save');
     $private_node = $this->drupalGetNodeByTitle($private_node_title);
-    $this->assertTrue(!empty($private_node), 'New private forum node found in database.');
+    $this->assertNotEmpty($private_node, 'New private forum node found in database.');
 
     // Create a public node.
     $public_node_title = $this->randomMachineName(20);
@@ -79,7 +79,7 @@ public function testForumNodeAccess() {
     $this->drupalGet('node/add/forum', ['query' => ['forum_id' => 1]]);
     $this->submitForm($edit, 'Save');
     $public_node = $this->drupalGetNodeByTitle($public_node_title);
-    $this->assertTrue(!empty($public_node), 'New public forum node found in database.');
+    $this->assertNotEmpty($public_node, 'New public forum node found in database.');
 
     // Enable the new and active forum blocks.
     $this->drupalPlaceBlock('forum_active_block');
diff --git a/core/modules/forum/tests/src/Functional/ForumTest.php b/core/modules/forum/tests/src/Functional/ForumTest.php
index 4d1e0767eacb..29135c74837e 100644
--- a/core/modules/forum/tests/src/Functional/ForumTest.php
+++ b/core/modules/forum/tests/src/Functional/ForumTest.php
@@ -464,7 +464,7 @@ public function createForum($type, $parent = 0) {
       'description__value' => $description,
     ]);
     $term = array_shift($term);
-    $this->assertTrue(!empty($term), 'The ' . $type . ' exists in the database');
+    $this->assertNotEmpty($term, "The forum type '$type' should exist in the database.");
 
     // Verify forum hierarchy.
     $tid = $term->id();
diff --git a/core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTest.php b/core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTest.php
index 167e279b444c..8bacd7c95186 100644
--- a/core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTest.php
+++ b/core/modules/jsonapi/tests/src/Functional/JsonApiFunctionalTest.php
@@ -179,9 +179,9 @@ public function testRead() {
       'user--user',
       $first_include['type']
     );
-    $this->assertFalse(empty($first_include['attributes']));
-    $this->assertTrue(empty($first_include['attributes']['mail']));
-    $this->assertTrue(empty($first_include['attributes']['pass']));
+    $this->assertNotEmpty($first_include['attributes']);
+    $this->assertArrayNotHasKey('mail', $first_include['attributes']);
+    $this->assertArrayNotHasKey('pass', $first_include['attributes']);
     // 12. Collection with one access denied.
     $this->nodes[1]->set('status', FALSE);
     $this->nodes[1]->save();
@@ -284,8 +284,8 @@ public function testRead() {
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('user--user', $single_output['data']['type']);
     $this->assertEquals($this->user->get('name')->value, $single_output['data']['attributes']['name']);
-    $this->assertTrue(empty($single_output['data']['attributes']['mail']));
-    $this->assertTrue(empty($single_output['data']['attributes']['pass']));
+    $this->assertArrayNotHasKey('mail', $single_output['data']['attributes']);
+    $this->assertArrayNotHasKey('pass', $single_output['data']['attributes']);
     // 18. Test filtering on the column of a link.
     $filter = [
       'linkUri' => [
diff --git a/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php b/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
index c3ee121f41d8..c104fbea3723 100644
--- a/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
+++ b/core/modules/jsonapi/tests/src/Kernel/Normalizer/JsonApiDocumentTopLevelNormalizerTest.php
@@ -299,7 +299,7 @@ public function testNormalize() {
         'related' => ['href' => Url::fromUri('internal:/jsonapi/node/article/' . $this->node->uuid() . '/uid', ['query' => ['resourceVersion' => 'id:' . $this->node->getRevisionId()]])->setAbsolute()->toString(TRUE)->getGeneratedUrl()],
       ],
     ], $normalized['data']['relationships']['uid']);
-    $this->assertTrue(empty($normalized['meta']['omitted']));
+    $this->assertArrayNotHasKey('meta', $normalized);
     $this->assertSame($this->user->uuid(), $normalized['included'][0]['id']);
     $this->assertSame('user--user', $normalized['included'][0]['type']);
     $this->assertSame('user1', $normalized['included'][0]['attributes']['display_name']);
@@ -394,8 +394,8 @@ public function testNormalizeUuid() {
     $this->assertStringMatchesFormat($this->node->uuid(), $normalized['data']['id']);
     $this->assertEquals($this->node->type->entity->uuid(), $normalized['data']['relationships']['node_type']['data']['id']);
     $this->assertEquals($this->user->uuid(), $normalized['data']['relationships']['uid']['data']['id']);
-    $this->assertFalse(empty($normalized['included'][0]['id']));
-    $this->assertTrue(empty($normalized['meta']['omitted']));
+    $this->assertNotEmpty($normalized['included'][0]['id']);
+    $this->assertArrayNotHasKey('meta', $normalized);
     $this->assertEquals($this->user->uuid(), $normalized['included'][0]['id']);
     $this->assertCount(1, $normalized['included'][0]['attributes']);
     $this->assertCount(12, $normalized['included'][1]['attributes']);
diff --git a/core/modules/jsonapi/tests/src/Unit/Normalizer/HttpExceptionNormalizerTest.php b/core/modules/jsonapi/tests/src/Unit/Normalizer/HttpExceptionNormalizerTest.php
index 1e43522591e2..928fdf8514ae 100644
--- a/core/modules/jsonapi/tests/src/Unit/Normalizer/HttpExceptionNormalizerTest.php
+++ b/core/modules/jsonapi/tests/src/Unit/Normalizer/HttpExceptionNormalizerTest.php
@@ -49,8 +49,8 @@ public function testNormalize() {
     $normalized = $normalizer->normalize($exception, 'api_json');
     $normalized = $normalized->getNormalization();
     $error = $normalized[0];
-    $this->assertTrue(empty($error['meta']));
-    $this->assertTrue(empty($error['source']));
+    $this->assertArrayNotHasKey('meta', $error);
+    $this->assertArrayNotHasKey('source', $error);
   }
 
 }
diff --git a/core/modules/language/tests/src/Functional/LanguageConfigSchemaTest.php b/core/modules/language/tests/src/Functional/LanguageConfigSchemaTest.php
index af801d8ca87f..7145d7c30c80 100644
--- a/core/modules/language/tests/src/Functional/LanguageConfigSchemaTest.php
+++ b/core/modules/language/tests/src/Functional/LanguageConfigSchemaTest.php
@@ -50,7 +50,7 @@ protected function setUp(): void {
   public function testValidLanguageConfigSchema() {
     // Make sure no language configuration available by default.
     $config_data = $this->config('language.settings')->get();
-    $this->assertTrue(empty($config_data));
+    $this->assertEmpty($config_data);
 
     $settings_path = 'admin/config/regional/content-language';
 
diff --git a/core/modules/locale/tests/src/Functional/LocaleContentTest.php b/core/modules/locale/tests/src/Functional/LocaleContentTest.php
index 1f67248703c9..9b4c3b51ea6d 100644
--- a/core/modules/locale/tests/src/Functional/LocaleContentTest.php
+++ b/core/modules/locale/tests/src/Functional/LocaleContentTest.php
@@ -215,25 +215,25 @@ public function testContentTypeDirLang() {
     // Check if English node does not have lang tag.
     $this->drupalGet('node/' . $nodes['en']->id());
     $element = $this->cssSelect('article.node[lang="en"]');
-    $this->assertTrue(empty($element), 'The lang tag has not been assigned to the English node.');
+    $this->assertEmpty($element, 'The lang tag has not been assigned to the English node.');
 
     // Check if English node does not have dir tag.
     $element = $this->cssSelect('article.node[dir="ltr"]');
-    $this->assertTrue(empty($element), 'The dir tag has not been assigned to the English node.');
+    $this->assertEmpty($element, 'The dir tag has not been assigned to the English node.');
 
     // Check if Arabic node has lang="ar" & dir="rtl" tags.
     $this->drupalGet('node/' . $nodes['ar']->id());
     $element = $this->cssSelect('article.node[lang="ar"][dir="rtl"]');
-    $this->assertTrue(!empty($element), 'The lang and dir tags have been assigned correctly to the Arabic node.');
+    $this->assertNotEmpty($element, 'The lang and dir tags have been assigned correctly to the Arabic node.');
 
     // Check if Spanish node has lang="es" tag.
     $this->drupalGet('node/' . $nodes['es']->id());
     $element = $this->cssSelect('article.node[lang="es"]');
-    $this->assertTrue(!empty($element), 'The lang tag has been assigned correctly to the Spanish node.');
+    $this->assertNotEmpty($element, 'The lang tag has been assigned correctly to the Spanish node.');
 
     // Check if Spanish node does not have dir="ltr" tag.
     $element = $this->cssSelect('article.node[lang="es"][dir="ltr"]');
-    $this->assertTrue(empty($element), 'The dir tag has not been assigned to the Spanish node.');
+    $this->assertEmpty($element, 'The dir tag has not been assigned to the Spanish node.');
   }
 
 }
diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsTest.php
index e3bcc483002b..f22cc669128b 100644
--- a/core/modules/node/tests/src/Functional/NodeRevisionsTest.php
+++ b/core/modules/node/tests/src/Functional/NodeRevisionsTest.php
@@ -358,7 +358,7 @@ public function testNodeRevisionWithoutLogMessage() {
     $this->assertSession()->pageTextContains($new_title);
     $node_storage->resetCache([$node->id()]);
     $node_revision = $node_storage->load($node->id());
-    $this->assertTrue(empty($node_revision->revision_log->value), 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
+    $this->assertEmpty($node_revision->revision_log->value, 'After a new node revision is saved with an empty log message, the log message for the node is empty.');
   }
 
   /**
diff --git a/core/modules/node/tests/src/Functional/PagePreviewTest.php b/core/modules/node/tests/src/Functional/PagePreviewTest.php
index 4eca2c42b381..9f188c001014 100644
--- a/core/modules/node/tests/src/Functional/PagePreviewTest.php
+++ b/core/modules/node/tests/src/Functional/PagePreviewTest.php
@@ -213,7 +213,7 @@ public function testPagePreview() {
 
     // Check that we see the class of the node type on the body element.
     $body_class_element = $this->xpath("//body[contains(@class, 'page-node-type-page')]");
-    $this->assertTrue(!empty($body_class_element), 'Node type body class found.');
+    $this->assertNotEmpty($body_class_element, 'Node type body class found.');
 
     // Get the UUID.
     $url = parse_url($this->getUrl());
diff --git a/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareCombinationTest.php
index 2a71d6446f3b..dc1966815f5f 100644
--- a/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareCombinationTest.php
+++ b/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareCombinationTest.php
@@ -309,7 +309,7 @@ public function testNodeAccessLanguageAwareCombination() {
     $nids = $select->execute()->fetchAllAssoc('nid');
 
     // There are no nodes with German translations, so no results are returned.
-    $this->assertTrue(empty($nids), 'Query returns an empty result.');
+    $this->assertEmpty($nids, 'Query returns an empty result.');
 
     // Query the nodes table as admin user (full access) with the node access
     // tag and no specific langcode.
diff --git a/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php b/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php
index 7fb406758629..e4ec70f980f9 100644
--- a/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php
+++ b/core/modules/node/tests/src/Kernel/NodeAccessLanguageAwareTest.php
@@ -247,7 +247,7 @@ public function testNodeAccessLanguageAware() {
     $nids = $select->execute()->fetchAllAssoc('nid');
 
     // There are no nodes with German translations, so no results are returned.
-    $this->assertTrue(empty($nids), 'Query returns an empty result when the de langcode is specified.');
+    $this->assertEmpty($nids, 'Query returns an empty result when the de langcode is specified.');
 
     // Query the nodes table as admin user (full access) with the node access
     // tag and no specific langcode.
diff --git a/core/modules/node/tests/src/Kernel/NodeAccessLanguageTest.php b/core/modules/node/tests/src/Kernel/NodeAccessLanguageTest.php
index a7a66057af98..7e9f8873006a 100644
--- a/core/modules/node/tests/src/Kernel/NodeAccessLanguageTest.php
+++ b/core/modules/node/tests/src/Kernel/NodeAccessLanguageTest.php
@@ -231,7 +231,7 @@ public function testNodeAccessQueryTag() {
     $nids = $select->execute()->fetchAllAssoc('nid');
 
     // Because no nodes are created in German, no nodes are returned.
-    $this->assertTrue(empty($nids), 'Query returns an empty result.');
+    $this->assertEmpty($nids, 'Query returns an empty result.');
 
     // Query the nodes table as admin user (full access) with the node access
     // tag and no specific langcode.
diff --git a/core/modules/options/tests/src/Kernel/OptionsFieldTest.php b/core/modules/options/tests/src/Kernel/OptionsFieldTest.php
index d80be94be799..001a04e17197 100644
--- a/core/modules/options/tests/src/Kernel/OptionsFieldTest.php
+++ b/core/modules/options/tests/src/Kernel/OptionsFieldTest.php
@@ -28,9 +28,9 @@ public function testUpdateAllowedValues() {
     // All three options appear.
     $entity = EntityTest::create();
     $form = \Drupal::service('entity.form_builder')->getForm($entity);
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists');
+    $this->assertArrayHasKey(1, $form[$this->fieldName]['widget'], 'Option 1 exists');
+    $this->assertArrayHasKey(2, $form[$this->fieldName]['widget'], 'Option 2 exists');
+    $this->assertArrayHasKey(3, $form[$this->fieldName]['widget'], 'Option 3 exists');
 
     // Use one of the values in an actual entity, and check that this value
     // cannot be removed from the list.
@@ -54,9 +54,9 @@ public function testUpdateAllowedValues() {
     $this->fieldStorage->save();
     $entity = EntityTest::create();
     $form = \Drupal::service('entity.form_builder')->getForm($entity);
-    $this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists');
-    $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist');
+    $this->assertArrayNotHasKey(1, $form[$this->fieldName]['widget'], 'Option 1 does not exist');
+    $this->assertArrayHasKey(2, $form[$this->fieldName]['widget'], 'Option 2 exists');
+    $this->assertArrayNotHasKey(3, $form[$this->fieldName]['widget'], 'Option 3 does not exist');
 
     // Completely new options appear.
     $this->fieldStorage->setSetting('allowed_values', [10 => 'Update', 20 => 'Twenty']);
@@ -65,11 +65,11 @@ public function testUpdateAllowedValues() {
     // setting, so we need to reinitialize the entity object.
     $entity = EntityTest::create();
     $form = \Drupal::service('entity.form_builder')->getForm($entity);
-    $this->assertTrue(empty($form[$this->fieldName]['widget'][1]), 'Option 1 does not exist');
-    $this->assertTrue(empty($form[$this->fieldName]['widget'][2]), 'Option 2 does not exist');
-    $this->assertTrue(empty($form[$this->fieldName]['widget'][3]), 'Option 3 does not exist');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][10]), 'Option 10 exists');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][20]), 'Option 20 exists');
+    $this->assertArrayNotHasKey(1, $form[$this->fieldName]['widget'], 'Option 1 does not exist');
+    $this->assertArrayNotHasKey(2, $form[$this->fieldName]['widget'], 'Option 2 does not exist');
+    $this->assertArrayNotHasKey(3, $form[$this->fieldName]['widget'], 'Option 3 does not exist');
+    $this->assertArrayHasKey(10, $form[$this->fieldName]['widget'], 'Option 10 exists');
+    $this->assertArrayHasKey(20, $form[$this->fieldName]['widget'], 'Option 20 exists');
 
     // Options are reset when a new field with the same name is created.
     $this->fieldStorage->delete();
@@ -88,9 +88,9 @@ public function testUpdateAllowedValues() {
       ->save();
     $entity = EntityTest::create();
     $form = \Drupal::service('entity.form_builder')->getForm($entity);
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][1]), 'Option 1 exists');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][2]), 'Option 2 exists');
-    $this->assertTrue(!empty($form[$this->fieldName]['widget'][3]), 'Option 3 exists');
+    $this->assertArrayHasKey(1, $form[$this->fieldName]['widget'], 'Option 1 exists');
+    $this->assertArrayHasKey(2, $form[$this->fieldName]['widget'], 'Option 2 exists');
+    $this->assertArrayHasKey(3, $form[$this->fieldName]['widget'], 'Option 3 exists');
 
     // Test the generateSampleValue() method.
     $entity = EntityTest::create();
diff --git a/core/modules/path/tests/src/Functional/PathAliasTest.php b/core/modules/path/tests/src/Functional/PathAliasTest.php
index 04acb78a1b20..013ceebdc3d1 100644
--- a/core/modules/path/tests/src/Functional/PathAliasTest.php
+++ b/core/modules/path/tests/src/Functional/PathAliasTest.php
@@ -267,9 +267,9 @@ public function testNodeAlias() {
 
     // Confirm the 'canonical' and 'shortlink' URLs.
     $elements = $this->xpath("//link[contains(@rel, 'canonical') and contains(@href, '" . $edit['path[0][alias]'] . "')]");
-    $this->assertTrue(!empty($elements), 'Page contains canonical link URL.');
+    $this->assertNotEmpty($elements, 'Page contains canonical link URL.');
     $elements = $this->xpath("//link[contains(@rel, 'shortlink') and contains(@href, 'node/" . $node1->id() . "')]");
-    $this->assertTrue(!empty($elements), 'Page contains shortlink URL.');
+    $this->assertNotEmpty($elements, 'Page contains shortlink URL.');
 
     $previous = $edit['path[0][alias]'];
     // Change alias to one containing "exotic" characters.
diff --git a/core/modules/path/tests/src/Functional/PathTaxonomyTermTest.php b/core/modules/path/tests/src/Functional/PathTaxonomyTermTest.php
index 821727d1993a..b578e92640ec 100644
--- a/core/modules/path/tests/src/Functional/PathTaxonomyTermTest.php
+++ b/core/modules/path/tests/src/Functional/PathTaxonomyTermTest.php
@@ -69,9 +69,9 @@ public function testTermAlias() {
 
     // Confirm the 'canonical' and 'shortlink' URLs.
     $elements = $this->xpath("//link[contains(@rel, 'canonical') and contains(@href, '" . $edit['path[0][alias]'] . "')]");
-    $this->assertTrue(!empty($elements), 'Term page contains canonical link URL.');
+    $this->assertNotEmpty($elements, 'Term page contains canonical link URL.');
     $elements = $this->xpath("//link[contains(@rel, 'shortlink') and contains(@href, 'taxonomy/term/" . $tid . "')]");
-    $this->assertTrue(!empty($elements), 'Term page contains shortlink URL.');
+    $this->assertNotEmpty($elements, 'Term page contains shortlink URL.');
 
     // Change the term's URL alias.
     $edit2 = [];
diff --git a/core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php b/core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php
index d034d2c9e140..0066ca9495e9 100644
--- a/core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php
+++ b/core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php
@@ -77,12 +77,12 @@ public function testDisplayOptions() {
     $build = $node->body->view(['label' => 'inline']);
     $this->setRawContent($renderer->renderRoot($build));
     $elements = $this->xpath('//div[@data-quickedit-field-id]');
-    $this->assertFalse(!empty($elements), 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
+    $this->assertEmpty($elements, 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
 
     $build = $node->body->view('default');
     $this->setRawContent($renderer->renderRoot($build));
     $elements = $this->xpath('//div[@data-quickedit-field-id="node/1/body/en/default"]');
-    $this->assertTrue(!empty($elements), 'Body with data-quickedit-field-id attribute found.');
+    $this->assertNotEmpty($elements, 'Body with data-quickedit-field-id attribute found.');
   }
 
 }
diff --git a/core/modules/search/tests/src/Functional/SearchBlockTest.php b/core/modules/search/tests/src/Functional/SearchBlockTest.php
index c1c18c7b919b..7cf659ba4948 100644
--- a/core/modules/search/tests/src/Functional/SearchBlockTest.php
+++ b/core/modules/search/tests/src/Functional/SearchBlockTest.php
@@ -64,7 +64,7 @@ public function testSearchFormBlock() {
     // Check that name attribute is not empty.
     $pattern = "//input[@type='submit' and @name='']";
     $elements = $this->xpath($pattern);
-    $this->assertTrue(empty($elements), 'The search input field does not have empty name attribute.');
+    $this->assertEmpty($elements, 'The search input field does not have empty name attribute.');
 
     // Test a normal search via the block form, from the front page.
     $terms = ['keys' => 'test'];
diff --git a/core/modules/search/tests/src/Kernel/SearchExcerptTest.php b/core/modules/search/tests/src/Kernel/SearchExcerptTest.php
index 7ef4044eab25..3d740bb586d2 100644
--- a/core/modules/search/tests/src/Kernel/SearchExcerptTest.php
+++ b/core/modules/search/tests/src/Kernel/SearchExcerptTest.php
@@ -64,7 +64,7 @@ public function testSearchExcerpt() {
     // 123456789 HTMLTest +123456789+&lsquo;  +&lsquo;  +&lsquo;  +&lsquo;  +12345678  &nbsp;&nbsp;  +&lsquo;  +&lsquo;  +&lsquo;   &lsquo;
     $text = "<div class=\"field field--name-body field--type-text-with-summary field--label-hidden\"><div class=\"field__items\"><div class=\"field__item even\" property=\"content:encoded\"><p>123456789 HTMLTest +123456789+‘  +‘  +‘  +‘  +12345678      +‘  +‘  +‘   ‘</p>\n</div></div></div> ";
     $result = $this->doSearchExcerpt('HTMLTest', $text);
-    $this->assertFalse(empty($result), 'Rendered Multi-byte HTML encodings are not corrupted in search excerpts');
+    $this->assertNotEmpty($result, 'Rendered Multi-byte HTML encodings are not corrupted in search excerpts');
   }
 
   /**
diff --git a/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php b/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php
index 4e064969f8fd..110fc1516f9f 100644
--- a/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php
+++ b/core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php
@@ -53,7 +53,7 @@ public function testNoJavaScript() {
   protected function assertNoJavaScript(): void {
     // Ensure drupalSettings is not set.
     $settings = $this->getDrupalSettings();
-    $this->assertTrue(empty($settings), 'drupalSettings is not set.');
+    $this->assertEmpty($settings, 'drupalSettings is not set.');
     $this->assertSession()->responseNotMatches('/\.js/');
   }
 
diff --git a/core/modules/system/tests/src/Functional/Form/FormTest.php b/core/modules/system/tests/src/Functional/Form/FormTest.php
index 7c4eddd2fd38..d1b00eea3650 100644
--- a/core/modules/system/tests/src/Functional/Form/FormTest.php
+++ b/core/modules/system/tests/src/Functional/Form/FormTest.php
@@ -147,7 +147,7 @@ public function testRequiredFields() {
             else {
               // Make sure there is *no* form error for this element. We're
               // not using assertEmpty() because the array key might not exist.
-              $this->assertTrue(empty($errors[$element]), "Optional '$type' field '$element' has no errors with empty input");
+              $this->assertArrayNotHasKey($element, $errors, "Optional '$type' field '$element' should have no errors with empty input.");
             }
           }
         }
diff --git a/core/modules/system/tests/src/Functional/Form/StorageTest.php b/core/modules/system/tests/src/Functional/Form/StorageTest.php
index 847a6b460899..385ca20392a8 100644
--- a/core/modules/system/tests/src/Functional/Form/StorageTest.php
+++ b/core/modules/system/tests/src/Functional/Form/StorageTest.php
@@ -211,8 +211,8 @@ public function testImmutableFormLegacyProtection() {
     $original = json_decode($response, TRUE);
     $this->assertEquals($original['form']['#build_id_old'], $build_id, 'Original build_id was recorded');
     $this->assertNotEquals($original['form']['#build_id'], $build_id, 'New build_id was generated');
-    $this->assertTrue(empty($original['form']['#poisoned']), 'Original form structure was preserved');
-    $this->assertTrue(empty($original['form_state']['poisoned']), 'Original form state was preserved');
+    $this->assertArrayNotHasKey('#poisoned', $original['form'], 'Original form structure was preserved');
+    $this->assertArrayNotHasKey('poisoned', $original['form_state'], 'Original form state was preserved');
   }
 
 }
diff --git a/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php b/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php
index f525f8644193..1f70d519533e 100644
--- a/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php
+++ b/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\system\Functional\Menu;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Url;
 
 /**
@@ -40,7 +39,7 @@ protected function assertMenuActiveTrail($tree, $last_active) {
         $i++;
       }
       $elements = $this->xpath($xpath);
-      $this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.');
+      $this->assertNotEmpty($elements, 'Active trail to current page should be visible in menu tree.');
 
       // Append prefix for active link asserted below.
       $xpath .= '/following-sibling::ul/descendant::';
@@ -57,10 +56,7 @@ protected function assertMenuActiveTrail($tree, $last_active) {
       ':title' => $active_link_title,
     ];
     $elements = $this->xpath($xpath, $args);
-    $this->assertTrue(!empty($elements), new FormattableMarkup('Active link %title was found in menu tree, including active trail links %tree.', [
-      '%title' => $active_link_title,
-      '%tree' => implode(' » ', $tree),
-    ]));
+    $this->assertNotEmpty($elements, sprintf('Active link %s should be visible in menu tree, including active trail links %s.', $active_link_title, implode(' » ', $tree)));
   }
 
 }
diff --git a/core/modules/system/tests/src/Functional/Session/SessionTest.php b/core/modules/system/tests/src/Functional/Session/SessionTest.php
index 10c8f55b4704..4b696ea2d5b8 100644
--- a/core/modules/system/tests/src/Functional/Session/SessionTest.php
+++ b/core/modules/system/tests/src/Functional/Session/SessionTest.php
@@ -60,7 +60,7 @@ public function testSessionSaveRegenerate() {
     $this->drupalGet('session-test/id');
     $matches = [];
     preg_match('/\s*session_id:(.*)\n/', $this->getSession()->getPage()->getContent(), $matches);
-    $this->assertTrue(!empty($matches[1]), 'Found session ID before logging in.');
+    $this->assertNotEmpty($matches[1], 'Found session ID before logging in.');
     $original_session = $matches[1];
 
     // We cannot use $this->drupalLogin($user); because we exit in
@@ -77,7 +77,7 @@ public function testSessionSaveRegenerate() {
     $this->drupalGet('session-test/id');
     $matches = [];
     preg_match('/\s*session_id:(.*)\n/', $this->getSession()->getPage()->getContent(), $matches);
-    $this->assertTrue(!empty($matches[1]), 'Found session ID after logging in.');
+    $this->assertNotEmpty($matches[1], 'Found session ID after logging in.');
     $this->assertNotSame($original_session, $matches[1], 'Session ID changed after login.');
   }
 
diff --git a/core/modules/system/tests/src/Functional/Theme/EngineTwigTest.php b/core/modules/system/tests/src/Functional/Theme/EngineTwigTest.php
index da8fe199b8bc..c358a92f74e4 100644
--- a/core/modules/system/tests/src/Functional/Theme/EngineTwigTest.php
+++ b/core/modules/system/tests/src/Functional/Theme/EngineTwigTest.php
@@ -69,7 +69,7 @@ public function testTwigUrlGenerator() {
 
     // Make sure we got something.
     $content = $this->getSession()->getPage()->getContent();
-    $this->assertFalse(empty($content), 'Page content is not empty');
+    $this->assertNotEmpty($content, 'Page content is not empty');
     foreach ($expected as $string) {
       $this->assertSession()->responseContains('<div>' . $string . '</div>');
     }
@@ -103,7 +103,7 @@ public function testTwigLinkGenerator() {
     $this->assertCacheContext('url.site');
 
     $content = $this->getSession()->getPage()->getContent();
-    $this->assertFalse(empty($content), 'Page content is not empty');
+    $this->assertNotEmpty($content, 'Page content is not empty');
     foreach ($expected as $string) {
       $this->assertSession()->responseContains('<div>' . $string . '</div>');
     }
@@ -122,7 +122,7 @@ public function testTwigUrlToString() {
     ];
 
     $content = $this->getSession()->getPage()->getContent();
-    $this->assertFalse(empty($content), 'Page content is not empty');
+    $this->assertNotEmpty($content, 'Page content is not empty');
     foreach ($expected as $string) {
       $this->assertSession()->responseContains('<div>' . $string . '</div>');
     }
diff --git a/core/modules/system/tests/src/Kernel/Action/ActionTest.php b/core/modules/system/tests/src/Kernel/Action/ActionTest.php
index 2dac37555cec..becf628e64b7 100644
--- a/core/modules/system/tests/src/Kernel/Action/ActionTest.php
+++ b/core/modules/system/tests/src/Kernel/Action/ActionTest.php
@@ -45,13 +45,13 @@ public function testOperations() {
     $definitions = $this->actionManager->getDefinitions();
     // Verify that the action definitions are found.
     $this->assertGreaterThan(1, count($definitions));
-    $this->assertTrue(!empty($definitions['action_test_no_type']), 'The test action is among the definitions found.');
+    $this->assertNotEmpty($definitions['action_test_no_type'], 'The test action is among the definitions found.');
 
     $definition = $this->actionManager->getDefinition('action_test_no_type');
-    $this->assertTrue(!empty($definition), 'The test action definition is found.');
+    $this->assertNotEmpty($definition, 'The test action definition is found.');
 
     $definitions = $this->actionManager->getDefinitionsByType('user');
-    $this->assertTrue(empty($definitions['action_test_no_type']), 'An action with no type is not found.');
+    $this->assertArrayNotHasKey('action_test_no_type', $definitions, 'An action with no type is not found.');
 
     // Create an instance of the 'save entity' action.
     $action = $this->actionManager->createInstance('action_test_save_entity');
diff --git a/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php
index bab37c3981dd..a0e5bc68749f 100644
--- a/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php
+++ b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php
@@ -113,7 +113,7 @@ public function testReferenceablesWithNoLabelKey($match, $match_operator, $limit
 
     // Number of returned items.
     if (empty($count_limited)) {
-      $this->assertTrue(empty($referenceables[$this->bundle]));
+      $this->assertArrayNotHasKey($this->bundle, $referenceables);
     }
     else {
       $this->assertCount($count_limited, $referenceables[$this->bundle]);
diff --git a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
index f672a4c7cc20..42278b772ec0 100644
--- a/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
+++ b/core/modules/system/tests/src/Kernel/Extension/ModuleHandlerTest.php
@@ -301,7 +301,7 @@ public function testModuleMetaData() {
     // Generate the list of available modules.
     $modules = $this->container->get('extension.list.module')->getList();
     // Check that the mtime field exists for the system module.
-    $this->assertTrue(!empty($modules['system']->info['mtime']), 'The system.info.yml file modification time field is present.');
+    $this->assertNotEmpty($modules['system']->info['mtime'], 'The system.info.yml file modification time field is present.');
     // Use 0 if mtime isn't present, to avoid an array index notice.
     $test_mtime = !empty($modules['system']->info['mtime']) ? $modules['system']->info['mtime'] : 0;
     // Ensure the mtime field contains a number that is greater than zero.
@@ -333,7 +333,7 @@ public function testThemeMetaData() {
     // Generate the list of available themes.
     $themes = \Drupal::service('theme_handler')->rebuildThemeData();
     // Check that the mtime field exists for the bartik theme.
-    $this->assertTrue(!empty($themes['bartik']->info['mtime']), 'The bartik.info.yml file modification time field is present.');
+    $this->assertNotEmpty($themes['bartik']->info['mtime'], 'The bartik.info.yml file modification time field is present.');
     // Use 0 if mtime isn't present, to avoid an array index notice.
     $test_mtime = !empty($themes['bartik']->info['mtime']) ? $themes['bartik']->info['mtime'] : 0;
     // Ensure the mtime field contains a number that is greater than zero.
diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
index 30d27000f3e1..85b25ffe9b65 100644
--- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTermIndentationTest.php
@@ -97,7 +97,7 @@ public function testTermIndentation() {
     // Check explicitly that term 2 has no parents.
     \Drupal::entityTypeManager()->getStorage('taxonomy_term')->resetCache();
     $parents = $taxonomy_storage->loadParents($term2->id());
-    $this->assertTrue(empty($parents), 'Term 2 has no parents now');
+    $this->assertEmpty($parents, 'Term 2 has no parents now');
   }
 
 }
diff --git a/core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php b/core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php
index ab39d7babc96..f64a0af32f71 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermAutocompleteTest.php
@@ -172,7 +172,7 @@ public function testAutocompleteCountResults() {
       $this->autocompleteUrl,
       ['query' => ['q' => 'zzz']]
     );
-    $this->assertTrue(empty($data), 'Autocomplete returned no results');
+    $this->assertEmpty($data, 'Autocomplete returned no results');
 
     // Test that only one matching term found, when only one matches.
     $data = $this->drupalGetJson(
diff --git a/core/modules/taxonomy/tests/src/Functional/TermTest.php b/core/modules/taxonomy/tests/src/Functional/TermTest.php
index 99d4a1e74957..4ec62e5bdfa3 100644
--- a/core/modules/taxonomy/tests/src/Functional/TermTest.php
+++ b/core/modules/taxonomy/tests/src/Functional/TermTest.php
@@ -275,7 +275,7 @@ public function testNodeTermCreationAndDeletion() {
       $this->assertSession()->pageTextContains($term);
     }
     $tree = $this->container->get('entity_type.manager')->getStorage('taxonomy_term')->loadTree($this->vocabulary->id());
-    $this->assertTrue(empty($tree), 'The terms are not created on preview.');
+    $this->assertEmpty($tree, 'The terms are not created on preview.');
 
     // Save, creating the terms.
     $this->drupalGet('node/add/article');
diff --git a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php
index 3f85b2f81940..29e43b72bf56 100644
--- a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php
@@ -38,7 +38,7 @@ public function testTermDelete() {
     // Delete a valid term.
     $valid_term->delete();
     $terms = \Drupal::entityTypeManager()->getStorage('taxonomy_term')->loadByProperties(['vid' => $vocabulary->id()]);
-    $this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
+    $this->assertEmpty($terms, 'Vocabulary is empty after deletion');
   }
 
   /**
@@ -57,12 +57,12 @@ public function testMultipleParentDelete() {
     $term_storage = $this->container->get('entity_type.manager')->getStorage('taxonomy_term');
     $term_storage->resetCache([$child_term_id]);
     $child_term = Term::load($child_term_id);
-    $this->assertTrue(!empty($child_term), 'Child term is not deleted if only one of its parents is removed.');
+    $this->assertNotEmpty($child_term, 'Child term is not deleted if only one of its parents is removed.');
 
     $parent_term2->delete();
     $term_storage->resetCache([$child_term_id]);
     $child_term = Term::load($child_term_id);
-    $this->assertTrue(empty($child_term), 'Child term is deleted if all of its parents are removed.');
+    $this->assertEmpty($child_term, 'Child term is deleted if all of its parents are removed.');
   }
 
   /**
@@ -161,11 +161,11 @@ public function testTermPreview() {
     // Confirm we can get the view of unsaved term.
     $render_array = $entity_manager->getViewBuilder('taxonomy_term')
       ->view($term);
-    $this->assertTrue(!empty($render_array), 'Term view builder is built.');
+    $this->assertNotEmpty($render_array, 'Term view builder is built.');
 
     // Confirm we can render said view.
     $rendered = \Drupal::service('renderer')->renderPlain($render_array);
-    $this->assertTrue(!empty(trim($rendered)), 'Term is able to be rendered.');
+    $this->assertNotEmpty(trim($rendered), 'Term is able to be rendered.');
   }
 
 }
diff --git a/core/modules/text/tests/src/Kernel/TextSummaryTest.php b/core/modules/text/tests/src/Kernel/TextSummaryTest.php
index 5537e74acc0c..acac900bfcea 100644
--- a/core/modules/text/tests/src/Kernel/TextSummaryTest.php
+++ b/core/modules/text/tests/src/Kernel/TextSummaryTest.php
@@ -297,8 +297,8 @@ public function testRequiredSummary() {
       'test_textwithsummary' => ['value' => $this->randomMachineName()],
     ]);
     $form = \Drupal::service('entity.form_builder')->getForm($entity);
-    $this->assertTrue(!empty($form['test_textwithsummary']['widget'][0]['summary']), 'Summary field is shown');
-    $this->assertTrue(!empty($form['test_textwithsummary']['widget'][0]['summary']['#required']), 'Summary field is required');
+    $this->assertNotEmpty($form['test_textwithsummary']['widget'][0]['summary'], 'Summary field is shown');
+    $this->assertNotEmpty($form['test_textwithsummary']['widget'][0]['summary']['#required'], 'Summary field is required');
 
     // Test validation.
     /** @var \Symfony\Component\Validator\ConstraintViolation[] $violations */
diff --git a/core/modules/tour/tests/src/Functional/TourTestBase.php b/core/modules/tour/tests/src/Functional/TourTestBase.php
index 23f2190f4237..21b6f3fe169b 100644
--- a/core/modules/tour/tests/src/Functional/TourTestBase.php
+++ b/core/modules/tour/tests/src/Functional/TourTestBase.php
@@ -59,7 +59,7 @@ public function assertTourTips($tips = []) {
         }
         elseif (!empty($tip['data-class'])) {
           $elements = $this->getSession()->getPage()->findAll('css', '.' . $tip['data-class']);
-          $this->assertFalse(empty($elements), new FormattableMarkup('Found corresponding page element for tour tip with class .%data-class', ['%data-class' => $tip['data-class']]));
+          $this->assertNotEmpty($elements, sprintf("Page element for tour tip with class .%s should be present", $tip['data-class']));
         }
         else {
           // It's a modal.
diff --git a/core/modules/update/tests/src/Functional/UpdateContribTest.php b/core/modules/update/tests/src/Functional/UpdateContribTest.php
index 4a55f9d44027..f00934dd9fd1 100644
--- a/core/modules/update/tests/src/Functional/UpdateContribTest.php
+++ b/core/modules/update/tests/src/Functional/UpdateContribTest.php
@@ -442,7 +442,7 @@ public function testUpdateHiddenBaseTheme() {
     $project_info = new ProjectInfo();
     $project_info->processInfoList($projects, $theme_data, 'theme', TRUE);
 
-    $this->assertTrue(!empty($projects['update_test_basetheme']), 'Valid base theme (update_test_basetheme) was found.');
+    $this->assertNotEmpty($projects['update_test_basetheme'], 'Valid base theme (update_test_basetheme) was found.');
   }
 
   /**
diff --git a/core/modules/user/tests/src/Functional/RestRegisterUserTest.php b/core/modules/user/tests/src/Functional/RestRegisterUserTest.php
index 25d92624972b..0dafd8a27ea2 100644
--- a/core/modules/user/tests/src/Functional/RestRegisterUserTest.php
+++ b/core/modules/user/tests/src/Functional/RestRegisterUserTest.php
@@ -81,7 +81,7 @@ public function testRegisterUser() {
     $config->save();
     $user = $this->registerUser('Palmer.Eldritch');
     $this->assertFalse($user->isBlocked());
-    $this->assertFalse(empty($user->getPassword()));
+    $this->assertNotEmpty($user->getPassword());
     $email_count = count($this->drupalGetMails());
 
     $this->assertEquals(0, $email_count);
@@ -103,7 +103,7 @@ public function testRegisterUser() {
     $config->save();
     $name = 'Jason.Taverner';
     $user = $this->registerUser($name, FALSE);
-    $this->assertTrue(empty($user->getPassword()));
+    $this->assertEmpty($user->getPassword());
     $this->assertTrue($user->isBlocked());
     $this->resetAll();
 
@@ -116,7 +116,7 @@ public function testRegisterUser() {
     $name = 'Argaven';
     $user = $this->registerUser($name);
     $this->resetAll();
-    $this->assertFalse(empty($user->getPassword()));
+    $this->assertNotEmpty($user->getPassword());
     $this->assertTrue($user->isBlocked());
     $this->assertMailString('body', 'Your application for an account is', 2);
     $this->assertMailString('body', 'Argaven has applied for an account', 2);
@@ -128,7 +128,7 @@ public function testRegisterUser() {
     $name = 'Bob.Arctor';
     $user = $this->registerUser($name, FALSE);
     $this->resetAll();
-    $this->assertTrue(empty($user->getPassword()));
+    $this->assertEmpty($user->getPassword());
     $this->assertTrue($user->isBlocked());
 
     $this->assertMailString('body', 'Your application for an account is', 2);
@@ -210,7 +210,7 @@ protected function registerUser($name, $include_password = TRUE, $include_email
     $response = $this->registerRequest($name, $include_password, $include_email);
     $this->assertResourceResponse(200, FALSE, $response);
     $user = user_load_by_name($name);
-    $this->assertFalse(empty($user), 'User was create as expected');
+    $this->assertNotEmpty($user, 'User was create as expected');
     return $user;
   }
 
diff --git a/core/modules/user/tests/src/Functional/UserCancelTest.php b/core/modules/user/tests/src/Functional/UserCancelTest.php
index 897113f406e4..6ce17ab97430 100644
--- a/core/modules/user/tests/src/Functional/UserCancelTest.php
+++ b/core/modules/user/tests/src/Functional/UserCancelTest.php
@@ -662,7 +662,7 @@ public function testUserDeleteWithContentAndNodeAccess() {
     $node = $this->drupalCreateNode(['type' => 'page', 'uid' => $account->id()]);
     $account->delete();
     $load2 = \Drupal::entityTypeManager()->getStorage('node')->load($node->id());
-    $this->assertTrue(empty($load2));
+    $this->assertEmpty($load2);
   }
 
 }
diff --git a/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php b/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php
index d443e3ba2770..e40fbb959c59 100644
--- a/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php
+++ b/core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php
@@ -138,7 +138,7 @@ protected function assertViewsCacheTagsFromStaticRenderArray(ViewExecutable $vie
 
     $render_cache_item = $render_cache->get($original);
     if ($views_caching_is_enabled) {
-      $this->assertTrue(!empty($render_cache_item), 'Render cache item found.');
+      $this->assertNotEmpty($render_cache_item, 'Render cache item found.');
       if ($render_cache_item) {
         $this->assertEqualsCanonicalizing($expected_render_array_cache_tags, $render_cache_item['#cache']['tags']);
       }
diff --git a/core/modules/views/tests/src/Functional/Handler/HandlerTest.php b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
index 2ac51567d82e..dde6c344f9ba 100644
--- a/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
+++ b/core/modules/views/tests/src/Functional/Handler/HandlerTest.php
@@ -304,7 +304,7 @@ public function testSetRelationship() {
 
     $field->options['relationship'] = 'valid_relationship';
     $field->setRelationship();
-    $this->assertFalse(!empty($field->relationship), 'Make sure that the relationship alias was not set without building a views query before.');
+    $this->assertEmpty($field->relationship, 'Make sure that the relationship alias was not set without building a views query before.');
 
     // Remove the invalid relationship.
     unset($view->relationship['broken_relationship']);
diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
index 8eea7fb9faa6..21c3ad29be7a 100644
--- a/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayFeedTest.php
@@ -176,7 +176,7 @@ public function testDisabledFeed() {
     // Ensure there is no link rel present on the page.
     $this->drupalGet('/test-attached-disabled');
     $result = $this->xpath('//link[@rel="alternate"]');
-    $this->assertTrue(empty($result), 'Page display does not contain a feed header.');
+    $this->assertEmpty($result, 'Page display does not contain a feed header.');
 
     // Ensure the feed attachment returns 'Not found'.
     $this->drupalGet('/test-attached-disabled.xml');
diff --git a/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
index 087d21a5b695..5769c697d1fd 100644
--- a/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/DisplayTest.php
@@ -179,14 +179,14 @@ public function testReadMoreNoDisplay() {
     $view = Views::getView('test_display_more');
     // Confirm that the view validates when there is a page display.
     $errors = $view->validate();
-    $this->assertTrue(empty($errors), 'More link validation has no errors.');
+    $this->assertEmpty($errors, 'More link validation has no errors.');
 
     // Confirm that the view does not validate when the page display is disabled.
     $view->setDisplay('page_1');
     $view->display_handler->setOption('enabled', FALSE);
     $view->setDisplay('default');
     $errors = $view->validate();
-    $this->assertTrue(!empty($errors), 'More link validation has some errors.');
+    $this->assertNotEmpty($errors, 'More link validation has some errors.');
     $this->assertEquals('Display "Default" uses a "more" link but there are no displays it can link to. You need to specify a custom URL.', $errors['default'][0], 'More link validation has the right error.');
 
     // Confirm that the view does not validate when the page display does not exist.
@@ -194,7 +194,7 @@ public function testReadMoreNoDisplay() {
     $view->setDisplay('default');
     $view->display_handler->setOption('use_more', 1);
     $errors = $view->validate();
-    $this->assertTrue(!empty($errors), 'More link validation has some errors.');
+    $this->assertNotEmpty($errors, 'More link validation has some errors.');
     $this->assertEquals('Display "Default" uses a "more" link but there are no displays it can link to. You need to specify a custom URL.', $errors['default'][0], 'More link validation has the right error.');
   }
 
@@ -352,7 +352,7 @@ public function testMissingRelationship() {
     $view->removeHandler('default', 'relationship', 'uid_1');
     $errors = $view->validate();
     // Check that no error message is shown.
-    $this->assertTrue(empty($errors['default']), 'No errors found when removing unused relationship.');
+    $this->assertArrayNotHasKey('default', $errors, 'No errors found when removing unused relationship.');
 
     // Unset cached relationships (see DisplayPluginBase::getHandlers())
     unset($view->display_handler->handlers['relationship']);
diff --git a/core/modules/views/tests/src/Functional/Plugin/FilterTest.php b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
index c1a933d83d4d..8283e14f5af7 100644
--- a/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
+++ b/core/modules/views/tests/src/Functional/Plugin/FilterTest.php
@@ -81,7 +81,7 @@ public function testFilterQuery() {
     $this->executeView($view);
 
     // Make sure the query have where data.
-    $this->assertTrue(!empty($view->query->where));
+    $this->assertNotEmpty($view->query->where);
 
     // Check the data added.
     $where = $view->query->where;
diff --git a/core/modules/views/tests/src/Functional/Wizard/BasicTest.php b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php
index 75812cecf54d..6486e6c4e07d 100644
--- a/core/modules/views/tests/src/Functional/Wizard/BasicTest.php
+++ b/core/modules/views/tests/src/Functional/Wizard/BasicTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests\views\Functional\Wizard;
 
 use Drupal\Component\Serialization\Json;
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Url;
 use Drupal\views\Views;
 
@@ -221,7 +220,7 @@ public function testWizardDefaultValues() {
 
     foreach ($displays as $display) {
       foreach (['query', 'exposed_form', 'pager', 'style', 'row'] as $type) {
-        $this->assertFalse(empty($display['display_options'][$type]['options']), new FormattableMarkup('Default options found for @plugin.', ['@plugin' => $type]));
+        $this->assertNotEmpty($display['display_options'][$type]['options'], "There should be default options available for '$type'.");
       }
     }
   }
diff --git a/core/modules/views/tests/src/Functional/Wizard/PagerTest.php b/core/modules/views/tests/src/Functional/Wizard/PagerTest.php
index 90945038bcaf..fa8355a7d060 100644
--- a/core/modules/views/tests/src/Functional/Wizard/PagerTest.php
+++ b/core/modules/views/tests/src/Functional/Wizard/PagerTest.php
@@ -33,14 +33,14 @@ public function testPager() {
     // This technique for finding the existence of a pager
     // matches that used in Drupal\views_ui\Tests\PreviewTest.php.
     $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
-    $this->assertTrue(!empty($elements), 'Full pager found.');
+    $this->assertNotEmpty($elements, 'Full pager found.');
 
     // Make a View that does not have a pager.
     $path_with_no_pager = 'test-view-without-pager';
     $this->createViewAtPath($path_with_no_pager, FALSE);
     $this->drupalGet($path_with_no_pager);
     $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
-    $this->assertTrue(empty($elements), 'Full pager not found.');
+    $this->assertEmpty($elements, 'Full pager not found.');
   }
 
   /**
diff --git a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
index 9d1d3befe6d8..38b9687cdf50 100644
--- a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
+++ b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FieldTest.php
@@ -85,7 +85,7 @@ public function testFormatterChanging() {
     $web_assert->assertWaitOnAjaxRequest();
     $page->fillField('options[settings][trim_length]', '700');
     $apply_button = $page->find('css', '.views-ui-dialog button.button--primary');
-    $this->assertTrue(!empty($apply_button));
+    $this->assertNotEmpty($apply_button);
     $apply_button->press();
     $web_assert->assertWaitOnAjaxRequest();
 
diff --git a/core/modules/views/tests/src/Kernel/FieldApiDataTest.php b/core/modules/views/tests/src/Kernel/FieldApiDataTest.php
index 1df711aaeb29..c3c178707d4b 100644
--- a/core/modules/views/tests/src/Kernel/FieldApiDataTest.php
+++ b/core/modules/views/tests/src/Kernel/FieldApiDataTest.php
@@ -139,7 +139,7 @@ public function testViewsData() {
     // Test click sortable for string field.
     $this->assertTrue($data[$current_table][$field_storage_string->getName()]['field']['click sortable']);
     // Click sort should only be on the primary field.
-    $this->assertTrue(empty($data[$revision_table][$field_storage_string->getName()]['field']['click sortable']));
+    $this->assertArrayNotHasKey($field_storage_string->getName(), $data[$revision_table]);
     // Test click sortable for long text field.
     $data_long = $this->getViewsData('field_string_long');
     $current_table_long = $table_mapping->getDedicatedDataTableName($field_storage_string_long);
diff --git a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php
index 6f488ff6fed8..f81def4de0d4 100644
--- a/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php
+++ b/core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php
@@ -71,7 +71,7 @@ public function testEntityAreaData() {
 
     // Test that all expected entity types have data.
     foreach (array_keys($expected_entities) as $entity) {
-      $this->assertTrue(!empty($data['entity_' . $entity]), new FormattableMarkup('Views entity area data found for @entity', ['@entity' => $entity]));
+      $this->assertNotEmpty($data['entity_' . $entity], "Views entity '$entity' should have a data area.");
       // Test that entity_type is set correctly in the area data.
       $this->assertEquals($data['entity_' . $entity]['area']['entity_type'], $entity, new FormattableMarkup('Correct entity_type set for @entity', ['@entity' => $entity]));
     }
@@ -82,7 +82,7 @@ public function testEntityAreaData() {
 
     // Test that no configuration entity types have data.
     foreach (array_keys($expected_entities) as $entity) {
-      $this->assertTrue(empty($data['entity_' . $entity]), new FormattableMarkup('Views config entity area data not found for @entity', ['@entity' => $entity]));
+      $this->assertArrayNotHasKey('entity_' . $entity, $data, "Views config entity '$entity' should not have a data area.");
     }
   }
 
diff --git a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php
index b3630ce9de50..7bab5e5c5069 100644
--- a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php
+++ b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php
@@ -296,7 +296,7 @@ public function testHeaderStorage() {
     // Note: views_test_data_views_pre_render() adds some cache tags.
     $this->assertEquals(['config:views.view.test_cache_header_storage', 'views_test_data:1'], $output['#cache']['tags']);
     $this->assertEquals(['non-existing-placeholder-just-for-testing-purposes' => ['#lazy_builder' => ['Drupal\views_test_data\Controller\ViewsTestDataController::placeholderLazyBuilder', ['bar']]]], $output['#attached']['placeholders']);
-    $this->assertFalse(!empty($view->build_info['pre_render_called']), 'Make sure hook_views_pre_render is not called for the cached view.');
+    $this->assertArrayNotHasKey('pre_render_called', $view->build_info, 'Make sure hook_views_pre_render is not called for the cached view.');
   }
 
   /**
diff --git a/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php b/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php
index ba1a7a4da22b..841c20441872 100644
--- a/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php
+++ b/core/modules/views/tests/src/Kernel/Plugin/DisplayPageTest.php
@@ -196,7 +196,7 @@ public function testReadMore() {
     $output = $renderer->renderRoot($output);
     $this->setRawContent($output);
     $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
-    $this->assertTrue(empty($result), 'The more link is not shown.');
+    $this->assertEmpty($result, 'The more link is not shown.');
 
     $view = Views::getView('test_display_more');
     $view->setDisplay();
@@ -214,7 +214,7 @@ public function testReadMore() {
     $output = $renderer->renderRoot($output);
     $this->setRawContent($output);
     $result = $this->xpath('//div[@class=:class]/a', [':class' => 'more-link']);
-    $this->assertTrue(empty($result), 'The more link is not shown when view has more records.');
+    $this->assertEmpty($result, 'The more link is not shown when view has more records.');
 
     // Test the default value of use_more_always.
     $view = View::create()->getExecutable();
diff --git a/core/modules/views/tests/src/Kernel/PluginInstanceTest.php b/core/modules/views/tests/src/Kernel/PluginInstanceTest.php
index 315fae720372..d5d1dd6004d6 100644
--- a/core/modules/views/tests/src/Kernel/PluginInstanceTest.php
+++ b/core/modules/views/tests/src/Kernel/PluginInstanceTest.php
@@ -75,7 +75,7 @@ public function testPluginData() {
 
     // Tests that the plugin list has not missed any types.
     $diff = array_diff(array_keys($this->definitions), $this->pluginTypes);
-    $this->assertTrue(empty($diff), 'All plugins were found and matched.');
+    $this->assertEmpty($diff, 'All plugins were found and matched.');
   }
 
   /**
diff --git a/core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php b/core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php
index de5e12ef28d3..651310dd9e44 100644
--- a/core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php
+++ b/core/modules/views/tests/src/Unit/Plugin/Derivative/ViewsLocalTaskTest.php
@@ -159,7 +159,7 @@ public function testGetDerivativeDefinitionsWithLocalTask() {
     $this->assertEquals(12, $definitions['view.example_view.page_1']['weight']);
     $this->assertEquals('Example title', $definitions['view.example_view.page_1']['title']);
     $this->assertEquals($this->baseDefinition['class'], $definitions['view.example_view.page_1']['class']);
-    $this->assertTrue(empty($definitions['view.example_view.page_1']['base_route']));
+    $this->assertArrayNotHasKey('base_route', $definitions['view.example_view.page_1']);
   }
 
   /**
diff --git a/core/modules/views/tests/src/Unit/PluginTypeListTest.php b/core/modules/views/tests/src/Unit/PluginTypeListTest.php
index 29da6b3aff4d..ee84e5312717 100644
--- a/core/modules/views/tests/src/Unit/PluginTypeListTest.php
+++ b/core/modules/views/tests/src/Unit/PluginTypeListTest.php
@@ -39,7 +39,7 @@ public function testPluginList() {
     ];
 
     $diff = array_diff($plugin_list, ViewExecutable::getPluginTypes());
-    $this->assertTrue(empty($diff), 'The plugin list is correct');
+    $this->assertEmpty($diff);
   }
 
 }
diff --git a/core/modules/views_ui/tests/src/Functional/ViewEditTest.php b/core/modules/views_ui/tests/src/Functional/ViewEditTest.php
index 6be6c457802e..722a2a332c66 100644
--- a/core/modules/views_ui/tests/src/Functional/ViewEditTest.php
+++ b/core/modules/views_ui/tests/src/Functional/ViewEditTest.php
@@ -67,7 +67,7 @@ public function testOtherOptions() {
     $this->submitForm([], 'Save');
     $view = \Drupal::entityTypeManager()->getStorage('view')->load('test_view');
     $displays = $view->get('display');
-    $this->assertTrue(!empty($displays['test_1']), 'Display data found for new display ID key.');
+    $this->assertNotEmpty($displays['test_1'], 'Display data found for new display ID key.');
     $this->assertSame('test_1', $displays['test_1']['id'], 'New display ID matches the display ID key.');
     $this->assertArrayNotHasKey('attachment_1', $displays);
 
diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php
index 0c41a2c6843f..b2523408083a 100644
--- a/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php
+++ b/core/modules/views_ui/tests/src/FunctionalJavascript/PreviewTest.php
@@ -134,7 +134,7 @@ public function testPreviewWithPagersUI() {
 
     // Test that the pager is present and rendered.
     $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
-    $this->assertTrue(!empty($elements), 'Full pager found.');
+    $this->assertNotEmpty($elements, 'Full pager found.');
 
     // Verify elements and links to pages.
     // We expect to find 5 elements: current page == 1, links to pages 2 and
@@ -160,7 +160,7 @@ public function testPreviewWithPagersUI() {
 
     // Test that the pager is present and rendered.
     $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
-    $this->assertTrue(!empty($elements), 'Full pager found.');
+    $this->assertNotEmpty($elements, 'Full pager found.');
 
     // Verify elements and links to pages.
     // We expect to find 7 elements: links to '<< first' and '< previous'
@@ -192,7 +192,7 @@ public function testPreviewWithPagersUI() {
 
     // Test that the pager is present and rendered.
     $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
-    $this->assertTrue(!empty($elements), 'Mini pager found.');
+    $this->assertNotEmpty($elements, 'Mini pager found.');
 
     // Verify elements and links to pages.
     // We expect to find current pages element with no link, next page element
@@ -208,7 +208,7 @@ public function testPreviewWithPagersUI() {
 
     // Test that the pager is present and rendered.
     $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']);
-    $this->assertTrue(!empty($elements), 'Mini pager found.');
+    $this->assertNotEmpty($elements, 'Mini pager found.');
 
     // Verify elements and links to pages.
     // We expect to find 3 elements: previous page with a link, current
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php
index 0036e88a8f0d..de6cd41365a4 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/Ajax/DialogTest.php
@@ -173,7 +173,7 @@ public function testDialog() {
     // Check we get a chunk of the code, we can't test the whole form as form
     // build id and token with be different.
     $contact_form = $this->xpath("//form[@id='contact-form-add-form']");
-    $this->assertTrue(!empty($contact_form), 'Non-JS entity form page present.');
+    $this->assertNotEmpty($contact_form, 'Non-JS entity form page present.');
 
     // Reset: Return to the dialog links page.
     $this->drupalGet('ajax-test/dialog');
diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
index 76cf0ecbdc6f..0d3cabac0420 100644
--- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
+++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php
@@ -375,7 +375,7 @@ public function testGetMultiple() {
     $cids = ['key:key' => $long_cid];
     $return = $backend->getMultiple($cids);
     $this->assertEquals(300, $return[$long_cid]->data);
-    $this->assertTrue(empty($cids));
+    $this->assertEmpty($cids);
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php
index 9994e9db6fde..6b0ba0ae1615 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigCRUDTest.php
@@ -3,7 +3,6 @@
 namespace Drupal\KernelTests\Core\Config;
 
 use Drupal\Component\Utility\Crypt;
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Config\Config;
 use Drupal\Core\Config\ConfigNameException;
 use Drupal\Core\Config\ConfigValueException;
@@ -222,9 +221,7 @@ public function testNameValidation() {
         unset($test_characters[$i]);
       }
     }
-    $this->assertTrue(empty($test_characters), new FormattableMarkup('Expected ConfigNameException was thrown for all invalid name characters: @characters', [
-      '@characters' => implode(' ', $characters),
-    ]));
+    $this->assertEmpty($test_characters, sprintf('Expected ConfigNameException was thrown for all invalid name characters: %s', implode(' ', $characters)));
 
     // Verify that a valid config object name can be saved.
     $name = 'namespace.object';
diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php
index 22e610afec23..e53b30472ec1 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigDependencyTest.php
@@ -67,7 +67,7 @@ public function testDependencyManagement() {
     // the dependencies array.
     $raw_config = $this->config('config_test.dynamic.entity1');
     $root_module_dependencies = $raw_config->get('dependencies.module');
-    $this->assertTrue(empty($root_module_dependencies), 'Node module is not written to the root dependencies array as it is enforced.');
+    $this->assertEmpty($root_module_dependencies, 'Node module is not written to the root dependencies array as it is enforced.');
 
     // Create additional entities to test dependencies on config entities.
     $entity2 = $storage->create(['id' => 'entity2', 'dependencies' => ['enforced' => ['config' => [$entity1->getConfigDependencyName()]]]]);
@@ -516,8 +516,8 @@ public function testConfigEntityDelete() {
     // \Drupal\Core\Config\ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval().
     $config_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval('config', [$entity1->getConfigDependencyName()]);
     $this->assertEquals($entity2->uuid(), reset($config_entities['delete'])->uuid(), 'Entity 2 will be deleted.');
-    $this->assertTrue(empty($config_entities['update']), 'No dependent configuration entities will be updated.');
-    $this->assertTrue(empty($config_entities['unchanged']), 'No dependent configuration entities will be unchanged.');
+    $this->assertEmpty($config_entities['update'], 'No dependent configuration entities will be updated.');
+    $this->assertEmpty($config_entities['unchanged'], 'No dependent configuration entities will be unchanged.');
 
     // Test that doing a delete of entity1 deletes entity2 since it is dependent
     // on entity1.
@@ -568,7 +568,7 @@ public function testConfigEntityDelete() {
     // Do a dry run using
     // \Drupal\Core\Config\ConfigManager::getConfigEntitiesToChangeOnDependencyRemoval().
     $config_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval('config', [$entity1->getConfigDependencyName()]);
-    $this->assertTrue(empty($config_entities['delete']), 'No dependent configuration entities will be deleted.');
+    $this->assertEmpty($config_entities['delete'], 'No dependent configuration entities will be deleted.');
     $this->assertEquals($entity2->uuid(), reset($config_entities['update'])->uuid(), 'Entity 2 will be updated.');
     $this->assertEquals($entity3->uuid(), reset($config_entities['unchanged'])->uuid(), 'Entity 3 is not changed.');
 
@@ -634,8 +634,8 @@ public function testContentEntityDelete() {
     $config_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval('content', [$content_entity->getConfigDependencyName()]);
     $this->assertEquals($entity1->uuid(), $config_entities['delete'][1]->uuid(), 'Entity 1 will be deleted.');
     $this->assertEquals($entity2->uuid(), $config_entities['delete'][0]->uuid(), 'Entity 2 will be deleted.');
-    $this->assertTrue(empty($config_entities['update']), 'No dependencies of the content entity will be updated.');
-    $this->assertTrue(empty($config_entities['unchanged']), 'No dependencies of the content entity will be unchanged.');
+    $this->assertEmpty($config_entities['update'], 'No dependencies of the content entity will be updated.');
+    $this->assertEmpty($config_entities['unchanged'], 'No dependencies of the content entity will be unchanged.');
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php
index a07a3fd7cf63..602ca3624e3f 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigSchemaTest.php
@@ -319,7 +319,7 @@ public function testSchemaData() {
     $this->assertInstanceOf(StringInterface::class, $property);
     $this->assertEquals('/user/login', $property->getValue(), 'Got the right value for page.front data.');
     $definition = $property->getDataDefinition();
-    $this->assertTrue(empty($definition['translatable']), 'Got the right translatability setting for page.front data.');
+    $this->assertEmpty($definition['translatable'], 'Got the right translatability setting for page.front data.');
 
     // Check nested array of properties.
     $list = $meta->get('page')->getElements();
diff --git a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
index 678e0eee91ad..4d07af2a25a5 100644
--- a/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php
@@ -105,8 +105,8 @@ public function testSchema() {
           $string_ascii_check = ($column->Collation == 'ascii_general_ci');
         }
       }
-      $this->assertTrue(!empty($string_check), 'string field has the right collation.');
-      $this->assertTrue(!empty($string_ascii_check), 'ASCII string field has the right collation.');
+      $this->assertNotEmpty($string_check, 'string field has the right collation.');
+      $this->assertNotEmpty($string_ascii_check, 'ASCII string field has the right collation.');
     }
 
     // An insert without a value for the column 'test_table' should fail.
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php
index ccc1f537affe..e1f3497cba5d 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityApiTest.php
@@ -94,7 +94,7 @@ protected function assertCRUD(string $entity_type, UserInterface $user1): void {
     $storage->delete($entities);
 
     $all = $storage->loadMultiple();
-    $this->assertTrue(empty($all), new FormattableMarkup('%entity_type: Deleted all entities.', ['%entity_type' => $entity_type]));
+    $this->assertEmpty($all, "All entities of type '$entity_type' should have been deleted.");
 
     // Verify that all data got deleted.
     $definition = \Drupal::entityTypeManager()->getDefinition($entity_type);
@@ -124,7 +124,7 @@ protected function assertCRUD(string $entity_type, UserInterface $user1): void {
 
     // Verify that entities got deleted.
     $all = $storage->loadMultiple();
-    $this->assertTrue(empty($all), new FormattableMarkup('%entity_type: Deleted all entities.', ['%entity_type' => $entity_type]));
+    $this->assertEmpty($all, "All entities of type '$entity_type' should have been deleted.");
 
     // Verify that all data got deleted from the tables.
     $definition = \Drupal::entityTypeManager()->getDefinition($entity_type);
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
index f0f5211a0bda..e55211d347d0 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php
@@ -195,14 +195,14 @@ protected function doTestReadWrite($entity_type) {
     unset($entity->name->value);
     $this->assertFalse(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type]));
     $this->assertFalse(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not set.', ['%entity_type' => $entity_type]));
-    $this->assertTrue(empty($entity->name->value), new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
-    $this->assertTrue(empty($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
+    $this->assertEmpty($entity->name->value, new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
+    $this->assertEmpty($entity->name[0]->value, new FormattableMarkup('%entity_type: Name is empty.', ['%entity_type' => $entity_type]));
 
     $entity->name->value = 'a value';
     $this->assertTrue(isset($entity->name->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type]));
     $this->assertTrue(isset($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is set.', ['%entity_type' => $entity_type]));
-    $this->assertFalse(empty($entity->name->value), new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
-    $this->assertFalse(empty($entity->name[0]->value), new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
+    $this->assertNotEmpty($entity->name->value, new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
+    $this->assertNotEmpty($entity->name[0]->value, new FormattableMarkup('%entity_type: Name is not empty.', ['%entity_type' => $entity_type]));
     $this->assertTrue(isset($entity->name[0]), new FormattableMarkup('%entity_type: Name string item is set.', ['%entity_type' => $entity_type]));
     $this->assertFalse(isset($entity->name[1]), new FormattableMarkup('%entity_type: Second name string item is not set as it does not exist', ['%entity_type' => $entity_type]));
     $this->assertTrue(isset($entity->name), new FormattableMarkup('%entity_type: Name field is set.', ['%entity_type' => $entity_type]));
diff --git a/core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php b/core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php
index 36f1f9cc8397..7eb64d6f3808 100644
--- a/core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Field/FieldItemTest.php
@@ -51,7 +51,7 @@ protected function setUp(): void {
 
     $this->entityTypeManager->clearCachedDefinitions();
     $definitions = \Drupal::service('entity_field.manager')->getFieldStorageDefinitions($entity_type_id);
-    $this->assertTrue(!empty($definitions[$this->fieldName]));
+    $this->assertNotEmpty($definitions[$this->fieldName]);
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php b/core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php
index 970ca6909fce..a703fe9aa290 100644
--- a/core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php
+++ b/core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php
@@ -146,7 +146,7 @@ public function testOptionKey() {
    */
   public function testOptionRecurse() {
     $files = $this->fileSystem->scanDirectory($this->path . '/..', '/^javascript-/', ['recurse' => FALSE]);
-    $this->assertTrue(empty($files), "Without recursion couldn't find javascript files.");
+    $this->assertEmpty($files, "Without recursion couldn't find javascript files.");
 
     $files = $this->fileSystem->scanDirectory($this->path . '/..', '/^javascript-/', ['recurse' => TRUE]);
     $this->assertCount(2, $files, 'With recursion we found the expected javascript files.');
@@ -163,7 +163,7 @@ public function testOptionMinDepth() {
     $this->assertCount(2, $files, 'No minimum-depth gets files in current directory.');
 
     $files = $this->fileSystem->scanDirectory($this->path, '/^javascript-/', ['min_depth' => 1]);
-    $this->assertTrue(empty($files), 'Minimum-depth of 1 successfully excludes files from current directory.');
+    $this->assertEmpty($files, 'Minimum-depth of 1 successfully excludes files from current directory.');
   }
 
   /**
diff --git a/core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php b/core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php
index 2e7ad83046f8..6b8fd87dff31 100644
--- a/core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Form/FormCacheTest.php
@@ -94,7 +94,7 @@ public function testNoCacheToken() {
     $cached_form_state = new FormState();
     $cached_form = \Drupal::formBuilder()->getCache($this->formBuildId, $cached_form_state);
     $this->assertEquals($this->form['#property'], $cached_form['#property']);
-    $this->assertTrue(empty($cached_form['#cache_token']), 'Form has no cache token');
+    $this->assertArrayNotHasKey('#cache_token', $cached_form, 'Form has no cache token');
     $this->assertEquals($this->formState->get('example'), $cached_form_state->get('example'));
 
     // Restore user account.
diff --git a/core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageExpirableTest.php b/core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageExpirableTest.php
index 5b7bd8f5146a..9f52371007d4 100644
--- a/core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageExpirableTest.php
+++ b/core/tests/Drupal/KernelTests/Core/KeyValueStore/DatabaseStorageExpirableTest.php
@@ -148,7 +148,7 @@ public function testExpiration() {
     $all = $stores[0]->getAll();
     $this->assertCount(2, $all);
     foreach (['troubles', 'still'] as $key) {
-      $this->assertTrue(!empty($all[$key]));
+      $this->assertArrayHasKey($key, $all);
     }
 
     // Test DatabaseStorageExpirable::setWithExpireIfNotExists() will overwrite
diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php b/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php
index e394a2d2da19..aa506632c66f 100644
--- a/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Plugin/ContextPluginTest.php
@@ -72,7 +72,7 @@ public function testContext() {
     // Try to pass the wrong class type as a context value.
     $plugin->setContextValue('user', $node);
     $violations = $plugin->validateContexts();
-    $this->assertTrue(!empty($violations), 'The provided context value does not pass validation.');
+    $this->assertNotEmpty($violations, 'The provided context value does not pass validation.');
 
     // Set an appropriate context value and check to make sure its methods work
     // as expected.
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/BaseThemeRequiredTest.php b/core/tests/Drupal/KernelTests/Core/Theme/BaseThemeRequiredTest.php
index 13734db774c7..3bfd15948c0a 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/BaseThemeRequiredTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/BaseThemeRequiredTest.php
@@ -49,7 +49,7 @@ public function testWildWest() {
     $theme = $this->themeManager->getActiveTheme();
     /** @var \Drupal\Core\Theme\ActiveTheme $base_theme */
     $base_themes = $theme->getBaseThemeExtensions();
-    $this->assertTrue(empty($base_themes), 'No base theme is set when a theme has opted out of using Stable.');
+    $this->assertEmpty($base_themes, 'No base theme is set when a theme has opted out of using Stable.');
   }
 
 }
diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
index 378576dbcd58..942e9f537790 100644
--- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
+++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php
@@ -320,11 +320,11 @@ protected function tearDown(): void {
         ':table_name' => '%',
         ':pattern' => 'sqlite_%',
       ])->fetchAllKeyed(0, 0);
-      $this->assertTrue(empty($result), 'All test tables have been removed.');
+      $this->assertEmpty($result, 'All test tables have been removed.');
     }
     else {
       $tables = $connection->schema()->findTables($this->databasePrefix . '%');
-      $this->assertTrue(empty($tables), 'All test tables have been removed.');
+      $this->assertEmpty($tables, 'All test tables have been removed.');
     }
   }
 
diff --git a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
index c329a7ddeb3a..710a2770e685 100644
--- a/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
+++ b/core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php
@@ -87,7 +87,7 @@ public function testDiscovery() {
     $this->assertSame(['id' => 'item3', 'name' => 'test2 item 3', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_2/subdir1/item_3.test.yml'], $data['test_2']['item3']);
     $this->assertCount(1, $data['test_2']);
 
-    $this->assertTrue(empty($data['test_3']), 'test_3 provides 0 items');
+    $this->assertArrayNotHasKey('test_3', $data, 'test_3 provides 0 items');
 
     $this->assertSame(['id' => 'item4', 'name' => 'test4 item 4', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1/item_4.test.yml'], $data['test_4']['item4']);
     $this->assertSame(['id' => 'item5', 'name' => 'test4 item 5', YamlDirectoryDiscovery::FILE_KEY => 'vfs://modules/test_4/subdir1/item_5.test.yml'], $data['test_4']['item5']);
diff --git a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
index 3f41a393002a..c3c2cbc0021a 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Enhancer/EntityRouteEnhancerTest.php
@@ -85,7 +85,7 @@ public function testEnhancer() {
     $defaults = $route_enhancer->enhance($defaults, $request);
     $this->assertEquals('\Drupal\Core\Entity\Controller\EntityViewController::view', $defaults['_controller'], 'The entity view controller was not set.');
     $this->assertEquals('Mock entity', $defaults['_entity']);
-    $this->assertTrue(empty($defaults['view_mode']));
+    $this->assertArrayNotHasKey('view_mode', $defaults);
     $this->assertFalse(isset($defaults['_entity_view']));
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
index ae0f753ef7ec..96fd9fd76a20 100644
--- a/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/InfoParserUnitTest.php
@@ -45,7 +45,7 @@ protected function setUp(): void {
   public function testInfoParserNonExisting() {
     vfsStream::setup('modules');
     $info = $this->infoParser->parse(vfsStream::url('modules') . '/does_not_exist.info.txt');
-    $this->assertTrue(empty($info), 'Non existing info.yml returns empty array.');
+    $this->assertEmpty($info, 'Non existing info.yml returns empty array.');
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php b/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
index d47f35141efc..3979f2cc0733 100644
--- a/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/MetadataBubblingUrlGeneratorTest.php
@@ -56,7 +56,7 @@ public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata,
     $this->renderer->expects($this->exactly($invocations))
       ->method('render')
       ->willReturnCallback(function ($build) use ($self) {
-        $self->assertTrue(!empty($build['#cache']));
+        $this->assertArrayHasKey('#cache', $build);
       });
 
     $url = new Url('test_1', [], $options);
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
index 69fa66bdd4d7..70b6a83dc3a0 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
@@ -122,7 +122,7 @@ public function testRenderRecursionWithNestedRenderPlain() {
     $output = $renderer->renderRoot($page);
     $this->assertEquals('<p>This is a rendered placeholder!</p>' . $parent_markup, $output, 'Rendered output as expected, with the placeholder replaced.');
     $this->assertNotContains('test:complex_child', $page['#cache']['tags'], 'Cache tag bubbling not performed.');
-    $this->assertTrue(empty($page['#attached']), 'Asset bubbling not performed.');
+    $this->assertEmpty($page['#attached'], 'Asset bubbling not performed.');
   }
 
 }
-- 
GitLab