Update to Drupal 8.0.6. For more information, see https://www.drupal.org/drupal-8.0.6-release-notes
This commit is contained in:
parent
4297c64508
commit
b11a755ba8
159 changed files with 2340 additions and 543 deletions
|
|
@ -28,6 +28,7 @@ use Drupal\Core\Session\AnonymousUserSession;
|
|||
use Drupal\Core\Session\UserSession;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Drupal\Core\StreamWrapper\PublicStream;
|
||||
use Drupal\Core\Test\AssertMailTrait;
|
||||
use Drupal\Core\Url;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
|
@ -47,6 +48,9 @@ abstract class WebTestBase extends TestBase {
|
|||
use ContentTypeCreationTrait {
|
||||
createContentType as drupalCreateContentType;
|
||||
}
|
||||
use AssertMailTrait {
|
||||
getMails as drupalGetMails;
|
||||
}
|
||||
use NodeCreationTrait {
|
||||
getNodeByTitle as drupalGetNodeByTitle;
|
||||
createNode as drupalCreateNode;
|
||||
|
|
@ -2518,32 +2522,6 @@ abstract class WebTestBase extends TestBase {
|
|||
return $this->assertTrue($header_value == $value, $message ? $message : 'HTTP response header ' . $header . ' with value ' . $value . ' found, actual value: ' . $header_value, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array containing all emails sent during this test case.
|
||||
*
|
||||
* @param $filter
|
||||
* An array containing key/value pairs used to filter the emails that are
|
||||
* returned.
|
||||
*
|
||||
* @return
|
||||
* An array containing email messages captured during the current test.
|
||||
*/
|
||||
protected function drupalGetMails($filter = array()) {
|
||||
$captured_emails = \Drupal::state()->get('system.test_mail_collector') ?: array();
|
||||
$filtered_emails = array();
|
||||
|
||||
foreach ($captured_emails as $message) {
|
||||
foreach ($filter as $key => $value) {
|
||||
if (!isset($message[$key]) || $message[$key] != $value) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
$filtered_emails[] = $message;
|
||||
}
|
||||
|
||||
return $filtered_emails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Passes if the internal browser's URL matches the given path.
|
||||
*
|
||||
|
|
@ -2644,126 +2622,6 @@ abstract class WebTestBase extends TestBase {
|
|||
return $this->assertFalse($match, $message ? $message : SafeMarkup::format('HTTP response not expected @code, actual @curl_code', array('@code' => $code, '@curl_code' => $curl_code)), $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the most recently sent email message has the given value.
|
||||
*
|
||||
* The field in $name must have the content described in $value.
|
||||
*
|
||||
* @param $name
|
||||
* Name of field or message property to assert. Examples: subject, body,
|
||||
* id, ...
|
||||
* @param $value
|
||||
* Value of the field to assert.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
* (optional) The group this message is in, which is displayed in a column
|
||||
* in test output. Use 'Debug' to indicate this is debugging output. Do not
|
||||
* translate this string. Defaults to 'Email'; most tests do not override
|
||||
* this default.
|
||||
*
|
||||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
protected function assertMail($name, $value = '', $message = '', $group = 'Email') {
|
||||
$captured_emails = \Drupal::state()->get('system.test_mail_collector') ?: array();
|
||||
$email = end($captured_emails);
|
||||
return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the most recently sent email message has the string in it.
|
||||
*
|
||||
* @param $field_name
|
||||
* Name of field or message property to assert: subject, body, id, ...
|
||||
* @param $string
|
||||
* String to search for.
|
||||
* @param $email_depth
|
||||
* Number of emails to search for string, starting with most recent.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
* (optional) The group this message is in, which is displayed in a column
|
||||
* in test output. Use 'Debug' to indicate this is debugging output. Do not
|
||||
* translate this string. Defaults to 'Other'; most tests do not override
|
||||
* this default.
|
||||
*
|
||||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
protected function assertMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
|
||||
$mails = $this->drupalGetMails();
|
||||
$string_found = FALSE;
|
||||
// Cast MarkupInterface objects to string.
|
||||
$string = (string) $string;
|
||||
for ($i = count($mails) -1; $i >= count($mails) - $email_depth && $i >= 0; $i--) {
|
||||
$mail = $mails[$i];
|
||||
// Normalize whitespace, as we don't know what the mail system might have
|
||||
// done. Any run of whitespace becomes a single space.
|
||||
$normalized_mail = preg_replace('/\s+/', ' ', $mail[$field_name]);
|
||||
$normalized_string = preg_replace('/\s+/', ' ', $string);
|
||||
$string_found = (FALSE !== strpos($normalized_mail, $normalized_string));
|
||||
if ($string_found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$message) {
|
||||
$message = format_string('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $string));
|
||||
}
|
||||
return $this->assertTrue($string_found, $message, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the most recently sent email message has the pattern in it.
|
||||
*
|
||||
* @param $field_name
|
||||
* Name of field or message property to assert: subject, body, id, ...
|
||||
* @param $regex
|
||||
* Pattern to search for.
|
||||
* @param $message
|
||||
* (optional) A message to display with the assertion. Do not translate
|
||||
* messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed
|
||||
* variables in the message text, not t(). If left blank, a default message
|
||||
* will be displayed.
|
||||
* @param $group
|
||||
* (optional) The group this message is in, which is displayed in a column
|
||||
* in test output. Use 'Debug' to indicate this is debugging output. Do not
|
||||
* translate this string. Defaults to 'Other'; most tests do not override
|
||||
* this default.
|
||||
*
|
||||
* @return
|
||||
* TRUE on pass, FALSE on fail.
|
||||
*/
|
||||
protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
|
||||
$mails = $this->drupalGetMails();
|
||||
$mail = end($mails);
|
||||
$regex_found = preg_match("/$regex/", $mail[$field_name]);
|
||||
if (!$message) {
|
||||
$message = format_string('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $regex));
|
||||
}
|
||||
return $this->assertTrue($regex_found, $message, $group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs to verbose the most recent $count emails sent.
|
||||
*
|
||||
* @param $count
|
||||
* Optional number of emails to output.
|
||||
*/
|
||||
protected function verboseEmail($count = 1) {
|
||||
$mails = $this->drupalGetMails();
|
||||
for ($i = count($mails) -1; $i >= count($mails) - $count && $i >= 0; $i--) {
|
||||
$mail = $mails[$i];
|
||||
$this->verbose('Email:<pre>' . print_r($mail, TRUE) . '</pre>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mock request and sets it on the generator.
|
||||
*
|
||||
|
|
|
|||
Reference in a new issue