You are here

public function MagicCSSTestCase::testMagicCSSExcludes in Magic 7.2

Test magic_assets_exclude().

Testing to see if our regex sends back the appropriate responses.

File

./magic.test, line 103
A few tests to ensure the magic module is doing what it should be.

Class

MagicCSSTestCase
A quick test to ensure that we have the right CSS gets returned when we run our regex to selectively remove files.

Code

public function testMagicCSSExcludes() {
  module_load_include('inc', 'magic', 'includes/magic.assets');

  // A set of trials for our CSS testing.
  $tests = array(
    array(
      'removal' => array(
        ':core',
        '~:current-theme',
      ),
      'expected' => array(
        'ctools',
        'views',
        'theme',
        'admin_menu',
        'external',
        'inline',
      ),
      'message' => 'Removing core css alone.',
    ),
    array(
      'removal' => array(
        ':core',
        ':contrib',
        '~:current-theme',
      ),
      'expected' => array(
        'theme',
        'external',
        'inline',
      ),
      'message' => 'Removing core and contrib css.',
    ),
    array(
      'removal' => array(
        ':core',
        ':contrib',
        '~sites/all/modules/contrib/admin_menu*',
        '~:current-theme',
      ),
      'expected' => array(
        'theme',
        'admin_menu',
        'external',
        'inline',
      ),
      'message' => 'Removing core and contrib css, but leave admin menu.',
    ),
    array(
      'removal' => array(
        ':all',
        '~:current-theme',
      ),
      'expected' => array(
        'theme',
        'inline',
      ),
      'message' => 'Remove all CSS except for the current theme.',
    ),
  );
  foreach ($tests as $test) {
    $css = $this
      ->the_css_files();
    $expected = $this
      ->the_css_files($test['expected']);
    $steps = magic_assets_regex_steps($test['removal']);
    magic_assets_exclude($css, $steps);

    // We run this so that the array keys are the same.
    $css = array_values($css);
    $this
      ->assertEqual($expected, $css, $test['message']);
  }
}