Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 292987

The AssertMailTrait should cast the data type to boolean in assertMailPattern

$
0
0

Problem/Motivation

The /core/lib/Drupal/Core/Test/AssertMailTrait.php() uses the result of the preg_match() function in assertTrue(). However preg_match() function returns 1, 0 or FALSE.

protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
  $mails = $this->getMails();
  $mail = end($mails);
  $regex_found = preg_match("/$regex/", $mail[$field_name]);
  if (!$message) {
    $message = new FormattableMarkup('Expected text found in @field of email message: "@expected".', ['@field' => $field_name, '@expected' => $regex]);
  }
  return $this->assertTrue($regex_found, $message, $group);
}

Proposed resolution

Use data type casting to boolean.


Viewing all articles
Browse latest Browse all 292987

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>