diff --git a/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php b/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php
index 656e0015d13bcaac4cd5449bdba3679c8b179d13..7789f7accb7a960aeca0110ec2338072a0b58062 100644
--- a/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php
+++ b/core/modules/search/src/Tests/SearchKeywordsConditionsTest.php
@@ -7,6 +7,8 @@
 
 namespace Drupal\search\Tests;
 
+use Drupal\Component\Utility\SafeMarkup;
+
 /**
  * Verify the search without keywords set and extra conditions.
  *
@@ -59,6 +61,6 @@ function testSearchKeywordsConditions() {
     $keys = 'moving drop ' . $this->randomMachineName();
     $this->drupalGet("search/dummy_path", array('query' => array('keys' => 'bike', 'search_conditions' => $keys)));
     $this->assertText("Dummy search snippet to display.");
-    $this->assertRaw(print_r(array('keys' => 'bike', 'search_conditions' => $keys), TRUE));
+    $this->assertRaw(SafeMarkup::checkPlain(print_r(array('keys' => 'bike', 'search_conditions' => $keys), TRUE)));
   }
 }
diff --git a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php
index 5c97934543b7703fc102f33de51a897104658186..75541fd7243ab02740e9c5501cc32f4ad7f8ef74 100644
--- a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php
+++ b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php
@@ -64,7 +64,7 @@ public function execute() {
         'link' => Url::fromRoute('test_page_test.test_page')->toString(),
         'type' => 'Dummy result type',
         'title' => 'Dummy title',
-        'snippet' => SafeMarkup::set("Dummy search snippet to display. Keywords: {$this->keywords}\n\nConditions: " . print_r($this->searchParameters, TRUE)),
+        'snippet' => SafeMarkup::format("Dummy search snippet to display. Keywords: @keywords\n\nConditions: @search_parameters", ['@keywords' => $this->keywords, '@search_parameters' => print_r($this->searchParameters, TRUE)]),
       ),
     );
   }