summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/common.test
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2008-10-22 19:39:36 +0000
committerDries Buytaert <dries@buytaert.net>2008-10-22 19:39:36 +0000
commitd1d3ce0be71254fd95991cefd508f4246a33e2f9 (patch)
tree7de1478c9774decad1dc6c2685a2cedaa2231b8e /modules/simpletest/tests/common.test
parente83bf94b5ba1d30cd8e2158bf59bffedc0565102 (diff)
downloadbrdo-d1d3ce0be71254fd95991cefd508f4246a33e2f9.tar.gz
brdo-d1d3ce0be71254fd95991cefd508f4246a33e2f9.tar.bz2
- Patch #315797 by mfer, Rob Loach, et al: rework the parameter of drupal_add_js.
Diffstat (limited to 'modules/simpletest/tests/common.test')
-rw-r--r--modules/simpletest/tests/common.test103
1 files changed, 103 insertions, 0 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 0d7ad985c..74e053cf9 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -253,6 +253,109 @@ class DrupalSetContentTestCase extends DrupalWebTestCase {
}
/**
+ * Tests for the JavaScript system.
+ */
+class JavaScriptTestCase extends DrupalWebTestCase {
+ /**
+ * Implementation of getInfo().
+ */
+ function getInfo() {
+ return array(
+ 'name' => t('JavaScript'),
+ 'description' => t("Tests the JavaScript system."),
+ 'group' => t('System')
+ );
+ }
+
+ /**
+ * Implementation of setUp().
+ */
+ function setUp() {
+ // Reset drupal_add_js() before each test.
+ drupal_add_js(NULL, NULL, TRUE);
+ }
+
+ /**
+ * Test default JavaScript is empty.
+ */
+ function testDefault() {
+ $this->assertEqual(array(), drupal_add_js(), t('Default JavaScript is empty.'));
+ }
+
+ /**
+ * Test adding a JavaScript file.
+ */
+ function testAddFile() {
+ drupal_add_js('misc/collapse.js');
+ $javascript = drupal_add_js();
+ $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['core']), t('jQuery is added when a file is added.'));
+ $this->assertTrue(array_key_exists('misc/drupal.js', $javascript['header']['core']), t('Drupal.js is added when file is added.'));
+ $this->assertTrue(array_key_exists('misc/collapse.js', $javascript['header']['module']), t('JavaScript files are correctly added.'));
+ $this->assertEqual(base_path(), $javascript['header']['setting'][0]['basePath'], t('Base path JavaScript setting is correctly set.'));
+ }
+
+ /**
+ * Test adding settings.
+ */
+ function testAddSetting() {
+ drupal_add_js(array('drupal' => 'rocks', 'dries' => 280342800), 'setting');
+ $javascript = drupal_add_js();
+ $this->assertEqual(280342800, $javascript['header']['setting'][1]['dries'], t('JavaScript setting is set correctly.'));
+ $this->assertEqual('rocks', $javascript['header']['setting'][1]['drupal'], t('The other JavaScript setting is set correctly.'));
+ }
+
+ /**
+ * Test drupal_get_js() for JavaScript settings.
+ */
+ function testHeaderSetting() {
+ drupal_add_js(array('testSetting' => 'testValue'), '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 to see if resetting the JavaScript empties the cache.
+ */
+ function testReset() {
+ drupal_add_js('misc/collapse.js');
+ drupal_add_js(NULL, NULL, TRUE);
+ $this->assertEqual(array(), drupal_add_js(), t('Resetting the JavaScript correctly empties the cache.'));
+ }
+
+ /**
+ * Test adding inline scripts.
+ */
+ function testAddInline() {
+ $inline = '$(document).ready(function(){});';
+ drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer'));
+ $javascript = drupal_add_js();
+ $this->assertTrue(array_key_exists('misc/jquery.js', $javascript['header']['core']), t('jQuery is added when inline scripts are added.'));
+ $this->assertEqual($inline, $javascript['footer']['inline'][0]['code'], t('Inline JavaScript is correctly added to the footer.'));
+ }
+
+ /**
+ * Test drupal_get_js() with a footer scope.
+ */
+ function testFooterHTML() {
+ $inline = '$(document).ready(function(){});';
+ drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer'));
+ $javascript = drupal_get_js('footer');
+ $this->assertTrue(strpos($javascript, $inline) > 0, t('Rendered JavaScript footer returns the inline code.'));
+ }
+
+ /**
+ * Test drupal_add_js() sets preproccess to false when cache is set to false.
+ */
+ function testNoCache() {
+ drupal_add_js('misc/collapse.js', array('cache' => FALSE));
+ $javascript = drupal_add_js();
+ $this->assertTrue(!$javascript['header']['module']['misc/collapse.js']['preprocess'], t('Setting cache to FALSE sets proprocess to FALSE when adding JavaScript.'));
+ }
+}
+
+/**
* Tests Drupal error and exception handlers.
*/
class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {