diff --git a/core/includes/common.inc b/core/includes/common.inc
index 4c8695324e2..383dd29a37c 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -3759,15 +3759,15 @@ function drupal_region_class($region) {
* else being the same, JavaScript added by a call to drupal_add_js() that
* 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.
- * - async: If set to TRUE, the async attribute is set on the <script>
- * tag. Defaults to FALSE.
* - cache: If set to FALSE, the JavaScript file is loaded anew on every page
* call; in other words, it is not cached. Used only when 'type' references
* a JavaScript file. Defaults to TRUE.
* - preprocess: If TRUE and JavaScript aggregation is enabled, the script
* file will be aggregated. Defaults to TRUE.
+ * - attributes: An associative array of attributes for the ';
- $expected_2 = '';
-
- $this->assertTrue(strpos($javascript, $expected_1) > 0, 'Rendered external JavaScript with correct async attribute.');
- $this->assertTrue(strpos($javascript, $expected_2) > 0, 'Rendered internal JavaScript with correct async attribute.');
- }
-
- /**
- * Tests adding external JavaScript Files with the defer attribute.
- */
- function testDeferAttribute() {
- $default_query_string = variable_get('css_js_query_string', '0');
-
- drupal_add_library('system', 'drupal');
- drupal_add_js('http://example.com/script.js', array('defer' => TRUE));
- drupal_add_js('core/misc/collapse.js', array('defer' => TRUE));
+ drupal_add_js('http://example.com/script.js', array('attributes' => array('defer' => 'defer')));
+ drupal_add_js('core/misc/collapse.js', array('attributes' => array('defer' => 'defer')));
$javascript = drupal_get_js();
$expected_1 = '';
@@ -132,6 +114,27 @@ class JavaScriptTest extends WebTestBase {
$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.
+ config('system.performance')->set('preprocess.js', 1)->save();
+
+ $default_query_string = variable_get('css_js_query_string', '0');
+
+ drupal_add_library('system', 'drupal');
+ drupal_add_js('http://example.com/script.js', array('attributes' => array('defer' => 'defer')));
+ drupal_add_js('core/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.');
+ }
+
/**
* Tests drupal_get_js() for JavaScript settings.
*/