summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc32
-rw-r--r--modules/simpletest/tests/common_test.css3
-rw-r--r--modules/simpletest/tests/common_test.print.css3
-rw-r--r--modules/simpletest/tests/theme.test23
-rw-r--r--themes/tests/test_theme/test_theme.info14
5 files changed, 68 insertions, 7 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 8fda660e9..c4cff1c5c 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3116,12 +3116,24 @@ function drupal_pre_render_styles($elements) {
elseif ($group['preprocess']) {
$import = array();
foreach ($group['items'] as $item) {
- // The dummy query string needs to be added to the URL to control
- // browser-caching. IE7 does not support a media type on the @import
- // statement, so we instead specify the media for the group on the
- // STYLE tag.
- $query_string_separator = (strpos($item['data'], '?') !== FALSE) ? '&' : '?';
- $import[] = '@import url("' . check_plain(file_create_url($item['data']) . $query_string_separator . $query_string) . '");';
+ // A theme's .info file may have an entry for a file that doesn't
+ // exist as a way of overriding a module or base theme CSS file from
+ // being added to the page. Normally, file_exists() calls that need
+ // to run for every page request should be minimized, but this one
+ // is okay, because it only runs when CSS aggregation is disabled.
+ // On a server under heavy enough load that file_exists() calls need
+ // to be minimized, CSS aggregation should be enabled, in which case
+ // this code is not run. When aggregation is enabled,
+ // drupal_load_stylesheet() checks file_exists(), but only when
+ // building the aggregate file, which is then reused for many page
+ // requests.
+ if (file_exists($item['data'])) {
+ // The dummy query string needs to be added to the URL to control
+ // browser-caching. IE7 does not support a media type on the
+ // @import statement, so we instead specify the media for the
+ // group on the STYLE tag.
+ $import[] = '@import url("' . check_plain(file_create_url($item['data']) . '?' . $query_string) . '");';
+ }
}
// In addition to IE's limit of 31 total CSS inclusion tags, it also
// has a limit of 31 @import statements per STYLE tag.
@@ -3140,6 +3152,14 @@ function drupal_pre_render_styles($elements) {
else {
foreach ($group['items'] as $item) {
$element = $link_element_defaults;
+ // We do not check file_exists() here, because this code runs for
+ // files whose 'preprocess' is set to FALSE, and therefore, even
+ // when aggregation is enabled, and we want to avoid needlessly
+ // taxing a server that may be under heavy load. The file_exists()
+ // performed above for files whose 'preprocess' is TRUE is done for
+ // the benefit of theme .info files, but code that deals with files
+ // whose 'preprocess' is FALSE is responsible for ensuring the file
+ // exists.
// The dummy query string needs to be added to the URL to control
// browser-caching.
$query_string_separator = (strpos($item['data'], '?') !== FALSE) ? '&' : '?';
diff --git a/modules/simpletest/tests/common_test.css b/modules/simpletest/tests/common_test.css
new file mode 100644
index 000000000..023eae62d
--- /dev/null
+++ b/modules/simpletest/tests/common_test.css
@@ -0,0 +1,3 @@
+/* $Id$ */
+
+/* This file is for testing CSS file inclusion, no contents are necessary. */
diff --git a/modules/simpletest/tests/common_test.print.css b/modules/simpletest/tests/common_test.print.css
new file mode 100644
index 000000000..023eae62d
--- /dev/null
+++ b/modules/simpletest/tests/common_test.print.css
@@ -0,0 +1,3 @@
+/* $Id$ */
+
+/* This file is for testing CSS file inclusion, no contents are necessary. */
diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test
index f6dea3309..00eb49b89 100644
--- a/modules/simpletest/tests/theme.test
+++ b/modules/simpletest/tests/theme.test
@@ -74,6 +74,29 @@ class ThemeUnitTest extends DrupalWebTestCase {
$this->drupalGet('theme-test/alter');
$this->assertText('The altered data is test_theme_theme_test_alter_alter was invoked.', t('The theme was able to implement an alter hook during page building before anything was rendered.'));
}
+
+ /**
+ * Ensures a theme's .info file is able to override a module CSS file from being added to the page.
+ *
+ * @see test_theme.info
+ */
+ function testCSSOverride() {
+ // Reuse the same page as in testPreprocessForSuggestions(). We're testing
+ // what is output to the HTML HEAD based on what is in a theme's .info file,
+ // so it doesn't matter what page we get, as long as it is themed with the
+ // test theme. First we test with CSS aggregation disabled.
+ variable_set('preprocess_css', 0);
+ $this->drupalGet('theme-test/suggestion');
+ $this->assertNoText('system.base.css', t('The theme\'s .info file is able to override a module CSS file from being added to the page.'));
+
+ // Also test with aggregation enabled, simply ensuring no PHP errors are
+ // triggered during drupal_build_css_cache() when a source file doesn't
+ // exist. Then allow remaining tests to continue with aggregation disabled
+ // by default.
+ variable_set('preprocess_css', 1);
+ $this->drupalGet('theme-test/suggestion');
+ variable_set('preprocess_css', 0);
+ }
}
/**
diff --git a/themes/tests/test_theme/test_theme.info b/themes/tests/test_theme/test_theme.info
index 853a501b5..06fec4ed7 100644
--- a/themes/tests/test_theme/test_theme.info
+++ b/themes/tests/test_theme/test_theme.info
@@ -3,4 +3,16 @@ name = Test theme
description = Theme for testing the theme system
core = 7.x
engine = phptemplate
-hidden = TRUE \ No newline at end of file
+hidden = TRUE
+
+; Normally, themes may list CSS files like this, and if they exist in the theme
+; folder, then they get added to the page. If they have the same file name as a
+; module CSS file, then the theme's version overrides the module's version, so
+; that the module's version is not added to the page. Additionally, a theme may
+; have an entry like this one, without having the corresponding CSS file in the
+; theme's folder, and in this case, it just stops the module's version from
+; being loaded, and does not replace it with an alternate version. We have this
+; here in order for a test to ensure that this correctly prevents the module
+; version from being loaded, and that errors aren't caused by the lack of this
+; file within the theme folder.
+stylesheets[all][] = system.base.css