diff --git a/core/modules/comment/tests/src/Functional/CommentAdminTest.php b/core/modules/comment/tests/src/Functional/CommentAdminTest.php
index e7026026e2d189080ce2aca00ab0c55533173b60..24d13c16c9d4ba23b365067a97d7ebda0a27b9b1 100644
--- a/core/modules/comment/tests/src/Functional/CommentAdminTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentAdminTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\comment\Functional;
 
+use Drupal\comment\CommentInterface;
 use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Component\Utility\Html;
 use Drupal\language\Entity\ConfigurableLanguage;
@@ -41,7 +42,7 @@ public function testApprovalAdminInterface() {
     ]);
     $this->drupalLogin($this->adminUser);
     // Ensure that doesn't require contact info.
-    $this->setCommentAnonymous('0');
+    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
 
     // Test that the comments page loads correctly when there are no comments
     $this->drupalGet('admin/content/comment');
@@ -134,7 +135,7 @@ public function testApprovalNodeInterface() {
     ]);
     $this->drupalLogin($this->adminUser);
     // Ensure that doesn't require contact info.
-    $this->setCommentAnonymous('0');
+    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
     $this->drupalLogout();
 
     // Post anonymous comment without contact info.
@@ -220,7 +221,7 @@ public function testEditComment() {
     // Post anonymous comment.
     $this->drupalLogin($this->adminUser);
     // Ensure that we need email id before posting comment.
-    $this->setCommentAnonymous('2');
+    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MUST_CONTACT);
     $this->drupalLogout();
 
     // Post comment with contact info (required).
@@ -256,7 +257,7 @@ public function testCommentedTranslationDeletion() {
     // Rebuild the container to update the default language container variable.
     $this->rebuildContainer();
     // Ensure that doesn't require contact info.
-    $this->setCommentAnonymous('0');
+    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
     $this->drupalLogin($this->webUser);
     $count_query = \Drupal::entityTypeManager()
       ->getStorage('comment')
diff --git a/core/modules/comment/tests/src/Functional/CommentLinksTest.php b/core/modules/comment/tests/src/Functional/CommentLinksTest.php
index cf5ad5408519495968575a04bff41799ff57c382..97209f68189426b576ac2b0918f7f133f054883b 100644
--- a/core/modules/comment/tests/src/Functional/CommentLinksTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentLinksTest.php
@@ -83,7 +83,6 @@ public function testCommentLinks() {
 
     // Change comment settings.
     $this->setCommentSettings('form_location', CommentItemInterface::FORM_BELOW, 'Set comment form location');
-    $this->setCommentAnonymous(TRUE);
     $this->node->comment = CommentItemInterface::OPEN;
     $this->node->save();
 
diff --git a/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php b/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php
index 5c896e90b3585030beb37d712fa4b09ab15d226a..5bbce26e81d814ff5977efb95c4c4dcf87cfec35 100644
--- a/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php
+++ b/core/modules/comment/tests/src/Functional/CommentStatisticsTest.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Tests\comment\Functional;
 
+use Drupal\comment\CommentInterface;
 use Drupal\comment\CommentManagerInterface;
 use Drupal\comment\Entity\Comment;
 
@@ -89,7 +90,7 @@ public function testCommentNodeCommentStatistics() {
     $this->drupalLogout();
 
     // Ensure that the poster can leave some contact info.
-    $this->setCommentAnonymous('1');
+    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAY_CONTACT);
 
     // Post comment #2 as anonymous (comment approval enabled).
     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
diff --git a/core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php b/core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php
index 2fde2e05615984b7709bf94366d8c5f9551e6dba..9a60790340f18d5a3fa1f837cee75885f2afea85 100644
--- a/core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php
+++ b/core/modules/comment/tests/src/Functional/Views/CommentAdminTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\block_content\Entity\BlockContent;
 use Drupal\block_content\Entity\BlockContentType;
+use Drupal\comment\CommentInterface;
 use Drupal\comment\Entity\Comment;
 use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
 use Drupal\Tests\comment\Functional\CommentTestBase as CommentBrowserTestBase;
@@ -48,7 +49,7 @@ public function testApprovalAdminInterface() {
     $this->drupalPlaceBlock('page_title_block');
     $this->drupalLogin($this->adminUser);
     // Ensure that doesn't require contact info.
-    $this->setCommentAnonymous('0');
+    $this->setCommentAnonymous(CommentInterface::ANONYMOUS_MAYNOT_CONTACT);
 
     // Test that the comments page loads correctly when there are no comments.
     $this->drupalGet('admin/content/comment');