diff --git a/core/modules/system/tests/common.test b/core/modules/system/tests/common.test index 9b6e2be..7488444 100644 --- a/core/modules/system/tests/common.test +++ b/core/modules/system/tests/common.test @@ -1125,8 +1125,7 @@ class CommonJavaScriptTestCase extends WebTestBase { // Disable preprocessing $config = config('system.performance'); $this->preprocess_js = $config->get('preprocess_js'); - $config->set('preprocess_js', 0); - $config->save(); + $config->set('preprocess_js', 0)->save(); // Reset drupal_add_js() and drupal_add_library() statics before each test. drupal_static_reset('drupal_add_js'); @@ -1135,23 +1134,20 @@ class CommonJavaScriptTestCase extends WebTestBase { function tearDown() { // Restore configured value for JavaScript preprocessing. - $config = config('system.performance'); - $config->set('preprocess_js', $this->preprocess_js); - $config->save(); + config('system.performance') + ->set('preprocess_js', $this->preprocess_js) + ->save(); parent::tearDown(); } /** - * Test default JavaScript is empty. + * Test Drupal's javascript. */ - function testDefault() { + function testAll() { + // Test default JavaScript is empty. $this->assertEqual(array(), drupal_add_js(), t('Default JavaScript is empty.')); - } - /** - * Test adding a JavaScript file. - */ - function testAddFile() { + // Test adding a JavaScript file. $javascript = drupal_add_js('core/misc/collapse.js'); $this->assertTrue(array_key_exists('core/misc/jquery.js', $javascript), t('jQuery is added when a file is added.')); $this->assertTrue(array_key_exists('core/misc/drupal.js', $javascript), t('Drupal.js is added when file is added.')); @@ -1160,30 +1156,18 @@ class CommonJavaScriptTestCase extends WebTestBase { $this->assertEqual(base_path(), $javascript['settings']['data'][0]['basePath'], t('Base path JavaScript setting is correctly set.')); $this->assertIdentical($GLOBALS['script_path'], $javascript['settings']['data'][1]['scriptPath'], t('Script path JavaScript setting is correctly set.')); $this->assertIdentical('', $javascript['settings']['data'][2]['pathPrefix'], t('Path prefix JavaScript setting is correctly set.')); - } - /** - * Test adding settings. - */ - function testAddSetting() { + // Test adding settings. $javascript = drupal_add_js(array('drupal' => 'rocks', 'dries' => 280342800), 'setting'); $this->assertEqual(280342800, $javascript['settings']['data'][3]['dries'], t('JavaScript setting is set correctly.')); $this->assertEqual('rocks', $javascript['settings']['data'][3]['drupal'], t('The other JavaScript setting is set correctly.')); - } - /** - * Tests adding an external JavaScript File. - */ - function testAddExternal() { + // Tests adding an external JavaScript File. $path = 'http://example.com/script.js'; $javascript = drupal_add_js($path, 'external'); $this->assertTrue(array_key_exists('http://example.com/script.js', $javascript), t('Added an external JavaScript file.')); - } - /** - * Test drupal_get_js() for JavaScript settings. - */ - function testHeaderSetting() { + // Test drupal_get_js() for JavaScript settings. // Only the second of these two entries should appear in Drupal.settings. drupal_add_js(array('commonTest' => 'commonTestShouldNotAppear'), 'setting'); drupal_add_js(array('commonTest' => 'commonTestShouldAppear'), 'setting'); @@ -1214,79 +1198,46 @@ class CommonJavaScriptTestCase extends WebTestBase { // existing key in an associative array. $associative_array_override = strpos($javascript, 'commonTestNewValue') > 0 && strpos($javascript, 'commonTestOldValue') === FALSE; $this->assertTrue($associative_array_override, t('drupal_add_js() correctly overrides settings within an associative array.')); - } - /** - * Test to see if resetting the JavaScript empties the cache. - */ - function testReset() { + // Test to see if resetting the JavaScript empties the cache. + drupal_add_js('core/misc/collapse.js'); drupal_static_reset('drupal_add_js'); $this->assertEqual(array(), drupal_add_js(), t('Resetting the JavaScript correctly empties the cache.')); - } - /** - * Test adding inline scripts. - */ - function testAddInline() { + // Test adding inline scripts. $inline = 'jQuery(function () { });'; $javascript = drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer')); $this->assertTrue(array_key_exists('core/misc/jquery.js', $javascript), t('jQuery is added when inline scripts are added.')); $data = end($javascript); $this->assertEqual($inline, $data['data'], t('Inline JavaScript is correctly added to the footer.')); - } - /** - * Test rendering an external JavaScript file. - */ - function testRenderExternal() { + // Test rendering an external JavaScript file. $external = 'http://example.com/example.js'; drupal_add_js($external, 'external'); $javascript = drupal_get_js(); // Local files have a base_path() prefix, external files should not. $this->assertTrue(strpos($javascript, 'src="' . $external) > 0, t('Rendering an external JavaScript file.')); - } - /** - * Test drupal_get_js() with a footer scope. - */ - function testFooterHTML() { + // Test drupal_get_js() with a footer scope. $inline = 'jQuery(function () { });'; drupal_add_js($inline, array('type' => 'inline', 'scope' => 'footer')); $javascript = drupal_get_js('footer'); $this->assertTrue(strpos($javascript, $inline) > 0, t('Rendered JavaScript footer returns the inline code.')); - } - /** - * Test drupal_add_js() sets preproccess to false when cache is set to false. - */ - function testNoCache() { + // Test drupal_add_js() sets preproccess to false when cache is set to false. $javascript = drupal_add_js('core/misc/collapse.js', array('cache' => FALSE)); $this->assertFalse($javascript['core/misc/collapse.js']['preprocess'], t('Setting cache to FALSE sets proprocess to FALSE when adding JavaScript.')); - } - /** - * Test adding a JavaScript file with a different group. - */ - function testDifferentGroup() { + // Test adding a JavaScript file with a different group. $javascript = drupal_add_js('core/misc/collapse.js', array('group' => JS_THEME)); $this->assertEqual($javascript['core/misc/collapse.js']['group'], JS_THEME, t('Adding a JavaScript file with a different group caches the given group.')); - } - /** - * Test adding a JavaScript file with a different weight. - */ - function testDifferentWeight() { + // Test adding a JavaScript file with a different weight. $javascript = drupal_add_js('core/misc/collapse.js', array('weight' => 2)); $this->assertEqual($javascript['core/misc/collapse.js']['weight'], 2, t('Adding a JavaScript file with a different weight caches the given weight.')); - } - /** - * Test adding JavaScript within conditional comments. - * - * @see drupal_pre_render_conditional_comments() - */ - function testBrowserConditionalComments() { + // Test adding JavaScript within conditional comments. $default_query_string = variable_get('css_js_query_string', '0'); drupal_add_js('core/misc/collapse.js', array('browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE))); @@ -1298,22 +1249,14 @@ class CommonJavaScriptTestCase extends WebTestBase { $this->assertTrue(strpos($javascript, $expected_1) > 0, t('Rendered JavaScript within downlevel-hidden conditional comments.')); $this->assertTrue(strpos($javascript, $expected_2) > 0, t('Rendered JavaScript within downlevel-revealed conditional comments.')); - } - /** - * Test JavaScript versioning. - */ - function testVersionQueryString() { + // Test JavaScript versioning. drupal_add_js('core/misc/collapse.js', array('version' => 'foo')); drupal_add_js('core/misc/ajax.js', array('version' => 'bar')); $javascript = drupal_get_js(); $this->assertTrue(strpos($javascript, 'core/misc/collapse.js?v=foo') > 0 && strpos($javascript, 'core/misc/ajax.js?v=bar') > 0 , t('JavaScript version identifiers correctly appended to URLs')); - } - /** - * Test JavaScript grouping and aggregation. - */ - function testAggregation() { + // Test JavaScript grouping and aggregation. $default_query_string = variable_get('css_js_query_string', '0'); // To optimize aggregation, items with the 'every_page' option are ordered @@ -1350,12 +1293,8 @@ class CommonJavaScriptTestCase extends WebTestBase { '', )); $this->assertTrue(strpos($javascript, $expected) > 0, t('JavaScript is aggregated in the expected groups and order.')); - } - /** - * Tests JavaScript aggregation when files are added to a different scope. - */ - function testAggregationOrder() { + // Tests JavaScript aggregation when files are added to a different scope. // Enable JavaScript aggregation. config('system.performance')->set('preprocess_js', 1)->save(); drupal_static_reset('drupal_add_js'); @@ -1392,12 +1331,8 @@ class CommonJavaScriptTestCase extends WebTestBase { $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. - */ - function testRenderOrder() { + // Test JavaScript ordering. // 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')); @@ -1434,26 +1369,16 @@ class CommonJavaScriptTestCase extends WebTestBase { $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() { + // Test rendering the JavaScript with a file's weight above jQuery's. // JavaScript files are sorted first by group, then by the 'every_page' // flag, then by weight (see drupal_sort_css_js()), so to test the effect of // weight, we need the other two options to be the same. drupal_add_js('core/misc/collapse.js', array('group' => JS_LIBRARY, 'every_page' => TRUE, 'weight' => -21)); $javascript = drupal_get_js(); $this->assertTrue(strpos($javascript, 'core/misc/collapse.js') < strpos($javascript, 'core/misc/jquery.js'), t('Rendering a JavaScript file above jQuery.')); - } - /** - * Test altering a JavaScript's weight via hook_js_alter(). - * - * @see simpletest_js_alter() - */ - function testAlter() { + // Test altering a JavaScript's weight via hook_js_alter(). // Add both tableselect.js and simpletest.js, with a larger weight on SimpleTest. drupal_add_js('core/misc/tableselect.js'); drupal_add_js(drupal_get_path('module', 'simpletest') . '/simpletest.js', array('weight' => 9999));