AssertHelperTrait.php 731 B

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