diff --git a/core/includes/common.inc b/core/includes/common.inc index a392a5a..258f5bf 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2385,17 +2385,23 @@ function drupal_load_stylesheet($file, $optimize = NULL, $reset_basepath = TRUE) if ($basepath && !file_uri_scheme($file)) { $file = $basepath . '/' . $file; } + // Store the parent base path to restore it later. + $parent_base_path = $basepath; + // Set the current base path to process possible child imports. $basepath = dirname($file); // Load the CSS stylesheet. We suppress errors because themes may specify // stylesheets in their .info.yml file that don't exist in the theme's path, // but are merely there to disable certain module CSS files. + $content = ''; if ($contents = @file_get_contents($file)) { // Return the processed stylesheet. - return drupal_load_stylesheet_content($contents, $_optimize); + $content = drupal_load_stylesheet_content($contents, $_optimize); } - return ''; + // Restore the parent base path as the file and its childen are processed. + $basepath = $parent_base_path; + return $content; } /** diff --git a/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css b/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css index 4c905f5..19323c1 100644 --- a/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css +++ b/core/modules/simpletest/files/css_test_files/css_input_with_import.css.unoptimized.css @@ -1,6 +1,16 @@ +ul, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} +.ui-icon{background-image: url(images/icon.png);} + +p, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} body { diff --git a/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css new file mode 100644 index 0000000..5ed72ee --- /dev/null +++ b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css @@ -0,0 +1,30 @@ + + +@import "../import1.css"; +@import "../import2.css"; + +body { + margin: 0; + padding: 0; + background: #edf5fa; + font: 76%/170% Verdana, sans-serif; + color: #494949; +} + +.this .is .a .test { + font: 1em/100% Verdana, sans-serif; + color: #494949; +} +.this +.is +.a +.test { +font: 1em/100% Verdana, sans-serif; +color: #494949; +} + +textarea, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} + diff --git a/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.optimized.css b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.optimized.css new file mode 100644 index 0000000..aba3b21 --- /dev/null +++ b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.optimized.css @@ -0,0 +1,6 @@ +ul,select{font:1em/160% Verdana,sans-serif;color:#494949;}.ui-icon{background-image:url(../images/icon.png);} +p,select{font:1em/160% Verdana,sans-serif;color:#494949;} +body{margin:0;padding:0;background:#edf5fa;font:76%/170% Verdana,sans-serif;color:#494949;}.this .is .a .test{font:1em/100% Verdana,sans-serif;color:#494949;}.this +.is +.a +.test{font:1em/100% Verdana,sans-serif;color:#494949;}textarea,select{font:1em/160% Verdana,sans-serif;color:#494949;} diff --git a/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.unoptimized.css b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.unoptimized.css new file mode 100644 index 0000000..50fb4a8 --- /dev/null +++ b/core/modules/simpletest/files/css_test_files/css_subfolder/css_input_with_import.css.unoptimized.css @@ -0,0 +1,40 @@ + + + +ul, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} +.ui-icon{background-image: url(../images/icon.png);} + +p, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} + + +body { + margin: 0; + padding: 0; + background: #edf5fa; + font: 76%/170% Verdana, sans-serif; + color: #494949; +} + +.this .is .a .test { + font: 1em/100% Verdana, sans-serif; + color: #494949; +} +.this +.is +.a +.test { +font: 1em/100% Verdana, sans-serif; +color: #494949; +} + +textarea, select { + font: 1em/160% Verdana, sans-serif; + color: #494949; +} + diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsUnitTest.php index 5ab3c0a..d41800b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsUnitTest.php @@ -38,26 +38,30 @@ function testLoadCssBasic() { $testfiles = array( 'css_input_without_import.css', 'css_input_with_import.css', + 'css_subfolder/css_input_with_import.css', 'comment_hacks.css' ); $path = drupal_get_path('module', 'simpletest') . '/files/css_test_files'; foreach ($testfiles as $file) { - $expected = file_get_contents("$path/$file.unoptimized.css"); - $unoptimized_output = drupal_load_stylesheet("$path/$file.unoptimized.css", FALSE); + $file_path = $path . '/' . $file; + $file_url = $GLOBALS['base_url'] . '/' . $file_path; + + $expected = file_get_contents($file_path . '.unoptimized.css'); + $unoptimized_output = drupal_load_stylesheet($file_path, FALSE); $this->assertEqual($unoptimized_output, $expected, format_string('Unoptimized CSS file has expected contents (@file)', array('@file' => $file))); - $expected = file_get_contents("$path/$file.optimized.css"); - $optimized_output = drupal_load_stylesheet("$path/$file", TRUE); + $expected = file_get_contents($file_path . '.optimized.css'); + $optimized_output = drupal_load_stylesheet($file_path, TRUE); $this->assertEqual($optimized_output, $expected, format_string('Optimized CSS file has expected contents (@file)', array('@file' => $file))); // Repeat the tests by accessing the stylesheets by URL. - $expected = file_get_contents("$path/$file.unoptimized.css"); - $unoptimized_output_url = drupal_load_stylesheet($GLOBALS['base_url'] . "/$path/$file.unoptimized.css", FALSE); - $this->assertEqual($unoptimized_output, $expected, format_string('Unoptimized CSS file (loaded from an URL) has expected contents (@file)', array('@file' => $file))); + $expected = file_get_contents($file_path . '.unoptimized.css'); + $unoptimized_output_url = drupal_load_stylesheet($file_url, FALSE); + $this->assertEqual($unoptimized_output_url, $expected, format_string('Unoptimized CSS file (loaded from an URL) has expected contents (@file)', array('@file' => $file))); - $expected = file_get_contents("$path/$file.optimized.css"); - $optimized_output = drupal_load_stylesheet($GLOBALS['base_url'] . "/$path/$file", TRUE); - $this->assertEqual($optimized_output, $expected, format_string('Optimized CSS file (loaded from an URL) has expected contents (@file)', array('@file' => $file))); + $expected = file_get_contents($file_path . '.optimized.css'); + $optimized_output_url = drupal_load_stylesheet($file_url, TRUE); + $this->assertEqual($optimized_output_url, $expected, format_string('Optimized CSS file (loaded from an URL) has expected contents (@file)', array('@file' => $file))); } } }