1.20.x common.test CommonCascadingStylesheetsUnitTestCase::testLoadCssBasic()

Tests basic CSS loading with and without optimization via backdrop_load_stylesheet().

Known tests:

File

modules/simpletest/tests/common.test, line 979
Tests for common.inc functionality.

Class

CommonCascadingStylesheetsUnitTestCase
CSS Unit Tests.

Code

function testLoadCssBasic() {
  // Array of files to test living in 'simpletest/files/css_test_files/'.
  // - Original: name.css
  // - Unoptimized expected content: name.css.unoptimized.css
  // - Optimized expected content: name.css.optimized.css
  $testfiles = array(
    'css_input_without_import.css',
    'css_input_with_import.css',
    'css_subfolder/css_input_with_import.css',
    'comment_hacks.css'
  );
  $path = backdrop_get_path('module', 'simpletest') . '/files/css_test_files';
  foreach ($testfiles as $file) {
    $file_path = $path . '/' . $file;
    $file_url = $GLOBALS['base_url'] . '/' . $file_path;

    $expected = file_get_contents($file_path . '.unoptimized.css');
    $unoptimized_output = backdrop_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($file_path . '.optimized.css');
    $optimized_output = backdrop_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($file_path . '.unoptimized.css');
    $unoptimized_output_url = backdrop_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($file_path . '.optimized.css');
    $optimized_output_url = backdrop_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)));
  }
}