diff --git a/core/lib/Drupal/Core/Test/AssertMailTrait.php b/core/lib/Drupal/Core/Test/AssertMailTrait.php index 9e60079e12..ed08a187ef 100644 --- a/core/lib/Drupal/Core/Test/AssertMailTrait.php +++ b/core/lib/Drupal/Core/Test/AssertMailTrait.php @@ -57,12 +57,15 @@ protected function getMails(array $filter = []) { * this default. * * @return bool - * TRUE on pass, FALSE on fail. + * TRUE on pass. */ protected function assertMail($name, $value = '', $message = '', $group = 'Email') { $captured_emails = $this->container->get('state')->get('system.test_mail_collector') ?: []; $email = end($captured_emails); - return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, $group); + $this->assertNotEmpty($email, $message); + $this->assertArrayHasKey($name, $email, $message); + $this->assertSame($value, $email[$name], $message); + return TRUE; } /** diff --git a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php index 574a1557f7..cc99a7e2a0 100644 --- a/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php +++ b/core/modules/big_pipe/tests/src/Functional/BigPipeTest.php @@ -268,7 +268,8 @@ public function testBigPipeNoJs() { $this->assertNoRaw(BigPipe::STOP_SIGNAL, 'BigPipe stop signal absent.'); // Verifying BigPipe assets are absent. - $this->assertTrue(!isset($this->getDrupalSettings()['bigPipePlaceholderIds']) && empty($this->getDrupalSettings()['ajaxPageState']), 'BigPipe drupalSettings and BigPipe asset library absent.'); + $this->assertArrayNotHasKey('bigPipePlaceholderIds', $this->getDrupalSettings()); + $this->assertArrayNotHasKey('ajaxPageState', $this->getDrupalSettings()); $this->assertRaw('', 'Closing body tag present.'); // Verify that 4xx responses work fine. (4xx responses are handled by diff --git a/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php b/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php index 70d7e1e152..07a1b18cd0 100644 --- a/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php +++ b/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php @@ -207,7 +207,9 @@ public function testBlockViewBuilderViewAlter() { $build = $this->getBlockRenderArray(); $this->assertFalse(isset($build['#prefix']), 'The appended #pre_render callback has not yet run before rendering.'); $this->assertIdentical((string) $this->renderer->renderRoot($build), 'Hiya!
'); - $this->assertTrue(isset($build['#prefix']) && $build['#prefix'] === 'Hiya!
', 'A cached block without content is altered.'); + // Check that a cached block without content is altered. + $this->assertArrayHasKey('#prefix', $build); + $this->assertSame('Hiya!
', $build['#prefix']); } /** diff --git a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php index b2df21206b..4e9637c107 100644 --- a/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php +++ b/core/modules/block_content/tests/src/Kernel/Migrate/d6/MigrateBlockContentTest.php @@ -40,14 +40,16 @@ public function testBlockMigration() { /** @var \Drupal\block_content\Entity\BlockContent $block */ $block = BlockContent::load(1); $this->assertIdentical('My block 1', $block->label()); - $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); + $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertIdentical('en', $block->language()->getId()); $this->assertIdentical('

My first custom block body

', $block->body->value); $this->assertIdentical('full_html', $block->body->format); $block = BlockContent::load(2); $this->assertIdentical('My block 2', $block->label()); - $this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time()); + $this->assertGreaterThanOrEqual(REQUEST_TIME, $block->getChangedTime()); + $this->assertLessThanOrEqual(time(), $block->getChangedTime()); $this->assertIdentical('en', $block->language()->getId()); $this->assertIdentical('

My second custom block body

', $block->body->value); $this->assertIdentical('full_html', $block->body->format); diff --git a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php index 2af323a516..bfd03eef24 100644 --- a/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php +++ b/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php @@ -101,8 +101,8 @@ public function testCommentInterface() { // Test changing the comment author to "Anonymous". $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => '']); - $this->assertTrue($comment->getAuthorName() == 'Anonymous', 'Comment author successfully changed to anonymous.'); - $this->assertTrue($comment->getOwnerId() == 0, 'Comment author successfully changed to anonymous.'); + $this->assertSame('Anonymous', $comment->getAuthorName()); + $this->assertEquals(0, $comment->getOwnerId()); // Test changing the comment author to an unverified user. $random_name = $this->randomMachineName(); @@ -114,7 +114,8 @@ public function testCommentInterface() { // Test changing the comment author to a verified user. $this->drupalGet('comment/' . $comment->id() . '/edit'); $comment = $this->postComment(NULL, $comment->comment_body->value, $comment->getSubject(), ['uid' => $this->webUser->getAccountName() . ' (' . $this->webUser->id() . ')']); - $this->assertTrue($comment->getAuthorName() == $this->webUser->getAccountName() && $comment->getOwnerId() == $this->webUser->id(), 'Comment author successfully changed to a registered user.'); + $this->assertSame($this->webUser->getAccountName(), $comment->getAuthorName()); + $this->assertSame($this->webUser->id(), $comment->getOwnerId()); $this->drupalLogout(); diff --git a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php index f0fbe3bd8a..0b9bfffca4 100644 --- a/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php +++ b/core/modules/comment/tests/src/Functional/CommentNonNodeTest.php @@ -176,7 +176,8 @@ public function postComment(EntityInterface $entity, $comment, $subject = '', $c $this->assertText($subject, 'Comment subject posted.'); } $this->assertText($comment, 'Comment body posted.'); - $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment ID found.'); + // Check the comment ID was extracted. + $this->assertArrayHasKey(1, $match); } if (isset($match[1])) { diff --git a/core/modules/comment/tests/src/Functional/CommentTestBase.php b/core/modules/comment/tests/src/Functional/CommentTestBase.php index abdae813e0..13b2abdcdc 100644 --- a/core/modules/comment/tests/src/Functional/CommentTestBase.php +++ b/core/modules/comment/tests/src/Functional/CommentTestBase.php @@ -175,7 +175,8 @@ public function postComment($entity, $comment, $subject = '', $contact = NULL, $ $this->assertText($subject, 'Comment subject posted.'); } $this->assertText($comment, 'Comment body posted.'); - $this->assertTrue((!empty($match) && !empty($match[1])), 'Comment id found.'); + // Check the comment ID was extracted. + $this->assertArrayHasKey(1, $match); } if (isset($match[1])) { diff --git a/core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php b/core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php index ea9232f645..ccad0f0775 100644 --- a/core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php +++ b/core/modules/config/tests/src/Functional/ConfigInstallProfileOverrideTest.php @@ -70,8 +70,7 @@ public function testInstallProfileConfigOverwrite() { $config = $this->config('system.site'); // Verify the system.site config has a valid UUID. - $site_uuid = $config->get('uuid'); - $this->assertTrue(Uuid::isValid($site_uuid) && strlen($site_uuid) > 0, "Site UUID '$site_uuid' is valid"); + $this->assertTrue(Uuid::isValid($config->get('uuid'))); // Verify the profile overrides have been used. $this->assertEquals(91, $config->get('weight_select_max')); // Ensure the site configure form is used. diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php index 27e9cdf192..502a7f0549 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php @@ -148,7 +148,8 @@ public function testSettingsUI() { $field_override = BaseFieldOverride::loadByName('entity_test_mul', 'entity_test_mul', 'name'); $this->assertTrue($field_override->isTranslatable(), 'Base fields can be overridden with a base field bundle override entity.'); $definitions = $entity_field_manager->getFieldDefinitions('entity_test_mul', 'entity_test_mul'); - $this->assertTrue($definitions['name']->isTranslatable() && !$definitions['user_id']->isTranslatable(), 'Base field bundle overrides were correctly altered.'); + $this->assertTrue($definitions['name']->isTranslatable()); + $this->assertFalse($definitions['user_id']->isTranslatable()); // Test that language settings are correctly stored. $language_configuration = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_article'); diff --git a/core/modules/editor/tests/src/Functional/EditorAdminTest.php b/core/modules/editor/tests/src/Functional/EditorAdminTest.php index e2ffd5ecfb..5f8baf0c94 100644 --- a/core/modules/editor/tests/src/Functional/EditorAdminTest.php +++ b/core/modules/editor/tests/src/Functional/EditorAdminTest.php @@ -62,7 +62,8 @@ public function testNoEditorAvailable() { $roles_pos = strpos($raw_content, 'Roles'); $editor_pos = strpos($raw_content, 'Text editor'); $filters_pos = strpos($raw_content, 'Enabled filters'); - $this->assertTrue($roles_pos < $editor_pos && $editor_pos < $filters_pos, '"Text Editor" select appears in the correct location of the text format configuration UI.'); + $this->assertGreaterThan($roles_pos, $editor_pos); + $this->assertLessThan($filters_pos, $editor_pos); // Verify the