summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/common.test
diff options
context:
space:
mode:
Diffstat (limited to 'modules/simpletest/tests/common.test')
-rw-r--r--modules/simpletest/tests/common.test56
1 files changed, 51 insertions, 5 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index c266dc3b4..5650d8c01 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -56,6 +56,14 @@ class DrupalAlterTestCase extends DrupalWebTestCase {
$this->assertEqual($array_copy, $array_expected, t('First argument to drupal_alter() was altered.'));
$this->assertEqual($entity_copy, $entity_expected, t('Second argument to drupal_alter() was altered.'));
$this->assertEqual($array2_copy, $array2_expected, t('Third argument to drupal_alter() was altered.'));
+
+ // Verify alteration order when passing an array of types to drupal_alter().
+ // common_test_module_implements_alter() places 'block' implementation after
+ // other modules.
+ $array_copy = $array;
+ $array_expected = array('foo' => 'Drupal block theme');
+ drupal_alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
+ $this->assertEqual($array_copy, $array_expected, t('hook_TYPE_alter() implementations ran in correct order.'));
}
}
@@ -516,7 +524,7 @@ class CommonSizeTestCase extends DrupalUnitTestCase {
/**
* Test drupal_explode_tags() and drupal_implode_tags().
*/
-class DrupalTagsHandlingTestCase extends DrupalWebTestCase {
+class DrupalTagsHandlingTestCase extends DrupalUnitTestCase {
var $validTags = array(
'Drupal' => 'Drupal',
'Drupal with some spaces' => 'Drupal with some spaces',
@@ -1739,6 +1747,37 @@ class DrupalRenderTestCase extends DrupalWebTestCase {
'@type' => var_export($element['#type'], TRUE),
)));
}
+
+ /**
+ * Tests caching of an empty render item.
+ */
+ function testDrupalRenderCache() {
+ // Force a request via GET.
+ $request_method = $_SERVER['REQUEST_METHOD'];
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ // Create an empty element.
+ $test_element = array(
+ '#cache' => array(
+ 'cid' => 'render_cache_test',
+ ),
+ '#markup' => '',
+ );
+
+ // Render the element and confirm that it goes through the rendering
+ // process (which will set $element['#printed']).
+ $element = $test_element;
+ drupal_render($element);
+ $this->assertTrue(isset($element['#printed']), t('No cache hit'));
+
+ // Render the element again and confirm that it is retrieved from the cache
+ // instead (so $element['#printed'] will not be set).
+ $element = $test_element;
+ drupal_render($element);
+ $this->assertFalse(isset($element['#printed']), t('Cache hit'));
+
+ // Restore the previous request method.
+ $_SERVER['REQUEST_METHOD'] = $request_method;
+ }
}
/**
@@ -2064,7 +2103,7 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase {
function assertError($error, $group, $function, $file, $message = NULL) {
$this->assertEqual($error['group'], $group, t("Group was %group", array('%group' => $group)));
$this->assertEqual($error['caller']['function'], $function, t("Function was %function", array('%function' => $function)));
- $this->assertEqual(basename($error['caller']['file']), $file, t("File was %file", array('%file' => $file)));
+ $this->assertEqual(drupal_basename($error['caller']['file']), $file, t("File was %file", array('%file' => $file)));
if (isset($message)) {
$this->assertEqual($error['message'], $message, t("Message was %message", array('%message' => $message)));
}
@@ -2074,7 +2113,7 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase {
/**
* Test the drupal_parse_info_file() API function.
*/
-class ParseInfoFilesTestCase extends DrupalWebTestCase {
+class ParseInfoFilesTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Parsing .info files',
@@ -2333,8 +2372,10 @@ class DrupalJSONTest extends DrupalUnitTestCase {
$str .= chr($i);
}
// Characters that must be escaped.
- $html_unsafe = array('<', '>', '&');
- $html_unsafe_escaped = array('\u003c', '\u003e', '\u0026');
+ // We check for unescaped " separately.
+ $html_unsafe = array('<', '>', '\'', '&');
+ // The following are the encoded forms of: < > ' & "
+ $html_unsafe_escaped = array('\u003C', '\u003E', '\u0027', '\u0026', '\u0022');
// Verify there aren't character encoding problems with the source string.
$this->assertIdentical(strlen($str), 128, t('A string with the full ASCII table has the correct length.'));
@@ -2346,6 +2387,11 @@ class DrupalJSONTest extends DrupalUnitTestCase {
$json = drupal_json_encode($str);
$this->assertTrue(strlen($json) > strlen($str), t('A JSON encoded string is larger than the source string.'));
+ // The first and last characters should be ", and no others.
+ $this->assertTrue($json[0] == '"', t('A JSON encoded string begins with ".'));
+ $this->assertTrue($json[strlen($json) - 1] == '"', t('A JSON encoded string ends with ".'));
+ $this->assertTrue(substr_count($json, '"') == 2, t('A JSON encoded string contains exactly two ".'));
+
// Verify that encoding/decoding is reversible.
$json_decoded = drupal_json_decode($json);
$this->assertIdentical($str, $json_decoded, t('Encoding a string to JSON and decoding back results in the original string.'));