diff --git a/core/includes/common.inc b/core/includes/common.inc
index b45819c..6b2d95b 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -5097,6 +5097,28 @@ function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {
   return (($skip_anonymous && $user->uid == 0) || ($token == drupal_get_token($value)));
 }
 
+
+/**
+ * Exports any variable to a string for output, including resource IDs.
+ *
+ * var_export() does not support resource IDs, so we include special handling
+ * for them.
+ *
+ * @param mixed $var
+ *   The variable to export. Can be any data type.
+ *
+ * @return string
+ *   The string containing the exported variable data.
+ */
+function drupal_var_export($var) {
+  if (is_resource($var)) {
+    return get_resource_type($var) . ' resource';
+  }
+  else {
+    return var_export($var, TRUE);
+  }
+}
+
 function _drupal_bootstrap_full() {
   static $called = FALSE;
 
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
index 552b4e3..a9356e0 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php
@@ -174,6 +174,26 @@ abstract class TestBase {
   }
 
   /**
+   * Assembles an assertion message from a default and optional custom text.
+   *
+   * @param string $default
+   *   The default message text. Always displayed.
+   * @param string $custom
+   *   (optional) A custom message explaining the assertion. Defaults to an
+   *   empty string.
+   */
+  protected function assertionMessage($default, $custom = '') {
+    if (!empty($custom)) {
+      $message = $custom . ' (' . $default . ') ';
+    }
+    else {
+      $message = $default;
+    }
+
+    return truncate_utf8($message, 256);
+  }
+
+  /**
    * Store an assertion from outside the testing context.
    *
    * This is useful for inserting assertions that can only be recorded after
@@ -268,7 +288,14 @@ abstract class TestBase {
    *   TRUE if the assertion succeeded, FALSE otherwise.
    */
   protected function assertTrue($value, $message = '', $group = 'Other') {
-    return $this->assert((bool) $value, $message ? $message : t('Value @value is TRUE.', array('@value' => var_export($value, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @value is TRUE.',
+        array('@value' => drupal_var_export($value))
+      ),
+      $message
+    );
+    return $this->assert((bool) $value, $message, $group);
   }
 
   /**
@@ -284,7 +311,14 @@ abstract class TestBase {
    *   TRUE if the assertion succeeded, FALSE otherwise.
    */
   protected function assertFalse($value, $message = '', $group = 'Other') {
-    return $this->assert(!$value, $message ? $message : t('Value @value is FALSE.', array('@value' => var_export($value, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @value is FALSE.',
+        array('@value' => drupal_var_export($value))
+      ),
+      $message
+    );
+    return $this->assert(!$value, $message, $group);
   }
 
   /**
@@ -300,7 +334,14 @@ abstract class TestBase {
    *   TRUE if the assertion succeeded, FALSE otherwise.
    */
   protected function assertNull($value, $message = '', $group = 'Other') {
-    return $this->assert(!isset($value), $message ? $message : t('Value @value is NULL.', array('@value' => var_export($value, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @value is NULL.',
+        array('@value' => drupal_var_export($value))
+      ),
+      $message
+    );
+    return $this->assert(!isset($value), $message, $group);
   }
 
   /**
@@ -316,7 +357,14 @@ abstract class TestBase {
    *   TRUE if the assertion succeeded, FALSE otherwise.
    */
   protected function assertNotNull($value, $message = '', $group = 'Other') {
-    return $this->assert(isset($value), $message ? $message : t('Value @value is not NULL.', array('@value' => var_export($value, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @value is not NULL.',
+        array('@value' => drupal_var_export($value))
+      ),
+      $message
+    );
+    return $this->assert(isset($value), $message, $group);
   }
 
   /**
@@ -334,7 +382,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 : t('Value @first is equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @first is equal to value @second.',
+        array(
+          '@first' => drupal_var_export($first),
+          '@second' => drupal_var_export($second),
+        )
+      ),
+      $message
+    );
+    return $this->assert($first == $second, $message, $group);
   }
 
   /**
@@ -352,7 +410,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 : t('Value @first is not equal to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @first is not equal to value @second.',
+        array(
+          '@first' => drupal_var_export($first),
+          '@second' => drupal_var_export($second),
+        )
+      ),
+      $message
+    );
+    return $this->assert($first != $second, $message, $group);
   }
 
   /**
@@ -370,7 +438,17 @@ 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 : t('Value @first is identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @first is identical to value @second.',
+        array(
+          '@first' => drupal_var_export($first),
+          '@second' => drupal_var_export($second),
+        )
+      ),
+      $message
+    );
+    return $this->assert($first === $second, $message, $group);
   }
 
   /**
@@ -388,7 +466,17 @@ 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 : t('Value @first is not identical to value @second.', array('@first' => var_export($first, TRUE), '@second' => var_export($second, TRUE))), $group);
+    $message = $this->assertionMessage(
+      format_string(
+        'Value @first is not identical to value @second.',
+        array(
+          '@first' => drupal_var_export($first),
+          '@second' => drupal_var_export($second),
+        )
+      ),
+      $message
+    );
+    return $this->assert($first !== $second, $message, $group);
   }
 
   /**
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index db0f09f..51d52f5 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -1808,7 +1808,10 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertLink($label, $index = 0, $message = '', $group = 'Other') {
     $links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
-    $message = ($message ?  $message : t('Link with label %label found.', array('%label' => $label)));
+    $message = $this->assertionMessage(
+      format_string('Link with label %label found.', array('%label' => $label)),
+      $message
+    );
     return $this->assert(isset($links[$index]), $message, $group);
   }
 
@@ -1828,7 +1831,13 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertNoLink($label, $message = '', $group = 'Other') {
     $links = $this->xpath('//a[normalize-space(text())=:label]', array(':label' => $label));
-    $message = ($message ?  $message : t('Link with label %label not found.', array('%label' => $label)));
+    $message = $this->assertionMessage(
+      format_string(
+        'Link with label %label not found.',
+        array('%label' => $label)
+      ),
+      $message
+    );
     return $this->assert(empty($links), $message, $group);
   }
 
@@ -1849,7 +1858,13 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertLinkByHref($href, $index = 0, $message = '', $group = 'Other') {
     $links = $this->xpath('//a[contains(@href, :href)]', array(':href' => $href));
-    $message = ($message ?  $message : t('Link containing href %href found.', array('%href' => $href)));
+    $message = $this->assertionMessage(
+      format_string(
+        'Link containing href %href found.',
+        array('%href' => $href)
+      ),
+      $message
+    );
     return $this->assert(isset($links[$index]), $message, $group);
   }
 
@@ -1868,7 +1883,13 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertNoLinkByHref($href, $message = '', $group = 'Other') {
     $links = $this->xpath('//a[contains(@href, :href)]', array(':href' => $href));
-    $message = ($message ?  $message : t('No link containing href %href found.', array('%href' => $href)));
+    $message = $this->assertionMessage(
+      format_string(
+        'No link containing href %href found.',
+        array('%href' => $href)
+      ),
+      $message
+    );
     return $this->assert(empty($links), $message, $group);
   }
 
@@ -2110,11 +2131,14 @@ abstract class WebTestBase extends TestBase {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertUrl($path, array $options = array(), $message = '', $group = 'Other') {
-    if (!$message) {
-      $message = t('Current URL is @url.', array(
-        '@url' => var_export(url($path, $options), TRUE),
-      ));
-    }
+    $message = $this->assertionMessage(
+      format_string(
+        'Current URL is @url.',
+        array('@url' => var_export(url($path, $options), TRUE))
+      ),
+      $message
+    );
+
     $options['absolute'] = TRUE;
     return $this->assertEqual($this->getUrl(), url($path, $options), $message, $group);
   }
@@ -2133,9 +2157,10 @@ abstract class WebTestBase extends TestBase {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertRaw($raw, $message = '', $group = 'Other') {
-    if (!$message) {
-      $message = t('Raw "@raw" found', array('@raw' => $raw));
-    }
+    $message = $this->assertionMessage(
+      format_string('Raw "@raw" found', array('@raw' => $raw)),
+      $message
+    );
     return $this->assert(strpos($this->drupalGetContent(), $raw) !== FALSE, $message, $group);
   }
 
@@ -2153,9 +2178,10 @@ abstract class WebTestBase extends TestBase {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertNoRaw($raw, $message = '', $group = 'Other') {
-    if (!$message) {
-      $message = t('Raw "@raw" not found', array('@raw' => $raw));
-    }
+    $message = $this->assertionMessage(
+      format_string('Raw "@raw" not found', array('@raw' => $raw)),
+      $message
+    );
     return $this->assert(strpos($this->drupalGetContent(), $raw) === FALSE, $message, $group);
   }
 
@@ -2215,9 +2241,9 @@ abstract class WebTestBase extends TestBase {
     if ($this->plainTextContent === FALSE) {
       $this->plainTextContent = filter_xss($this->drupalGetContent(), array());
     }
-    if (!$message) {
-      $message = !$not_exists ? t('"@text" found', array('@text' => $text)) : t('"@text" not found', array('@text' => $text));
-    }
+    $default_message = !$not_exists ? format_string('"@text" found', array('@text' => $text)) : format_string('"@text" not found', array('@text' => $text));
+    $message = $this->assertionMessage($default_message, $message);
+
     return $this->assert($not_exists == (strpos($this->plainTextContent, $text) === FALSE), $message, $group);
   }
 
@@ -2281,9 +2307,10 @@ abstract class WebTestBase extends TestBase {
     if ($this->plainTextContent === FALSE) {
       $this->plainTextContent = filter_xss($this->drupalGetContent(), array());
     }
-    if (!$message) {
-      $message = '"' . $text . '"' . ($be_unique ? ' found only once' : ' found more than once');
-    }
+
+    $default_message = '"' . $text . '"' . ($be_unique ? ' found only once' : ' found more than once');
+    $message = $this->assertionMessage($default_message, $message);
+
     $first_occurance = strpos($this->plainTextContent, $text);
     if ($first_occurance === FALSE) {
       return $this->assert(FALSE, $message, $group);
@@ -2306,9 +2333,10 @@ abstract class WebTestBase extends TestBase {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertPattern($pattern, $message = '', $group = 'Other') {
-    if (!$message) {
-      $message = t('Pattern "@pattern" found', array('@pattern' => $pattern));
-    }
+    $message = $this->assertionMessage(
+      format_string('Pattern "@pattern" found', array('@pattern' => $pattern)),
+      $message
+    );
     return $this->assert((bool) preg_match($pattern, $this->drupalGetContent()), $message, $group);
   }
 
@@ -2325,9 +2353,13 @@ abstract class WebTestBase extends TestBase {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertNoPattern($pattern, $message = '', $group = 'Other') {
-    if (!$message) {
-      $message = t('Pattern "@pattern" not found', array('@pattern' => $pattern));
-    }
+    $message = $this->assertionMessage(
+      format_string(
+        'Pattern "@pattern" not found',
+        array('@pattern' => $pattern)
+      ),
+      $message
+    );
     return $this->assert(!preg_match($pattern, $this->drupalGetContent()), $message, $group);
   }
 
@@ -2345,12 +2377,13 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertTitle($title, $message = '', $group = 'Other') {
     $actual = (string) current($this->xpath('//title'));
-    if (!$message) {
-      $message = t('Page title @actual is equal to @expected.', array(
+    $message = $this->assertionMessage(
+      format_string('Page title @actual is equal to @expected.', array(
         '@actual' => var_export($actual, TRUE),
         '@expected' => var_export($title, TRUE),
-      ));
-    }
+      )),
+      $message
+    );
     return $this->assertEqual($actual, $title, $message, $group);
   }
 
@@ -2368,12 +2401,13 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertNoTitle($title, $message = '', $group = 'Other') {
     $actual = (string) current($this->xpath('//title'));
-    if (!$message) {
-      $message = t('Page title @actual is not equal to @unexpected.', array(
+    $message = $this->assertionMessage(
+      format_string('Page title @actual is not equal to @unexpected.', array(
         '@actual' => var_export($actual, TRUE),
         '@unexpected' => var_export($title, TRUE),
-      ));
-    }
+      )),
+      $message
+    );
     return $this->assertNotEqual($actual, $title, $message, $group);
   }
 
@@ -2498,19 +2532,24 @@ abstract class WebTestBase extends TestBase {
    *   TRUE on pass, FALSE on fail.
    */
   protected function assertFieldByName($name, $value = NULL, $message = NULL) {
-    if (!isset($message)) {
-      if (!isset($value)) {
-        $message = t('Found field with name @name', array(
+    if (!isset($value)) {
+      $default_message = format_string(
+        'Found field with name @name',
+        array(
           '@name' => var_export($name, TRUE),
-        ));
-      }
-      else {
-        $message = t('Found field with name @name and value @value', array(
+        )
+      );
+    }
+    else {
+      $default_message = format_string(
+        'Found field with name @name and value @value',
+        array(
           '@name' => var_export($name, TRUE),
           '@value' => var_export($value, TRUE),
-        ));
-      }
+        )
+      );
     }
+    $message = $this->assertionMessage($default_message, $message);
     return $this->assertFieldByXPath($this->constructFieldXpath('name', $name), $value, $message, t('Browser'));
   }
 
@@ -2529,7 +2568,14 @@ abstract class WebTestBase extends TestBase {
    *   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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'Did not find field by name @name',
+        array('@name' => $name)
+      ),
+      $message
+    );
+    return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message, t('Browser'));
   }
 
   /**
@@ -2547,7 +2593,11 @@ abstract class WebTestBase extends TestBase {
    *   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'));
+    $message = $this->assertionMessage(
+      format_string('Found field by id @id', array('@id' => $id)),
+      $message
+    );
+    return $this->assertFieldByXPath($this->constructFieldXpath('id', $id), $value, $message, t('Browser'));
   }
 
   /**
@@ -2565,7 +2615,11 @@ abstract class WebTestBase extends TestBase {
    *   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'));
+    $message = $this->assertionMessage(
+      format_string('Did not find field by id @id', array('@id' => $id)),
+      $message
+    );
+    return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message, t('Browser'));
   }
 
   /**
@@ -2580,7 +2634,11 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertFieldChecked($id, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      t('Checkbox field @id is checked.', array('@id' => $id)),
+      $message
+    );
+    return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message, t('Browser'));
   }
 
   /**
@@ -2595,7 +2653,11 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertNoFieldChecked($id, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string('Checkbox field @id is not checked.', array('@id' => $id)),
+      $message
+    );
+    return $this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), $message, t('Browser'));
   }
 
   /**
@@ -2612,7 +2674,17 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertOption($id, $option, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'Option @option for field @id exists.',
+        array(
+          '@option' => $option,
+          '@id' => $id
+        )
+      ),
+      $message
+    );
+    return $this->assertTrue(isset($options[0]), $message, t('Browser'));
   }
 
   /**
@@ -2630,7 +2702,14 @@ abstract class WebTestBase extends TestBase {
   protected function assertNoOption($id, $option, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'Option @option for field @id does not exist.',
+        array('@option' => $option, '@id' => $id)
+      ),
+      $message
+    );
+    return $this->assertTrue(isset($selects[0]) && !isset($options[0]), $message, t('Browser'));
   }
 
   /**
@@ -2649,7 +2728,14 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertOptionSelected($id, $option, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'Option @option for field @id is selected.',
+        array('@option' => $option, '@id' => $id)
+      ),
+      $message
+    );
+    return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message, t('Browser'));
   }
 
   /**
@@ -2666,7 +2752,14 @@ abstract class WebTestBase extends TestBase {
    */
   protected function assertNoOptionSelected($id, $option, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'Option @option for field @id is not selected.',
+        array('@option' => $option, '@id' => $id)
+      ),
+      $message
+    );
+    return $this->assertTrue(isset($elements[0]) && empty($elements[0]['selected']), $message, t('Browser'));
   }
 
   /**
@@ -2760,7 +2853,17 @@ abstract class WebTestBase extends TestBase {
   protected function assertResponse($code, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'HTTP response expected !code, actual !curl_code',
+        array(
+          '!code' => var_export($code, TRUE),
+          '!curl_code' => $curl_code
+        )
+      ),
+      $message
+    );
+    return $this->assertTrue($match, $message, t('Browser'));
   }
 
   /**
@@ -2778,7 +2881,14 @@ abstract class WebTestBase extends TestBase {
   protected function assertNoResponse($code, $message = '') {
     $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'));
+    $message = $this->assertionMessage(
+      format_string(
+        'HTTP response not expected !code, actual !curl_code',
+        array('!code' => $code, '!curl_code' => $curl_code)
+      ),
+      $message
+    );
+    return $this->assertFalse($match, $message, t('Browser'));
   }
 
   /**
