5325e8c9b003bcb673bbb1988e58d4f7ea167568
[yaffs-website] / web / core / modules / simpletest / src / AssertHelperTrait.php
1 <?php
2
3 namespace Drupal\simpletest;
4
5 use Drupal\Component\Render\MarkupInterface;
6
7 /**
8  * Provides helper methods for assertions.
9  */
10 trait AssertHelperTrait {
11
12   /**
13    * Casts MarkupInterface objects into strings.
14    *
15    * @param string|array $value
16    *   The value to act on.
17    *
18    * @return mixed
19    *   The input value, with MarkupInterface objects casted to string.
20    */
21   protected static function castSafeStrings($value) {
22     if ($value instanceof MarkupInterface) {
23       $value = (string) $value;
24     }
25     if (is_array($value)) {
26       array_walk_recursive($value, function (&$item) {
27         if ($item instanceof MarkupInterface) {
28           $item = (string) $item;
29         }
30       });
31     }
32     return $value;
33   }
34
35 }