function CascadingStylesheetsUnitTest::testLoadCssBasic

Tests CSS loading via drupal_load_stylesheet().

This test loads CSS files with and without CSS optimization. Known tests:

File

drupal/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsUnitTest.php, line 33
Definition of Drupal\system\Tests\Common\CascadingStylesheetsUnitTest.

Class

CascadingStylesheetsUnitTest
Tests CSS functions.

Namespace

Drupal\system\Tests\Common

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',
    '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);
    $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);
    $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("{$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,
    )));
  }
}