diff --git a/includes/common.inc b/includes/common.inc index 262e1c57b8591694acd0f2d97a5728a65e98b630..98713800dc88ea0c91f6dc53f492f645a2d3d74c 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -4098,7 +4098,12 @@ function drupal_region_class($region) { * happened later in the page request gets added to the page after one for * which drupal_add_js() happened earlier in the page request. * - defer: If set to TRUE, the defer attribute is set on the <script> - * tag. Defaults to FALSE. + * tag. Defaults to FALSE. Note that setting this to TRUE will disable + * preprocessing as though the 'preprocess' option was set to FALSE. + * - attributes: An associative array of attributes for the '; + $expected_2 = ''; + + $this->assertTrue(strpos($javascript, $expected_1) > 0, 'Rendered external JavaScript with correct defer attribute.'); + $this->assertTrue(strpos($javascript, $expected_2) > 0, 'Rendered internal JavaScript with correct defer attribute.'); + } + + /** + * Tests that attributes are maintained when JS aggregation is enabled. + */ + function testAggregatedAttributes() { + // Enable aggregation. + variable_set('preprocess_js', TRUE); + + $default_query_string = variable_get('css_js_query_string', '0'); + + drupal_add_js('http://example.com/script.js', array('attributes' => array('defer' => 'defer'))); + drupal_add_js('misc/collapse.js', array('attributes' => array('defer' => 'defer'))); + $javascript = drupal_get_js(); + + $expected_1 = ''; + $expected_2 = ''; + + $this->assertTrue(strpos($javascript, $expected_1) > 0, 'Rendered external JavaScript with correct defer attribute with aggregation enabled.'); + $this->assertTrue(strpos($javascript, $expected_2) > 0, 'Rendered internal JavaScript with correct defer attribute with aggregation enabled.'); + } + + /** * Test altering a JavaScript's weight via hook_js_alter(). * * @see simpletest_js_alter()