summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-07-10 05:45:56 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-07-10 05:45:56 +0000
commitffc8cab84b79857e46849ed80a6de89a03defc68 (patch)
tree5eab30ddd31add1fb7ee0b49dc08da797244c603 /modules
parent976336e2f874192a7a5c720e9f93b61b6a05cf3b (diff)
downloadbrdo-ffc8cab84b79857e46849ed80a6de89a03defc68.tar.gz
brdo-ffc8cab84b79857e46849ed80a6de89a03defc68.tar.bz2
#505528 by Damien Tournoud and Rob Loach: Ensure proper weight of JS files.
Diffstat (limited to 'modules')
-rw-r--r--modules/simpletest/tests/common.test40
1 files changed, 40 insertions, 0 deletions
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 229b91c21..1892de1b5 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -560,6 +560,46 @@ class JavaScriptTestCase extends DrupalWebTestCase {
}
/**
+ * Test JavaScript ordering.
+ */
+ function testRenderOrder() {
+ // Add a bunch of JavaScript in strange ordering.
+ drupal_add_js('(function($){alert("Weight 5 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));
+ drupal_add_js('(function($){alert("Weight 0 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
+ drupal_add_js('(function($){alert("Weight 0 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
+ drupal_add_js('(function($){alert("Weight -8 #1");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
+ drupal_add_js('(function($){alert("Weight -8 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
+ drupal_add_js('(function($){alert("Weight -8 #3");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
+ drupal_add_js('(function($){alert("Weight -8 #4");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => -8));
+ drupal_add_js('(function($){alert("Weight 5 #2");})(jQuery);', array('type' => 'inline', 'scope' => 'footer', 'weight' => 5));
+ drupal_add_js('(function($){alert("Weight 0 #3");})(jQuery);', array('type' => 'inline', 'scope' => 'footer'));
+
+ // Construct the expected result from the regex.
+ $expected = array(
+ "-8 #1",
+ "-8 #2",
+ "-8 #3",
+ "-8 #4",
+ "0 #1",
+ "0 #2",
+ "0 #3",
+ "5 #1",
+ "5 #2",
+ );
+
+ // Retrieve the rendered JavaScript and test against the regex.
+ $js = drupal_get_js('footer');
+ $matches = array();
+ if (preg_match_all('/Weight\s([-0-9]+\s[#0-9]+)/', $js, $matches)) {
+ $result = $matches[1];
+ }
+ else {
+ $result = array();
+ }
+ $this->assertIdentical($result, $expected, t('JavaScript is added in the expected weight order.'));
+ }
+
+ /**
* Test rendering the JavaScript with a file's weight above jQuery's.
*/
function testRenderDifferentWeight() {