diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 27333e8f84cc905506a1e8ee9cc36a01856d3424..89ccb8e7729f8397cbec5ae44daaacf389877842 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -518,7 +518,7 @@ protected function assertNotIdentical($first, $second, $message = '', $group = ' * @return * TRUE if the assertion succeeded, FALSE otherwise. */ - protected function assertIdenticalObject($object1, $object2, $message = '', $group = '') { + protected function assertIdenticalObject($object1, $object2, $message = '', $group = 'Other') { $message = $message ?: format_string('!object1 is identical to !object2', array( '!object1' => var_export($object1, TRUE), '!object2' => var_export($object2, TRUE), @@ -527,7 +527,7 @@ protected function assertIdenticalObject($object1, $object2, $message = '', $gro foreach ($object1 as $key => $value) { $identical = $identical && isset($object2->$key) && $object2->$key === $value; } - return $this->assertTrue($identical, $message); + return $this->assertTrue($identical, $message, $group); } diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 694a763da4af09f4037fe5592a2445a2fa23cb89..7d14ca029434c23a1fa28f0d5b054ab6e1b507cc 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -2205,7 +2205,7 @@ protected function assertNoText($text, $message = '', $group = 'Other') { * messages: use format_string() 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 + * 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. @@ -2286,7 +2286,7 @@ protected function assertNoUniqueText($text, $message = '', $group = 'Other') { * messages: use format_string() 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 + * 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. @@ -2428,11 +2428,16 @@ protected function assertNoTitle($title, $message = '', $group = 'Other') { * (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. + * @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 assertThemeOutput($callback, array $variables = array(), $expected, $message = '') { + protected function assertThemeOutput($callback, array $variables = array(), $expected, $message = '', $group = 'Other') { $output = theme($callback, $variables); $this->verbose('Variables:' . '
' .  check_plain(var_export($variables, TRUE)) . '
' . '
' . 'Result:' . '
' .  check_plain(var_export($output, TRUE)) . '
' @@ -2443,7 +2448,7 @@ protected function assertThemeOutput($callback, array $variables = array(), $exp $message = '%callback rendered correctly.'; } $message = format_string($message, array('%callback' => 'theme_' . $callback . '()')); - return $this->assertIdentical($output, $expected, $message); + return $this->assertIdentical($output, $expected, $message, $group); } /** @@ -2576,12 +2581,13 @@ protected function assertNoFieldByXPath($xpath, $value = NULL, $message = '', $g * @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 + * translate this string. Defaults to 'Browser'; most tests do not override * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertFieldByName($name, $value = NULL, $message = NULL) { + protected function assertFieldByName($name, $value = NULL, $message = NULL, $group = 'Browser') { if (!isset($message)) { if (!isset($value)) { $message = t('Found field with name @name', array( @@ -2595,7 +2601,7 @@ protected function assertFieldByName($name, $value = NULL, $message = NULL) { )); } } - return $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value, $message, t('Browser')); + return $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value, $message, $group); } /** @@ -2612,13 +2618,14 @@ protected function assertFieldByName($name, $value = NULL, $message = NULL) { * @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 + * translate this string. Defaults to 'Browser'; most tests do not override * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertNoFieldByName($name, $value = '', $message = '') { - return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), t('Browser')); + protected function assertNoFieldByName($name, $value = '', $message = '', $group = 'Browser') { + return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : t('Did not find field by name @name', array('@name' => $name)), $group); } /** @@ -2635,13 +2642,14 @@ protected function assertNoFieldByName($name, $value = '', $message = '') { * @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 + * translate this string. Defaults to 'Browser'; most tests do not override * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertFieldById($id, $value = '', $message = '') { - return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), t('Browser')); + protected function assertFieldById($id, $value = '', $message = '', $group = 'Browser') { + return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Found field by id @id', array('@id' => $id)), $group); } /** @@ -2658,13 +2666,14 @@ protected function assertFieldById($id, $value = '', $message = '') { * @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 + * translate this string. Defaults to 'Browser'; most tests do not override * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertNoFieldById($id, $value = '', $message = '') { - return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), t('Browser')); + protected function assertNoFieldById($id, $value = '', $message = '', $group = 'Browser') { + return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : t('Did not find field by id @id', array('@id' => $id)), $group); } /** @@ -2676,12 +2685,18 @@ protected function assertNoFieldById($id, $value = '', $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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertFieldChecked($id, $message = '') { + protected function assertFieldChecked($id, $message = '', $group = 'Browser') { $elements = $this->xpath('//input[@id=:id]', array(':id' => $id)); - return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is checked.', array('@id' => $id)), t('Browser')); + return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is checked.', array('@id' => $id)), $group); } /** @@ -2693,12 +2708,18 @@ protected function assertFieldChecked($id, $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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertNoFieldChecked($id, $message = '') { + protected function assertNoFieldChecked($id, $message = '', $group = 'Browser') { $elements = $this->xpath('//input[@id=:id]', array(':id' => $id)); - return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is not checked.', array('@id' => $id)), t('Browser')); + return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is not checked.', array('@id' => $id)), $group); } /** @@ -2712,12 +2733,18 @@ protected function assertNoFieldChecked($id, $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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertOption($id, $option, $message = '') { + protected function assertOption($id, $option, $message = '', $group = 'Browser') { $options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option)); - return $this->assertTrue(isset($options[0]), $message ? $message : t('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), t('Browser')); + return $this->assertTrue(isset($options[0]), $message ? $message : t('Option @option for field @id exists.', array('@option' => $option, '@id' => $id)), $group); } /** @@ -2731,13 +2758,19 @@ protected function assertOption($id, $option, $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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertNoOption($id, $option, $message = '') { + protected function assertNoOption($id, $option, $message = '', $group = 'Browser') { $selects = $this->xpath('//select[@id=:id]', array(':id' => $id)); $options = $this->xpath('//select[@id=:id]/option[@value=:option]', array(':id' => $id, ':option' => $option)); - return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : t('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), t('Browser')); + return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message ? $message : t('Option @option for field @id does not exist.', array('@option' => $option, '@id' => $id)), $group); } /** @@ -2751,14 +2784,20 @@ protected function assertNoOption($id, $option, $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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * TRUE on pass, FALSE on fail. * * @todo $id is unusable. Replace with $name. */ - protected function assertOptionSelected($id, $option, $message = '') { + protected function assertOptionSelected($id, $option, $message = '', $group = 'Browser') { $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option)); - return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is selected.', array('@option' => $option, '@id' => $id)), t('Browser')); + return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is selected.', array('@option' => $option, '@id' => $id)), $group); } /** @@ -2772,12 +2811,18 @@ protected function assertOptionSelected($id, $option, $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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * TRUE on pass, FALSE on fail. */ - protected function assertNoOptionSelected($id, $option, $message = '') { + protected function assertNoOptionSelected($id, $option, $message = '', $group = 'Browser') { $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(':id' => $id, ':option' => $option)); - return $this->assertTrue(isset($elements[0]) && empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is not selected.', array('@option' => $option, '@id' => $id)), t('Browser')); + return $this->assertTrue(isset($elements[0]) && empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is not selected.', array('@option' => $option, '@id' => $id)), $group); } /** @@ -2794,6 +2839,7 @@ protected function assertNoOptionSelected($id, $option, $message = '') { * 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. */ @@ -2815,6 +2861,7 @@ protected function assertField($field, $message = '', $group = 'Other') { * 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. */ @@ -2841,6 +2888,7 @@ protected function assertNoField($field, $message = '', $group = 'Other') { * it should add a "todo" comment above the call to this function explaining * the legacy bug that the test wishes to ignore and including a link to an * issue that is working to fix that legacy bug. + * * @return * TRUE on pass, FALSE on fail. */ @@ -2864,6 +2912,7 @@ protected function assertNoDuplicateIds($message = '', $group = 'Other', $ids_to * Field attributes. * @param $value * Value of field. + * * @return * XPath for specified values. */ @@ -2882,13 +2931,19 @@ protected function constructFieldXpath($attribute, $value) { * (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. + * @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 'Browser'; most tests do not override + * this default. + * * @return * Assertion result. */ - protected function assertResponse($code, $message = '') { + 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 : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser')); + return $this->assertTrue($match, $message ? $message : t('HTTP response expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group); } /** @@ -2901,14 +2956,19 @@ protected function assertResponse($code, $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. + * @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 'Browser'; most tests do not override + * this default. * * @return * Assertion result. */ - protected function assertNoResponse($code, $message = '') { + 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 : t('HTTP response not expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), t('Browser')); + return $this->assertFalse($match, $message ? $message : t('HTTP response not expected !code, actual !curl_code', array('!code' => $code, '!curl_code' => $curl_code)), $group); } /** @@ -2924,14 +2984,19 @@ protected function assertNoResponse($code, $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. + * @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 'E-mail'; most tests do not override + * this default. * * @return * TRUE on pass, FALSE on fail. */ - protected function assertMail($name, $value = '', $message = '') { + protected function assertMail($name, $value = '', $message = '', $group = 'E-mail') { $captured_emails = state()->get('system.test_email_collector') ?: array(); $email = end($captured_emails); - return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, t('E-mail')); + return $this->assertTrue($email && isset($email[$name]) && $email[$name] == $value, $message, $group); } /** @@ -2943,11 +3008,20 @@ protected function assertMail($name, $value = '', $message = '') { * 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 format_string() 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) { + protected function assertMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') { $mails = $this->drupalGetMails(); $string_found = FALSE; for ($i = count($mails) -1; $i >= count($mails) - $email_depth && $i >= 0; $i--) { @@ -2961,7 +3035,10 @@ protected function assertMailString($field_name, $string, $email_depth) { break; } } - return $this->assertTrue($string_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $string))); + 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); } /** @@ -2971,15 +3048,27 @@ protected function assertMailString($field_name, $string, $email_depth) { * 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 format_string() 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) { + protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') { $mails = $this->drupalGetMails(); $mail = end($mails); $regex_found = preg_match("/$regex/", $mail[$field_name]); - return $this->assertTrue($regex_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $regex))); + 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); } /**