diff options
Diffstat (limited to 'modules/simpletest/tests')
-rw-r--r-- | modules/simpletest/tests/bootstrap.test | 25 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 27 |
2 files changed, 50 insertions, 2 deletions
diff --git a/modules/simpletest/tests/bootstrap.test b/modules/simpletest/tests/bootstrap.test index d8a9d8c1b..99bdca774 100644 --- a/modules/simpletest/tests/bootstrap.test +++ b/modules/simpletest/tests/bootstrap.test @@ -426,3 +426,28 @@ class BootstrapResettableStaticTestCase extends DrupalUnitTestCase { $this->assertEqual($var, 'foo', t('Variable was reset after second invocation of global reset.')); } } + +/** + * Test miscellaneous functions in bootstrap.inc. + */ +class BootstrapMiscTestCase extends DrupalUnitTestCase { + + public static function getInfo() { + return array( + 'name' => 'Miscellaneous bootstrap unit tests', + 'description' => 'Test miscellaneous functions in bootstrap.inc.', + 'group' => 'Bootstrap', + ); + } + + /** + * Test miscellaneous functions in bootstrap.inc. + */ + function testMisc() { + // Test drupal_array_merge_deep(). + $link_options_1 = array('fragment' => 'x', 'attributes' => array('title' => 'X', 'class' => array('a', 'b')), 'language' => 'en'); + $link_options_2 = array('fragment' => 'y', 'attributes' => array('title' => 'Y', 'class' => array('c', 'd')), 'html' => TRUE); + $expected = array('fragment' => 'y', 'attributes' => array('title' => 'Y', 'class' => array('a', 'b', 'c', 'd')), 'language' => 'en', 'html' => TRUE); + $this->assertIdentical(drupal_array_merge_deep($link_options_1, $link_options_2), $expected, t('drupal_array_merge_deep() returned a properly merged array.')); + } +} diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 83f2e9734..9dc2532ab 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1195,11 +1195,34 @@ class JavaScriptTestCase extends DrupalWebTestCase { * Test drupal_get_js() for JavaScript settings. */ function testHeaderSetting() { - drupal_add_js(array('testSetting' => 'testValue'), 'setting'); + // Only the second of these two entries should appear in Drupal.settings. + drupal_add_js(array('commonTest' => 'commonTestShouldNotAppear'), 'setting'); + drupal_add_js(array('commonTest' => 'commonTestShouldAppear'), 'setting'); + // All three of these entries should appear in Drupal.settings. + drupal_add_js(array('commonTestArray' => array('commonTestValue0')), 'setting'); + drupal_add_js(array('commonTestArray' => array('commonTestValue1')), 'setting'); + drupal_add_js(array('commonTestArray' => array('commonTestValue2')), 'setting'); + // Only the second of these two entries should appear in Drupal.settings. + drupal_add_js(array('commonTestArray' => array('key' => 'commonTestOldValue')), 'setting'); + drupal_add_js(array('commonTestArray' => array('key' => 'commonTestNewValue')), 'setting'); + $javascript = drupal_get_js('header'); $this->assertTrue(strpos($javascript, 'basePath') > 0, t('Rendered JavaScript header returns basePath setting.')); - $this->assertTrue(strpos($javascript, 'testSetting') > 0, t('Rendered JavaScript header returns custom setting.')); $this->assertTrue(strpos($javascript, 'misc/jquery.js') > 0, t('Rendered JavaScript header includes jQuery.')); + + // Test whether drupal_add_js can be used to override a previous setting. + $this->assertTrue(strpos($javascript, 'commonTestShouldAppear') > 0, t('Rendered JavaScript header returns custom setting.')); + $this->assertTrue(strpos($javascript, 'commonTestShouldNotAppear') === FALSE, t('drupal_add_js() correctly overrides a custom setting.')); + + // Test whether drupal_add_js can be used to add numerically indexed values + // to an array. + $array_values_appear = strpos($javascript, 'commonTestValue0') > 0 && strpos($javascript, 'commonTestValue1') > 0 && strpos($javascript, 'commonTestValue2') > 0; + $this->assertTrue($array_values_appear, t('drupal_add_js() correctly adds settings to the end of an indexed array.')); + + // Test whether drupal_add_js can be used to override the entry for an + // existing key in an associative array. + $associative_array_override = strpos($javascript, 'commonTestNewValue') > 0 && strpos($javascript, 'commonTestOldValue') === FALSE; + $this->assertTrue($associative_array_override, t('drupal_add_js() correctly overrides settings within an associative array.')); } /** |