1 common.test CommonJavaScriptTestCase::testAggregationOrder()

Tests JavaScript aggregation when files are added to a different scope.

File

core/modules/simpletest/tests/common.test, line 1489
Tests for common.inc functionality.

Class

CommonJavaScriptTestCase
Tests for the JavaScript system.

Code

function testAggregationOrder() {
  // Enable JavaScript aggregation.
  config_set('system.core', 'preprocess_js', 1);
  backdrop_static_reset('backdrop_add_js');

  // Add two JavaScript files to the current request and build the cache.
  backdrop_add_js('core/misc/ajax.js');
  backdrop_add_js('core/misc/autocomplete.js');

  $js_items = backdrop_add_js();
  backdrop_build_js_cache(array(
    'core/misc/ajax.js' => $js_items['core/misc/ajax.js'],
    'core/misc/autocomplete.js' => $js_items['core/misc/autocomplete.js']
  ));

  // Store the expected key for the first item in the cache.
  $cache = array_keys(state_get('js_cache_files', array()));
  $expected_key = $cache[0];

  // Reset variables and add a file in a different scope first.
  state_set('js_cache_files', FALSE);
  backdrop_static_reset('backdrop_add_js');
  backdrop_add_js('some/custom/javascript_file.js', array('scope' => 'footer'));
  backdrop_add_js('core/misc/ajax.js');
  backdrop_add_js('core/misc/autocomplete.js');

  // Rebuild the cache.
  $js_items = backdrop_add_js();
  backdrop_build_js_cache(array(
    'core/misc/ajax.js' => $js_items['core/misc/ajax.js'],
    'core/misc/autocomplete.js' => $js_items['core/misc/autocomplete.js']
  ));

  // Compare the expected key for the first file to the current one.
  $cache = array_keys(state_get('js_cache_files', array()));
  $key = $cache[0];
  $this->assertEqual($key, $expected_key, 'JavaScript aggregation is not affected by ordering in different scopes.');
}