diff --git a/core/modules/system/src/Tests/System/PageTitleTest.php b/core/modules/system/src/Tests/System/PageTitleTest.php
index 1a63f23..6d56a6f 100644
--- a/core/modules/system/src/Tests/System/PageTitleTest.php
+++ b/core/modules/system/src/Tests/System/PageTitleTest.php
@@ -143,19 +143,19 @@ public function testRoutingTitle() {
     // controller does not escape them.
     $this->drupalGet('test-page-cached-controller');
     $this->assertTitle('Cached title | Drupal');
-    $this->assertText(SafeMarkup::checkPlain('<span>Cached title</span>'));
+    $this->assertRaw(SafeMarkup::checkPlain('<span>Cached title</span>') . '</h1>');
     $this->drupalGet('test-page-cached-controller');
     $this->assertTitle('Cached title | Drupal');
-    $this->assertText(SafeMarkup::checkPlain('<span>Cached title</span>'));
+    $this->assertRaw(SafeMarkup::checkPlain('<span>Cached title</span>') . '</h1>');
 
     // Ensure that titles are cacheable and are escaped normally if the
     // controller escapes them use SafeMarkup::checkPlain().
     $this->drupalGet('test-page-cached-controller-safe');
-    $this->assertTitle('Cached title | Drupal');
-    $this->assertText(SafeMarkup::checkPlain('<span>Cached title</span>'));
+    $this->assertTitle('<span>Cached title</span> | Drupal');
+    $this->assertRaw(SafeMarkup::checkPlain('<span>Cached title</span>') . '</h1>');
     $this->drupalGet('test-page-cached-controller-safe');
-    $this->assertTitle('Cached title | Drupal');
-    $this->assertText(SafeMarkup::checkPlain('<span>Cached title</span>'));
+    $this->assertTitle('<span>Cached title</span> | Drupal');
+    $this->assertRaw(SafeMarkup::checkPlain('<span>Cached title</span>') . '</h1>');
   }
 
 }
diff --git a/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php
index c6313b5..b0d4136 100644
--- a/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php
+++ b/core/modules/system/tests/modules/test_page_test/src/Controller/Test.php
@@ -66,7 +66,7 @@ public function controllerWithCache($mark_safe = FALSE) {
     if ($mark_safe) {
       $build['#title'] = SafeMarkup::checkPlain($build['#title']);
     }
-    $build['#cache']['keys'] = ['test_controller', 'with_title'];
+    $build['#cache']['keys'] = ['test_controller', 'with_title', $mark_safe];
 
     return $build;
   }
