function CascadingStylesheetsUnitTest::testLoadCssBasic

7.x common.test CascadingStylesheetsUnitTest::testLoadCssBasic()

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

Known tests:

File

drupal-7.x/modules/simpletest/tests/common.test, line 921
Tests for common.inc functionality.

Class

CascadingStylesheetsUnitTest
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 = drupal_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 = 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($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($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($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)));
  }
}