From 47f1ff523d738eb7d2e66ee7f689f62c5d6964de Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 30 Apr 2012 21:42:08 -0700 Subject: Issue #1404380 by msonnabaum, xjm, mjpa: Fixed Unnecessary aggregation of CSS/JS. --- modules/simpletest/tests/common.test | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'modules') diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 5ce0d95cd..437b67cd1 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -1342,6 +1342,48 @@ class JavaScriptTestCase extends DrupalWebTestCase { $this->assertEqual($javascript['misc/collapse.js']['weight'], 2, t('Adding a JavaScript file with a different weight caches the given weight.')); } + /** + * Tests JavaScript aggregation when files are added to a different scope. + */ + function testAggregationOrder() { + // Enable JavaScript aggregation. + variable_set('preprocess_js', 1); + drupal_static_reset('drupal_add_js'); + + // Add two JavaScript files to the current request and build the cache. + drupal_add_js('misc/ajax.js'); + drupal_add_js('misc/autocomplete.js'); + + $js_items = drupal_add_js(); + drupal_build_js_cache(array( + 'misc/ajax.js' => $js_items['misc/ajax.js'], + 'misc/autocomplete.js' => $js_items['misc/autocomplete.js'] + )); + + // Store the expected key for the first item in the cache. + $cache = array_keys(variable_get('drupal_js_cache_files', array())); + $expected_key = $cache[0]; + + // Reset variables and add a file in a different scope first. + variable_del('drupal_js_cache_files'); + drupal_static_reset('drupal_add_js'); + drupal_add_js('some/custom/javascript_file.js', array('scope' => 'footer')); + drupal_add_js('misc/ajax.js'); + drupal_add_js('misc/autocomplete.js'); + + // Rebuild the cache. + $js_items = drupal_add_js(); + drupal_build_js_cache(array( + 'misc/ajax.js' => $js_items['misc/ajax.js'], + 'misc/autocomplete.js' => $js_items['misc/autocomplete.js'] + )); + + // Compare the expected key for the first file to the current one. + $cache = array_keys(variable_get('drupal_js_cache_files', array())); + $key = $cache[0]; + $this->assertEqual($key, $expected_key, 'JavaScript aggregation is not affected by ordering in different scopes.'); + } + /** * Test JavaScript ordering. */ -- cgit v1.2.3