Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -178,6 +178,10 @@ trait AssertContentTrait {
protected function buildXPathQuery($xpath, array $args = array()) {
// Replace placeholders.
foreach ($args as $placeholder => $value) {
// Cast MarkupInterface objects to string.
if (is_object($value)) {
$value = (string) $value;
}
// XPath 1.0 doesn't support a way to escape single or double quotes in a
// string literal. We split double quotes out of the string, and encode
// them separately.
@ -281,7 +285,7 @@ trait AssertContentTrait {
*
* An optional link index may be passed.
*
* @param string $label
* @param string|\Drupal\Component\Render\MarkupInterface $label
* Text between the anchor tags.
* @param int $index
* Link position counting from zero.
@ -299,6 +303,8 @@ trait AssertContentTrait {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertLink($label, $index = 0, $message = '', $group = 'Other') {
// Cast MarkupInterface objects to string.
$label = (string) $label;
$links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
$message = ($message ? $message : strtr('Link with label %label found.', array('%label' => $label)));
return $this->assert(isset($links[$index]), $message, $group);
@ -307,12 +313,13 @@ trait AssertContentTrait {
/**
* Passes if a link with the specified label is not found.
*
* @param string $label
* @param string|\Drupal\Component\Render\MarkupInterface $label
* Text between the anchor tags.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -323,6 +330,8 @@ trait AssertContentTrait {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNoLink($label, $message = '', $group = 'Other') {
// Cast MarkupInterface objects to string.
$label = (string) $label;
$links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
$message = ($message ? $message : SafeMarkup::format('Link with label %label not found.', array('%label' => $label)));
return $this->assert(empty($links), $message, $group);
@ -337,8 +346,9 @@ trait AssertContentTrait {
* Link position counting from zero.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -361,8 +371,9 @@ trait AssertContentTrait {
* The full or partial value of the 'href' attribute of the anchor tag.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -385,8 +396,9 @@ trait AssertContentTrait {
* The full or partial value of the 'href' attribute of the anchor tag.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -411,8 +423,9 @@ trait AssertContentTrait {
* Raw (HTML) string to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -424,7 +437,7 @@ trait AssertContentTrait {
*/
protected function assertRaw($raw, $message = '', $group = 'Other') {
if (!$message) {
$message = SafeMarkup::format('Raw "@raw" found', array('@raw' => $raw));
$message = 'Raw "' . Html::escape($raw) . '" found';
}
return $this->assert(strpos($this->getRawContent(), (string) $raw) !== FALSE, $message, $group);
}
@ -438,8 +451,9 @@ trait AssertContentTrait {
* Raw (HTML) string to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -451,7 +465,7 @@ trait AssertContentTrait {
*/
protected function assertNoRaw($raw, $message = '', $group = 'Other') {
if (!$message) {
$message = SafeMarkup::format('Raw "@raw" not found', array('@raw' => $raw));
$message = 'Raw "' . Html::escape($raw) . '" not found';
}
return $this->assert(strpos($this->getRawContent(), (string) $raw) === FALSE, $message, $group);
}
@ -465,8 +479,9 @@ trait AssertContentTrait {
* Raw (HTML) string to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -478,7 +493,7 @@ trait AssertContentTrait {
*/
protected function assertEscaped($raw, $message = '', $group = 'Other') {
if (!$message) {
$message = SafeMarkup::format('Escaped "@raw" found', array('@raw' => $raw));
$message = 'Escaped "' . Html::escape($raw) . '" found';
}
return $this->assert(strpos($this->getRawContent(), Html::escape($raw)) !== FALSE, $message, $group);
}
@ -493,8 +508,9 @@ trait AssertContentTrait {
* Raw (HTML) string to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -506,7 +522,7 @@ trait AssertContentTrait {
*/
protected function assertNoEscaped($raw, $message = '', $group = 'Other') {
if (!$message) {
$message = SafeMarkup::format('Escaped "@raw" not found', array('@raw' => $raw));
$message = 'Escaped "' . Html::escape($raw) . '" not found';
}
return $this->assert(strpos($this->getRawContent(), Html::escape($raw)) === FALSE, $message, $group);
}
@ -521,8 +537,9 @@ trait AssertContentTrait {
* Plain text to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -548,8 +565,9 @@ trait AssertContentTrait {
* Plain text to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -574,8 +592,9 @@ trait AssertContentTrait {
* Plain text to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -602,12 +621,13 @@ trait AssertContentTrait {
* through a web browser. In other words the HTML has been filtered out of
* the contents.
*
* @param string $text
* @param string|\Drupal\Component\Render\MarkupInterface $text
* Plain text to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -628,12 +648,13 @@ trait AssertContentTrait {
* through a web browser. In other words the HTML has been filtered out of
* the contents.
*
* @param string $text
* @param string|\Drupal\Component\Render\MarkupInterface $text
* Plain text to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -652,12 +673,13 @@ trait AssertContentTrait {
*
* It is not recommended to call this function directly.
*
* @param string $text
* @param string|\Drupal\Component\Render\MarkupInterface $text
* Plain text to look for.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -671,6 +693,8 @@ trait AssertContentTrait {
* TRUE on pass, FALSE on fail.
*/
protected function assertUniqueTextHelper($text, $message = '', $group = 'Other', $be_unique = FALSE) {
// Cast MarkupInterface objects to string.
$text = (string) $text;
if (!$message) {
$message = '"' . $text . '"' . ($be_unique ? ' found only once' : ' found more than once');
}
@ -690,8 +714,9 @@ trait AssertContentTrait {
* Perl regex to look for including the regex delimiters.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -715,8 +740,9 @@ trait AssertContentTrait {
* Perl regex to look for including the regex delimiters.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -763,8 +789,9 @@ trait AssertContentTrait {
* The string the title should be.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -779,6 +806,8 @@ trait AssertContentTrait {
preg_match('@<title>(.*)</title>@', $this->getRawContent(), $matches);
if (isset($matches[1])) {
$actual = $matches[1];
$actual = $this->castSafeStrings($actual);
$title = $this->castSafeStrings($title);
if (!$message) {
$message = SafeMarkup::format('Page title @actual is equal to @expected.', array(
'@actual' => var_export($actual, TRUE),
@ -797,8 +826,9 @@ trait AssertContentTrait {
* The string the title should not be.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -830,8 +860,9 @@ trait AssertContentTrait {
* The expected themed output string.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -846,7 +877,7 @@ trait AssertContentTrait {
$renderer = \Drupal::service('renderer');
// The string cast is necessary because theme functions return
// SafeStringInterface objects. This means we can assert that $expected
// MarkupInterface objects. This means we can assert that $expected
// matches the theme output without having to worry about 0 == ''.
$output = (string) $renderer->executeInRenderContext(new RenderContext(), function() use ($callback, $variables) {
return \Drupal::theme()->render($callback, $variables);
@ -873,8 +904,9 @@ trait AssertContentTrait {
* checking the actual value, while still checking that the field exists.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -930,8 +962,9 @@ trait AssertContentTrait {
* exists.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -980,8 +1013,9 @@ trait AssertContentTrait {
* page does not match it.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1020,8 +1054,9 @@ trait AssertContentTrait {
* exists.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1060,8 +1095,9 @@ trait AssertContentTrait {
* default value ('') asserts that the field value is not an empty string.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1080,15 +1116,16 @@ trait AssertContentTrait {
*
* @param string $id
* ID of field to assert.
* @param string $value
* @param string|\Drupal\Component\Render\MarkupInterface $value
* (optional) Value for the field to assert. You may pass in NULL to skip
* checking the value, while still checking that the field exists.
* However, the default value ('') asserts that the field value is an empty
* string.
* @param string $message
* @param string|\Drupal\Component\Render\MarkupInterface $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1099,6 +1136,11 @@ trait AssertContentTrait {
* TRUE on pass, FALSE on fail.
*/
protected function assertFieldById($id, $value = '', $message = '', $group = 'Browser') {
// Cast MarkupInterface objects to string.
if (isset($value)) {
$value = (string) $value;
}
$message = (string) $message;
return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : SafeMarkup::format('Found field by id @id', array('@id' => $id)), $group);
}
@ -1114,8 +1156,9 @@ trait AssertContentTrait {
* value ('') asserts that the field value is not an empty string.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1136,8 +1179,9 @@ trait AssertContentTrait {
* ID of field to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1159,8 +1203,9 @@ trait AssertContentTrait {
* ID of field to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1184,8 +1229,9 @@ trait AssertContentTrait {
* Option to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1209,8 +1255,9 @@ trait AssertContentTrait {
* Option to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1234,8 +1281,9 @@ trait AssertContentTrait {
* Option to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1260,8 +1308,9 @@ trait AssertContentTrait {
* Option to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1287,8 +1336,9 @@ trait AssertContentTrait {
* Option to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1314,8 +1364,9 @@ trait AssertContentTrait {
* Option to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1337,8 +1388,9 @@ trait AssertContentTrait {
* Name or ID of field to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1359,8 +1411,9 @@ trait AssertContentTrait {
* Name or ID of field to assert.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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
@ -1379,8 +1432,9 @@ trait AssertContentTrait {
*
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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 string $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

View file

@ -0,0 +1,40 @@
<?php
/**
* @file
* Contains \Drupal\simpletest\AssertHelperTrait.
*/
namespace Drupal\simpletest;
use Drupal\Component\Render\MarkupInterface;
/**
* Provides helper methods for assertions.
*/
trait AssertHelperTrait {
/**
* Casts MarkupInterface objects into strings.
*
* @param string|array $value
* The value to act on.
*
* @return mixed
* The input value, with MarkupInterface objects casted to string.
*/
protected function castSafeStrings($value) {
if ($value instanceof MarkupInterface) {
$value = (string) $value;
}
if (is_array($value)) {
array_walk_recursive($value, function (&$item) {
if ($item instanceof MarkupInterface) {
$item = (string) $item;
}
});
}
return $value;
}
}

View file

@ -13,6 +13,7 @@ use Behat\Mink\Exception\Exception;
use Behat\Mink\Mink;
use Behat\Mink\Session;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\ConnectionNotDefinedException;
use Drupal\Core\Database\Database;
@ -23,6 +24,7 @@ use Drupal\Core\Session\UserSession;
use Drupal\Core\Site\Settings;
use Drupal\Core\StreamWrapper\StreamWrapperInterface;
use Drupal\Core\Test\TestRunnerKernel;
use Drupal\Core\Url;
use Drupal\user\UserInterface;
use Symfony\Component\HttpFoundation\Request;
@ -404,7 +406,14 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
// The URL generator service is not necessarily available yet; e.g., in
// interactive installer tests.
if ($this->container->has('url_generator')) {
$url = $this->container->get('url_generator')->generateFromPath($path, $options);
if (UrlHelper::isExternal($path)) {
$url = Url::fromUri($path, $options)->toString();
}
else {
// This is needed for language prefixing.
$options['path_processing'] = TRUE;
$url = Url::fromUri('base:/' . $path, $options)->toString();
}
}
else {
$url = $this->getAbsoluteUrl($path);
@ -1010,7 +1019,7 @@ abstract class BrowserTestBase extends \PHPUnit_Framework_TestCase {
*/
protected function prepareEnvironment() {
// Bootstrap Drupal so we can use Drupal's built in functions.
$this->classLoader = require __DIR__ . '/../../../vendor/autoload.php';
$this->classLoader = require __DIR__ . '/../../../../autoload.php';
$request = Request::createFromGlobals();
$kernel = TestRunnerKernel::createFromRequest($request, $this->classLoader);
// TestRunnerKernel expects the working directory to be DRUPAL_ROOT.

View file

@ -62,6 +62,17 @@ class SimpletestTestForm extends FormBase {
'#tableselect' => TRUE,
'#button_type' => 'primary',
);
$form['clean'] = array(
'#type' => 'fieldset',
'#title' => $this->t('Clean test environment'),
'#description' => $this->t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
'#weight' => 200,
);
$form['clean']['op'] = array(
'#type' => 'submit',
'#value' => $this->t('Clean environment'),
'#submit' => array('simpletest_clean_environment'),
);
// Do not needlessly re-execute a full test discovery if the user input
// already contains an explicit list of test classes to run.
@ -187,18 +198,6 @@ class SimpletestTestForm extends FormBase {
}
}
$form['clean'] = array(
'#type' => 'fieldset',
'#title' => $this->t('Clean test environment'),
'#description' => $this->t('Remove tables with the prefix "simpletest" and temporary directories that are left over from tests that crashed. This is intended for developers when creating tests.'),
'#weight' => 200,
);
$form['clean']['op'] = array(
'#type' => 'submit',
'#value' => $this->t('Clean environment'),
'#submit' => array('simpletest_clean_environment'),
);
return $form;
}

View file

@ -111,12 +111,9 @@ abstract class InstallerTestBase extends WebTestBase {
$this->container
->register('language.default', 'Drupal\Core\Language\LanguageDefault')
->addArgument('%language.default_values%');
$this->container
->register('language_manager', 'Drupal\Core\Language\LanguageManager')
->addArgument(new Reference('language.default'));
$this->container
->register('string_translation', 'Drupal\Core\StringTranslation\TranslationManager')
->addArgument(new Reference('language_manager'));
->addArgument(new Reference('language.default'));
$this->container
->set('app.root', DRUPAL_ROOT);
\Drupal::setContainer($this->container);
@ -159,7 +156,7 @@ abstract class InstallerTestBase extends WebTestBase {
$this->container = $this->kernel->getContainer();
// Manually configure the test mail collector implementation to prevent
// tests from sending out e-mails and collect them in state instead.
// tests from sending out emails and collect them in state instead.
$this->container->get('config.factory')
->getEditable('system.mail')
->set('interface.default', 'test_mail_collector')

View file

@ -116,23 +116,20 @@ abstract class KernelTestBase extends TestBase {
* @see config_get_config_directory()
*
* @throws \RuntimeException
* Thrown when CONFIG_ACTIVE_DIRECTORY or CONFIG_STAGING_DIRECTORY cannot
* be created or made writable.
* Thrown when CONFIG_SYNC_DIRECTORY cannot be created or made writable.
*/
protected function prepareConfigDirectories() {
$this->configDirectories = array();
include_once DRUPAL_ROOT . '/core/includes/install.inc';
foreach (array(CONFIG_ACTIVE_DIRECTORY, CONFIG_STAGING_DIRECTORY) as $type) {
// Assign the relative path to the global variable.
$path = $this->siteDirectory . '/config_' . $type;
$GLOBALS['config_directories'][$type] = $path;
// Ensure the directory can be created and is writeable.
if (!install_ensure_config_directory($type)) {
throw new \RuntimeException("Failed to create '$type' config directory $path");
}
// Provide the already resolved path for tests.
$this->configDirectories[$type] = $path;
// Assign the relative path to the global variable.
$path = $this->siteDirectory . '/config_' . CONFIG_SYNC_DIRECTORY;
$GLOBALS['config_directories'][CONFIG_SYNC_DIRECTORY] = $path;
// Ensure the directory can be created and is writeable.
if (!install_ensure_config_directory(CONFIG_SYNC_DIRECTORY)) {
throw new \RuntimeException("Failed to create '" . CONFIG_SYNC_DIRECTORY . "' config directory $path");
}
// Provide the already resolved path for tests.
$this->configDirectories[CONFIG_SYNC_DIRECTORY] = $path;
}
/**
@ -193,6 +190,22 @@ EOD;
}
$this->kernel->boot();
// Ensure database install tasks have been run.
require_once __DIR__ . '/../../../includes/install.inc';
$connection = Database::getConnection();
$errors = db_installer_object($connection->driver())->runTasks();
if (!empty($errors)) {
$this->fail('Failed to run installer database tasks: ' . implode(', ', $errors));
}
// Reboot the kernel because the container might contain a connection to the
// database that has been closed during the database install tasks. This
// prevents any services created during the first boot from having stale
// database connections, for example, \Drupal\Core\Config\DatabaseStorage.
$this->kernel->shutdown();
$this->kernel->boot();
// Save the original site directory path, so that extensions in the
// site-specific directory can still be discovered in the test site
// environment.
@ -572,8 +585,14 @@ EOD;
* The rendered string output (typically HTML).
*/
protected function render(array &$elements) {
$content = $this->container->get('renderer')->renderRoot($elements);
drupal_process_attached($elements);
// Use the bare HTML page renderer to render our links.
$renderer = $this->container->get('bare_html_page_renderer');
$response = $renderer->renderBarePage(
$elements, '', $this->container->get('theme.manager')->getActiveTheme()->getName()
);
// Glean the content from the response object.
$content = $response->getContent();
$this->setRawContent($content);
$this->verbose('<pre style="white-space: pre-wrap">' . Html::escape($content));
return $content;

View file

@ -7,6 +7,7 @@
namespace Drupal\simpletest;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Random;
use Drupal\Component\Utility\SafeMarkup;
@ -29,6 +30,7 @@ abstract class TestBase {
use SessionTestTrait;
use RandomGeneratorTrait;
use AssertHelperTrait;
/**
* The test run ID.
@ -359,7 +361,7 @@ abstract class TestBase {
* @param $status
* Can be 'pass', 'fail', 'exception', 'debug'.
* TRUE is a synonym for 'pass', FALSE for 'fail'.
* @param $message
* @param string|\Drupal\Component\Render\MarkupInterface $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
@ -377,6 +379,9 @@ abstract class TestBase {
* is the caller function itself.
*/
protected function assert($status, $message = '', $group = 'Other', array $caller = NULL) {
if ($message instanceof MarkupInterface) {
$message = (string) $message;
}
// Convert boolean status to string status.
if (is_bool($status)) {
$status = $status ? 'pass' : 'fail';
@ -654,7 +659,17 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertEqual($first, $second, $message = '', $group = 'Other') {
return $this->assert($first == $second, $message ? $message : SafeMarkup::format('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
// Cast objects implementing MarkupInterface to string instead of
// relying on PHP casting them to string depending on what they are being
// comparing with.
$first = $this->castSafeStrings($first);
$second = $this->castSafeStrings($second);
$is_equal = $first == $second;
if (!$is_equal || !$message) {
$default_message = SafeMarkup::format('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($is_equal, $message, $group);
}
/**
@ -679,7 +694,17 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotEqual($first, $second, $message = '', $group = 'Other') {
return $this->assert($first != $second, $message ? $message : SafeMarkup::format('Value @first is not equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
// Cast objects implementing MarkupInterface to string instead of
// relying on PHP casting them to string depending on what they are being
// comparing with.
$first = $this->castSafeStrings($first);
$second = $this->castSafeStrings($second);
$not_equal = $first != $second;
if (!$not_equal || !$message) {
$default_message = SafeMarkup::format('Value @first is not equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($not_equal, $message, $group);
}
/**
@ -704,7 +729,12 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertIdentical($first, $second, $message = '', $group = 'Other') {
return $this->assert($first === $second, $message ? $message : SafeMarkup::format('Value @first is identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
$is_identical = $first === $second;
if (!$is_identical || !$message) {
$default_message = SafeMarkup::format('Value @first is identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($is_identical, $message, $group);
}
/**
@ -729,7 +759,12 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotIdentical($first, $second, $message = '', $group = 'Other') {
return $this->assert($first !== $second, $message ? $message : SafeMarkup::format('Value @first is not identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
$not_identical = $first !== $second;
if (!$not_identical || !$message) {
$default_message = SafeMarkup::format('Value @first is not identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE)));
$message = $message ? $message . PHP_EOL . $default_message : $default_message;
}
return $this->assert($not_identical, $message, $group);
}
/**
@ -754,9 +789,9 @@ abstract class TestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') {
$message = $message ?: SafeMarkup::format('!object1 is identical to !object2', array(
'!object1' => var_export($object1, TRUE),
'!object2' => var_export($object2, TRUE),
$message = $message ?: SafeMarkup::format('@object1 is identical to @object2', array(
'@object1' => var_export($object1, TRUE),
'@object2' => var_export($object2, TRUE),
));
$identical = TRUE;
foreach ($object1 as $key => $value) {
@ -872,7 +907,8 @@ abstract class TestBase {
$verbose_filename = $this->verboseClassName . '-' . $this->verboseId . '-' . $this->testId . '.html';
if (file_put_contents($this->verboseDirectory . '/' . $verbose_filename, $message)) {
$url = $this->verboseDirectoryUrl . '/' . $verbose_filename;
// Not using _l() to avoid invoking the theme system, so that unit tests
// Not using \Drupal\Core\Utility\LinkGeneratorInterface::generate()
// to avoid invoking the theme system, so that unit tests
// can use verbose() as well.
$url = '<a href="' . $url . '" target="_blank">Verbose message</a>';
$this->error($url, 'User notice');
@ -933,6 +969,10 @@ abstract class TestBase {
$this->httpAuthCredentials = $username . ':' . $password;
}
// Force assertion failures to be thrown as AssertionError for PHP 5 & 7
// compatibility.
\Drupal\Component\Assertion\Handle::register();
set_error_handler(array($this, 'errorHandler'));
// Iterate through all the methods in this class, unless a specific list of
// methods to run was passed.
@ -1478,7 +1518,7 @@ abstract class TestBase {
if (!$this->configImporter) {
// Set up the ConfigImporter object for testing.
$storage_comparer = new StorageComparer(
$this->container->get('config.storage.staging'),
$this->container->get('config.storage.sync'),
$this->container->get('config.storage'),
$this->container->get('config.manager')
);

View file

@ -68,6 +68,14 @@ EOS;
// Verify that the settings.testing.php got taken into account.
$this->assertTrue(function_exists('simpletest_test_stub_settings_function'));
// Ensure that the database tasks have been run during set up. Neither MySQL
// nor SQLite make changes that are testable.
$database = $this->container->get('database');
if ($database->driver() == 'pgsql') {
$this->assertEqual('on', $database->query("SHOW standard_conforming_strings")->fetchField());
$this->assertEqual('escape', $database->query("SHOW bytea_output")->fetchField());
}
}
/**

View file

@ -20,9 +20,7 @@ class MigrateSimpletestConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public static $modules = array('simpletest');
@ -31,7 +29,6 @@ class MigrateSimpletestConfigsTest extends MigrateDrupal6TestBase {
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['simpletest']);
$this->executeMigration('d6_simpletest_settings');
}

View file

@ -167,11 +167,20 @@ EOD;
// Check to see if runtime assertions are indeed on, if successful this
// will be the first of sixteen passes asserted in confirmStubResults()
try {
assert(FALSE, 'Lorem Ipsum');
// Test with minimum possible arguments to make sure no notice for
// missing argument is thrown.
assert(FALSE);
$this->fail('Runtime assertions are not working.');
}
catch (\AssertionError $e) {
$this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.');
try {
// Now test with an error message to ensure it is correctly passed
// along by the rethrow.
assert(FALSE, 'Lorem Ipsum');
}
catch ( \AssertionError $e ) {
$this->assertEqual($e->getMessage(), 'Lorem Ipsum', 'Runtime assertions Enabled and running.');
}
}
// This causes the second of the sixteen passes asserted in
// confirmStubResults().

View file

@ -233,7 +233,7 @@ abstract class WebTestBase extends TestBase {
/**
* Get a node from the database based on its title.
*
* @param $title
* @param string|\Drupal\Component\Render\MarkupInterface $title
* A node title, usually generated by $this->randomMachineName().
* @param $reset
* (optional) Whether to reset the entity cache.
@ -245,6 +245,8 @@ abstract class WebTestBase extends TestBase {
if ($reset) {
\Drupal::entityManager()->getStorage('node')->resetCache();
}
// Cast MarkupInterface objects to string.
$title = (string) $title;
$nodes = entity_load_multiple_by_properties('node', array('title' => $title));
// Load the first node returned from the database.
$returned_node = reset($nodes);
@ -408,7 +410,6 @@ abstract class WebTestBase extends TestBase {
* - region: 'sidebar_first'.
* - theme: The default theme.
* - visibility: Empty array.
* - cache: array('max_age' => Cache::PERMANENT).
*
* @return \Drupal\block\Entity\Block
* The block entity.
@ -425,9 +426,6 @@ abstract class WebTestBase extends TestBase {
'label' => $this->randomMachineName(8),
'visibility' => array(),
'weight' => 0,
'cache' => array(
'max_age' => Cache::PERMANENT,
),
);
$values = [];
foreach (array('region', 'id', 'theme', 'plugin', 'weight', 'visibility') as $key) {
@ -1419,12 +1417,12 @@ abstract class WebTestBase extends TestBase {
$this->url = isset($original_url) ? $original_url : curl_getinfo($this->curlHandle, CURLINFO_EFFECTIVE_URL);
$message_vars = array(
'!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
'@method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
'@url' => isset($original_url) ? $original_url : $url,
'@status' => $status,
'!length' => format_size(strlen($this->getRawContent()))
'@length' => format_size(strlen($this->getRawContent()))
);
$message = SafeMarkup::format('!method @url returned @status (!length).', $message_vars);
$message = SafeMarkup::format('@method @url returned @status (@length).', $message_vars);
$this->assertTrue($this->getRawContent() !== FALSE, $message, 'Browser');
return $this->getRawContent();
}
@ -1690,6 +1688,14 @@ abstract class WebTestBase extends TestBase {
* (e.g., "&extra_var1=hello+world&extra_var2=you%26me").
*/
protected function drupalPostForm($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) {
if (is_object($submit)) {
// Cast MarkupInterface objects to string.
$submit = (string) $submit;
}
if (is_array($edit)) {
$edit = $this->castSafeStrings($edit);
}
$submit_matches = FALSE;
$ajax = is_array($submit);
if (isset($path)) {
@ -2223,7 +2229,7 @@ abstract class WebTestBase extends TestBase {
*/
protected function drupalHead($path, array $options = array(), array $headers = array()) {
$options['absolute'] = TRUE;
$url = $this->container->get('url_generator')->generateFromPath($path, $options);
$url = $this->buildUrl($path, $options);
$out = $this->curlExec(array(CURLOPT_NOBODY => TRUE, CURLOPT_URL => $url, CURLOPT_HTTPHEADER => $headers));
// Ensure that any changes to variables in the other thread are picked up.
$this->refreshVariables();
@ -2407,7 +2413,7 @@ abstract class WebTestBase extends TestBase {
*
* If the link is discovered and clicked, the test passes. Fail otherwise.
*
* @param string $label
* @param string|\Drupal\Component\Render\MarkupInterface $label
* Text between the anchor tags.
* @param int $index
* Link position counting from zero.
@ -2425,7 +2431,7 @@ abstract class WebTestBase extends TestBase {
*
* If the link is discovered and clicked, the test passes. Fail otherwise.
*
* @param string $label
* @param string|\Drupal\Component\Render\MarkupInterface $label
* Text between the anchor tags, uses starts-with().
* @param int $index
* Link position counting from zero.
@ -2442,7 +2448,7 @@ abstract class WebTestBase extends TestBase {
/**
* Provides a helper for ::clickLink() and ::clickLinkPartialName().
*
* @param string $label
* @param string|\Drupal\Component\Render\MarkupInterface $label
* Text between the anchor tags, uses starts-with().
* @param int $index
* Link position counting from zero.
@ -2453,6 +2459,8 @@ abstract class WebTestBase extends TestBase {
* Page contents on success, or FALSE on failure.
*/
protected function clickLinkHelper($label, $index, $pattern) {
// Cast MarkupInterface objects to string.
$label = (string) $label;
$url_before = $this->getUrl();
$urls = $this->xpath($pattern, array(':label' => $label));
if (isset($urls[$index])) {
@ -2662,8 +2670,9 @@ abstract class WebTestBase extends TestBase {
* (optional) Any additional options to pass for $path to the url generator.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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
@ -2675,12 +2684,18 @@ abstract class WebTestBase extends TestBase {
*/
protected function assertUrl($path, array $options = array(), $message = '', $group = 'Other') {
if ($path instanceof Url) {
$url = $path->setAbsolute()->toString();
$url_obj = $path;
}
elseif (UrlHelper::isExternal($path)) {
$url_obj = Url::fromUri($path, $options);
}
else {
$options['absolute'] = TRUE;
$url = $this->container->get('url_generator')->generateFromPath($path, $options);
$uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
// This is needed for language prefixing.
$options['path_processing'] = TRUE;
$url_obj = Url::fromUri($uri, $options);
}
$url = $url_obj->setAbsolute()->toString();
if (!$message) {
$message = SafeMarkup::format('Expected @url matches current URL (@current_url).', array(
'@url' => var_export($url, TRUE),
@ -2702,8 +2717,9 @@ abstract class WebTestBase extends TestBase {
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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
@ -2716,7 +2732,7 @@ abstract class WebTestBase extends TestBase {
protected function assertResponse($code, $message = '', $group = 'Browser') {
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
return $this->assertTrue($match, $message ? $message : SafeMarkup::format('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group);
return $this->assertTrue($match, $message ? $message : SafeMarkup::format('HTTP response expected @code, actual @curl_code', array('@code' => $code, '@curl_code' => $curl_code)), $group);
}
/**
@ -2727,8 +2743,9 @@ abstract class WebTestBase extends TestBase {
* of all codes see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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
@ -2741,7 +2758,7 @@ abstract class WebTestBase extends TestBase {
protected function assertNoResponse($code, $message = '', $group = 'Browser') {
$curl_code = curl_getinfo($this->curlHandle, CURLINFO_HTTP_CODE);
$match = is_array($code) ? in_array($curl_code, $code) : $curl_code == $code;
return $this->assertFalse($match, $message ? $message : SafeMarkup::format('HTTP response not expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group);
return $this->assertFalse($match, $message ? $message : SafeMarkup::format('HTTP response not expected @code, actual @curl_code', array('@code' => $code, '@curl_code' => $curl_code)), $group);
}
/**
@ -2756,8 +2773,9 @@ abstract class WebTestBase extends TestBase {
* Value of the field to assert.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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
@ -2784,8 +2802,9 @@ abstract class WebTestBase extends TestBase {
* 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 format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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
@ -2798,6 +2817,8 @@ abstract class WebTestBase extends TestBase {
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
@ -2824,8 +2845,9 @@ abstract class WebTestBase extends TestBase {
* Pattern to search for.
* @param $message
* (optional) A message to display with the assertion. Do not translate
* messages: use format_string() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
* 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
@ -2934,8 +2956,19 @@ abstract class WebTestBase extends TestBase {
// The URL generator service is not necessarily available yet; e.g., in
// interactive installer tests.
else if ($this->container->has('url_generator')) {
$options['absolute'] = TRUE;
return $this->container->get('url_generator')->generateFromPath($path, $options);
$force_internal = isset($options['external']) && $options['external'] == FALSE;
if (!$force_internal && UrlHelper::isExternal($path)) {
return Url::fromUri($path, $options)->toString();
}
else {
$uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
// Path processing is needed for language prefixing. Skip it when a
// path that may look like an external URL is being used as internal.
$options['path_processing'] = !$force_internal;
return Url::fromUri($uri, $options)
->setAbsolute()
->toString();
}
}
else {
return $this->getAbsoluteUrl($path);