You are here

class AdvAggCascadingStylesheetsTestCase in Advanced CSS/JS Aggregation 7.2

Test the Drupal CSS system.

Hierarchy

Expanded class hierarchy of AdvAggCascadingStylesheetsTestCase

Related topics

File

tests/advagg.test, line 99
Tests for advagg.module.

View source
class AdvAggCascadingStylesheetsTestCase extends DrupalWebTestCase {

  /**
   * Store configured value for CSS preprocessing.
   *
   * @var bool
   */
  protected $preprocessCss = NULL;

  /**
   * Create user.
   *
   * @var object
   */
  protected $bigUser;

  /**
   * Theme settings.
   *
   * @var array
   */
  protected $themes;

  /**
   * Provide information to the UI for this test.
   */
  public static function getInfo() {
    return array(
      'name' => 'CSS',
      'description' => 'Tests adding various cascading stylesheets to the page.',
      'group' => 'AdvAgg',
    );
  }

  /**
   * Install the advagg module and include needed files.
   */
  public function setUp() {

    // Enable any modules required for the test. This should be an array of
    // module names.
    parent::setUp(array(
      'advagg',
      'php',
      'locale',
      'common_test',
      'menu_test',
      'color',
    ));

    // Include the advagg.module file.
    drupal_load('module', 'advagg');
    module_load_include('inc', 'advagg', 'advagg');

    // Set settings for testing.
    $GLOBALS['conf']['advagg_convert_absolute_to_relative_path'] = FALSE;
    $GLOBALS['conf']['advagg_convert_absolute_to_protocol_relative_path'] = FALSE;
    $GLOBALS['conf']['advagg_force_https_path'] = FALSE;
    $GLOBALS['conf']['advagg_skip_file_create_url_inside_css'] = FALSE;

    // Disable CSS preprocessing.
    $this->preprocessCss = variable_get('preprocess_css', 0);
    variable_set('preprocess_css', 0);

    // Create users.
    $this->bigUser = $this
      ->drupalCreateUser(array(
      'administer themes',
    ));

    // This tests the color module in both Bartik and Garland.
    $this->themes = array(
      'bartik' => array(
        'palette_input' => 'palette[bg]',
        'scheme' => 'slate',
        'scheme_color' => '#3b3b3b',
      ),
    );
    theme_enable(array_keys($this->themes));

    // Reset drupal_add_css() before each test.
    advagg_test_reset_statics();
  }

  /**
   * Restore any variables we set.
   */
  public function tearDown() {

    // Restore configured value for CSS preprocessing.
    variable_set('preprocess_css', $this->preprocessCss);
    parent::tearDown();
  }

  /**
   * Tests rendering the stylesheets.
   */
  public function testRenderFile() {
    foreach ($this->themes as $theme => $test_values) {
      variable_set('theme_default', $theme);
      $settings_path = 'admin/appearance/settings/' . $theme;
      $this
        ->drupalLogin($this->bigUser);
      $this
        ->drupalGet($settings_path);
      $this
        ->assertResponse(200);
      $edit['scheme'] = '';
      $edit[$test_values['palette_input']] = '#123456';
      $this
        ->drupalPost($settings_path, $edit, t('Save configuration'));

      // Reset drupal_add_css() before each test.
      $GLOBALS['conf']['advagg_convert_absolute_to_relative_path'] = FALSE;
      $GLOBALS['conf']['advagg_convert_absolute_to_protocol_relative_path'] = FALSE;
      advagg_test_reset_statics();

      // Add the css file.
      $stylesheets = variable_get('color_' . $theme . '_stylesheets', array());
      drupal_add_css($stylesheets[0]);
      $css = file_create_url($stylesheets[0]);

      // Get the render array.
      $full_css = advagg_get_css();
      $styles = drupal_render($full_css);
      $this
        ->assertTrue(strpos($styles, $css) !== FALSE, "Rendered CSS includes the added stylesheet ({$css}).");
    }

    // Reset drupal_add_css() before each test.
    advagg_test_reset_statics();

    // Add the css file.
    $css = drupal_get_path('module', 'simpletest') . '/simpletest.css';
    drupal_add_css($css);

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);
    $this
      ->assertTrue(strpos($styles, $css) > 0, "Rendered CSS includes the added stylesheet ({$css}).");

    // Verify that newlines are properly added inside style tags.
    $query_string = variable_get('css_js_query_string', '0');
    $css_processed = "<style type=\"text/css\" media=\"all\">\n@import url(\"" . check_plain(file_create_url($css)) . "?" . $query_string . "\");\n</style>";
    $this
      ->assertEqual(trim($styles), $css_processed, 'Rendered CSS includes newlines inside style tags for JavaScript use.');

    //
    // Tests rendering an external stylesheet.
    advagg_test_reset_statics();

    // Add the css file.
    $css = 'http://example.com/style.css';
    drupal_add_css($css, 'external');

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);

    // Stylesheet URL may be the href of a LINK tag or in an @import statement
    // of a STYLE tag.
    $this
      ->assertTrue(strpos($styles, 'href="' . $css) > 0 || strpos($styles, '@import url("' . $css . '")') > 0, 'Rendering an external CSS file.');

    //
    // Tests rendering inline stylesheets with preprocessing on.
    advagg_test_reset_statics();

    // Add the inline css.
    $css = 'body { padding: 0px; }';
    list($embed_prefix, $embed_suffix) = advagg_get_css_prefix_suffix();
    $css_preprocessed = '<style type="text/css" media="all">' . $embed_prefix . advagg_load_stylesheet_content($css, TRUE) . $embed_suffix . '</style>';
    drupal_add_css($css, array(
      'type' => 'inline',
    ));

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);
    $this
      ->assertEqual(trim($styles), $css_preprocessed, 'Rendering preprocessed inline CSS adds it to the page.');

    //
    // Tests removing charset when rendering stylesheets with preprocessing on.
    advagg_test_reset_statics();
    $cases = array(
      array(
        'asset' => '@charset "UTF-8";html{font-family:"sans-serif";}',
        'expected' => 'html{font-family:"sans-serif";}',
      ),
      // This asset contains extra \n character.
      array(
        'asset' => "@charset 'UTF-8';\nhtml{font-family:'sans-serif';}",
        'expected' => "\nhtml{font-family:'sans-serif';}",
      ),
    );
    foreach ($cases as $case) {
      $this
        ->assertEqual($case['expected'], advagg_load_stylesheet_content($case['asset']), 'CSS optimizing correctly removes the charset declaration.');
    }

    //
    // Tests rendering inline stylesheets with preprocessing off.
    advagg_test_reset_statics();

    // Add the inline css.
    $css = 'body { padding: 0px; }';
    drupal_add_css($css, array(
      'type' => 'inline',
      'preprocess' => FALSE,
    ));

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);
    $this
      ->assertTrue(strpos($styles, $css) > 0, 'Rendering non-preprocessed inline CSS adds it to the page.');

    //
    // Test CSS ordering.
    advagg_test_reset_statics();

    // A module CSS file.
    drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css');

    // A few system CSS files, ordered in a strange way.
    $system_path = drupal_get_path('module', 'system');
    drupal_add_css($system_path . '/system.menus.css', array(
      'group' => CSS_SYSTEM,
    ));
    drupal_add_css($system_path . '/system.base.css', array(
      'group' => CSS_SYSTEM,
      'weight' => -10,
    ));
    drupal_add_css($system_path . '/system.theme.css', array(
      'group' => CSS_SYSTEM,
    ));
    $expected = array(
      $system_path . '/system.base.css',
      $system_path . '/system.menus.css',
      $system_path . '/system.theme.css',
      drupal_get_path('module', 'simpletest') . '/simpletest.css',
    );

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);

    // Stylesheet URL may be the href of a LINK tag or in an @import statement
    // of a STYLE tag.
    if (preg_match_all('/(href="|url\\(")' . preg_quote($GLOBALS['base_url'] . '/', '/') . '([^?]+)\\?/', $styles, $matches)) {
      $result = $matches[2];
    }
    else {
      $result = array();
    }
    $this
      ->assertIdentical($result, $expected, 'The CSS files are in the expected order.');

    //
    // Test CSS override.
    advagg_test_reset_statics();
    $system = drupal_get_path('module', 'system');
    $simpletest = drupal_get_path('module', 'simpletest');
    drupal_add_css($system . '/system.base.css');
    drupal_add_css($simpletest . '/tests/system.base.css');

    // The dummy stylesheet should be the only one included.
    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);
    $this
      ->assert(strpos($styles, $simpletest . '/tests/system.base.css') !== FALSE, 'The overriding CSS file is output.');
    $this
      ->assert(strpos($styles, $system . '/system.base.css') === FALSE, 'The overridden CSS file is not output.');

    // The reset is needed here until this is fixed
    // https://www.drupal.org/node/1388546
    advagg_test_reset_statics();
    drupal_add_css($simpletest . '/tests/system.base.css');
    drupal_add_css($system . '/system.base.css');

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);

    // The standard stylesheet should be the only one included.
    $this
      ->assert(strpos($styles, $system . '/system.base.css') !== FALSE, 'The overriding CSS file is output.');
    $this
      ->assert(strpos($styles, $simpletest . '/tests/system.base.css') === FALSE, 'The overridden CSS file is not output.');

    //
    //  Tests Locale module's CSS Alter to include RTL overrides.
    advagg_test_reset_statics();

    // Switch the language to a right to left language and add system.base.css.
    global $language;
    $language->direction = LANGUAGE_RTL;
    $path = drupal_get_path('module', 'system');
    drupal_add_css($path . '/system.base.css', array(
      'group' => CSS_SYSTEM,
    ));
    drupal_add_css($path . '/system.menus.css', array(
      'group' => CSS_SYSTEM,
    ));
    drupal_add_css($path . '/system.theme.css', array(
      'group' => CSS_SYSTEM,
    ));

    // Get the render array.
    $full_css = advagg_get_css();

    // Render the CSS.
    $styles = drupal_render($full_css);

    // Check to see if system.base-rtl.css was also added.
    $base_pos = strpos($styles, $path . '/system.base.css');
    $base_rtl_pos = strpos($styles, $path . '/system.base-rtl.css');
    $this
      ->assert($base_rtl_pos !== FALSE, 'CSS is alterable as right to left overrides are added.');
    $this
      ->assert($base_pos < $base_rtl_pos, 'system.base-rtl.css is added after system.base.css.');

    // Check to see if system.menus-rtl.css was also added.
    $menus_pos = strpos($styles, $path . '/system.menus.css');
    $menus_rtl_pos = strpos($styles, $path . '/system.menus-rtl.css');
    $this
      ->assert($menus_rtl_pos !== FALSE, 'CSS is alterable as right to left overrides are added.');
    $this
      ->assert($menus_pos < $menus_rtl_pos, 'system.menus-rtl.css is added after system.menus.css.');

    // Check to see if system.theme-rtl.css was also added.
    $theme_pos = strpos($styles, $path . '/system.theme.css');
    $theme_rtl_pos = strpos($styles, $path . '/system.theme-rtl.css');
    $this
      ->assert($theme_rtl_pos !== FALSE, 'CSS is alterable as right to left overrides are added.');
    $this
      ->assert($theme_pos < $theme_rtl_pos, 'system.theme-rtl.css is added after system.theme.css.');

    // Change the language back to left to right.
    $language->direction = LANGUAGE_LTR;

    //
    // Tests rendering inline stylesheets through a full page request.
    advagg_test_reset_statics();
    $css = 'body { font-size: 254px; }';

    // Inline CSS is minified unless 'preprocess' => FALSE is passed as a
    // drupal_add_css() option.
    $expected = 'body{font-size:254px;}';

    // Create a node, using the PHP filter that tests drupal_add_css().
    $php_format_id = 'php_code';
    $settings = array(
      'type' => 'page',
      'body' => array(
        LANGUAGE_NONE => array(
          array(
            'value' => t('This tests the inline CSS!') . "<?php drupal_add_css('{$css}', 'inline'); ?>",
            'format' => $php_format_id,
          ),
        ),
      ),
      'promote' => 1,
    );
    $node = $this
      ->drupalCreateNode($settings);

    // Fetch the page.
    $this
      ->drupalGet('node/' . $node->nid);
    $this
      ->assertRaw($expected, 'Inline stylesheets appear in the full page rendering.');

    //
    // Tests that the query string remains intact when adding CSS files that
    // have query string parameters.
    advagg_test_reset_statics();
    $this
      ->drupalGet('common-test/query-string');
    $query_string = variable_get('css_js_query_string', '0');
    $this
      ->assertRaw(drupal_get_path('module', 'node') . '/node.css?' . $query_string, 'Query string was appended correctly to css.');
    $this
      ->assertRaw(drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&amp;arg2=value2', 'Query string not escaped on a URI.');

    //
    // Make the tests below more robust by explicitly setting the default theme
    // and administrative theme that they expect.
    theme_enable(array(
      'bartik',
    ));
    variable_set('theme_default', 'bartik');
    variable_set('admin_theme', 'seven');

    // Test the theme callback when it is set to use an administrative theme.
    advagg_test_reset_statics();
    $this
      ->drupalGet('menu-test/theme-callback/use-admin-theme');
    $this
      ->assertText('Custom theme: seven. Actual theme: seven.', 'The administrative theme can be correctly set in a theme callback.');
    $this
      ->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");

    //
    // Test that the theme callback is properly inherited.
    advagg_test_reset_statics();
    $this
      ->drupalGet('menu-test/theme-callback/use-admin-theme/inheritance');
    $this
      ->assertText('Custom theme: seven. Actual theme: seven. Theme callback inheritance is being tested.', 'Theme callback inheritance correctly uses the administrative theme.');
    $this
      ->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");

    //
    // Test the theme callback when the site is in maintenance mode.
    advagg_test_reset_statics();
    variable_set('maintenance_mode', TRUE);

    // For a regular user, the fact that the site is in maintenance mode means
    // we expect the theme callback system to be bypassed entirely.
    $this
      ->drupalGet('menu-test/theme-callback/use-admin-theme');
    $this
      ->assertRaw('bartik/css/style.css', "The maintenance theme's CSS appears on the page.");

    // An administrator, however, should continue to see the requested theme.
    $admin_user = $this
      ->drupalCreateUser(array(
      'access site in maintenance mode',
    ));
    $this
      ->drupalLogin($admin_user);
    $this
      ->drupalGet('menu-test/theme-callback/use-admin-theme');
    $this
      ->assertText('Custom theme: seven. Actual theme: seven.', 'The theme callback system is correctly triggered for an administrator when the site is in maintenance mode.');
    $this
      ->assertRaw('seven/style.css', "The administrative theme's CSS appears on the page.");
    variable_set('maintenance_mode', FALSE);

    //
    // Test the theme callback when it is set to use an optional theme.
    advagg_test_reset_statics();

    // Request a theme that is not enabled.
    $this
      ->drupalGet('menu-test/theme-callback/use-stark-theme');
    $this
      ->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that is not enabled is requested.');
    $this
      ->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");

    // Now enable the theme and request it again.
    theme_enable(array(
      'stark',
    ));
    $this
      ->drupalGet('menu-test/theme-callback/use-stark-theme');
    $this
      ->assertText('Custom theme: stark. Actual theme: stark.', 'The theme callback system uses an optional theme once it has been enabled.');
    $this
      ->assertRaw('stark/layout.css', "The optional theme's CSS appears on the page.");

    // Test the theme callback when it is set to use a theme that does not
    // exist.
    $this
      ->drupalGet('menu-test/theme-callback/use-fake-theme');
    $this
      ->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when a theme that does not exist is requested.');
    $this
      ->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");

    //
    // Test the theme callback when no theme is requested.
    advagg_test_reset_statics();
    $this
      ->drupalGet('menu-test/theme-callback/no-theme-requested');
    $this
      ->assertText('Custom theme: NONE. Actual theme: bartik.', 'The theme callback system falls back on the default theme when no theme is requested.');
    $this
      ->assertRaw('bartik/css/style.css', "The default theme's CSS appears on the page.");

    //
    // Test that hook_custom_theme() can control the theme of a page.
    advagg_test_reset_statics();

    // Trigger hook_custom_theme() to dynamically request the Stark theme for
    // the requested page.
    variable_set('menu_test_hook_custom_theme_name', 'stark');
    theme_enable(array(
      'stark',
    ));

    // Visit a page that does not implement a theme callback. The above request
    // should be honored.
    $this
      ->drupalGet('menu-test/no-theme-callback');
    $this
      ->assertText('Custom theme: stark. Actual theme: stark.', 'The result of hook_custom_theme() is used as the theme for the current page.');
    $this
      ->assertRaw('stark/layout.css', "The Stark theme's CSS appears on the page.");

    //
    // Test that the theme callback wins out over hook_custom_theme().
    advagg_test_reset_statics();

    // Trigger hook_custom_theme() to dynamically request the Stark theme for
    // the requested page.
    variable_set('menu_test_hook_custom_theme_name', 'stark');
    theme_enable(array(
      'stark',
    ));

    // The menu "theme callback" should take precedence over a value set in
    // hook_custom_theme().
    $this
      ->drupalGet('menu-test/theme-callback/use-admin-theme');
    $this
      ->assertText('Custom theme: seven. Actual theme: seven.', 'The result of hook_custom_theme() does not override what was set in a theme callback.');
    $this
      ->assertRaw('seven/style.css', "The Seven theme's CSS appears on the page.");

    //
    // Test css split file processing.
    // Generate a massive css file.
    $css_string = advagg_test_generate_selector_css(1000);
    $css_string .= '@media print {' . advagg_test_generate_selector_css(1000) . '}';
    $css_string .= advagg_test_generate_selector_css(1000);
    $css_string .= '@media screen {' . advagg_test_generate_selector_css(1000) . '}';
    $css_string .= advagg_test_generate_selector_css(1000);
    $css_string .= '@media print {' . advagg_test_generate_selector_css(1000) . '}';
    $css_string .= advagg_test_generate_selector_css(9000);
    $css_string .= '@media print {' . advagg_test_generate_selector_css(9000) . '}';
    $css_string .= advagg_test_generate_selector_css(9000);
    $css_string .= '@media screen {' . advagg_test_generate_selector_css(9000) . '}';
    $css_string .= '@media print {' . advagg_test_generate_selector_css(50) . '}';
    $css_string .= '@media screen {' . advagg_test_generate_selector_css(50) . '}';
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= '@media print {' . advagg_test_generate_selector_css(50) . '}';
    $css_string .= '@media screen {' . advagg_test_generate_selector_css(50) . '}';
    $css_string .= '@media print {' . advagg_test_generate_selector_css(50) . '}';
    $css_string .= '@media screen {' . advagg_test_generate_selector_css(50) . '}';
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(15000);
    $css_string .= '@media print {' . advagg_test_generate_selector_css(15000) . '}';
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $css_string .= advagg_test_generate_selector_css(10);
    $file_info = array(
      // Use a file that exists but isn't actually being used here.
      'data' => drupal_get_path('module', 'advagg') . '/tests/css_test_files/advagg.css',
    );
    $before_selector_count = advagg_count_css_selectors($css_string);

    // Split the huge css file.
    $parts = advagg_split_css_file($file_info, $css_string);
    $after = '';
    foreach ($parts as $part) {

      // Get written file.
      $after .= "\n" . (string) @advagg_file_get_contents($part['data']);

      // Cleanup.
      unlink($part['data']);
    }

    // Note that a diff of the text can not be used for this test. Counting
    // selectors is close enough for now.
    $after_selector_count = advagg_count_css_selectors($after);
    $this
      ->assertEqual($before_selector_count, $after_selector_count, t('Expected %before selectors, got %after.', array(
      '%before' => $before_selector_count,
      '%after' => $after_selector_count,
    )));

    //
    // Test css file processing.
    advagg_test_reset_statics();

    // Array of files to test living in 'advagg/tests/css_test_files/'.
    // - Original: name.css
    // - Unoptimized expected content: name.css.unoptimized.css
    // - Optimized expected content: name.css.optimized.css
    //
    // File. Tests: css_input_without_import.css.
    // - Stripped comments and white-space.
    // - Retain white-space in selectors. (http://drupal.org/node/472820)
    // - Retain pseudo-selectors. (http://drupal.org/node/460448)
    //
    // File. Tests: css_input_with_import.css.
    // - Proper URLs in imported files. (http://drupal.org/node/265719)
    // - A background image with relative paths, which must be rewritten.
    // - The rewritten background image path must also be passed through
    //   file_create_url(). (https://drupal.org/node/1961340)
    // - Imported files that are external (protocol-relative URL or not)
    //   should not be expanded. (https://drupal.org/node/2014851)
    //
    // File in sub-folder. Tests: css_subfolder/css_input_with_import.css.
    // - CSS import path interpreted. (https://drupal.org/node/1198904)
    // - Don't adjust data URIs (https://drupal.org/node/2142441)
    //
    // File. Tests: comment_hacks.css.
    // - Retain comment hacks.
    $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', 'advagg') . '/tests/css_test_files';
    foreach ($testfiles as $file) {
      $file_path = $path . '/' . $file;
      $file_url = $GLOBALS['base_url'] . '/' . $file_path;
      $expected = advagg_file_get_contents($file_path . '.unoptimized.css');
      $unoptimized_output = advagg_load_stylesheet($file_path, FALSE);
      $this
        ->assertEqual($unoptimized_output, $expected, format_string('Unoptimized CSS file has expected contents (@file)', array(
        '@file' => $file,
      )));
      $expected = advagg_file_get_contents($file_path . '.optimized.css');
      $expected = advagg_test_remove_sniffer_comments($expected);
      $optimized_output = advagg_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 = advagg_file_get_contents($file_path . '.unoptimized.css');
      $unoptimized_output_url = advagg_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 = advagg_file_get_contents($file_path . '.optimized.css');
      $expected = advagg_test_remove_sniffer_comments($expected);
      $optimized_output_url = advagg_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,
      )));
    }

    // File. Tests: charset*.css
    // - Any @charaset declaration at the beginning of a file should be
    //   removed without breaking subsequent CSS.
    $testfiles = array(
      'charset.css',
      'charset_newline.css',
      'charset_sameline.css',
    );
    $path = drupal_get_path('module', 'advagg') . '/tests/css_test_files';
    foreach ($testfiles as $file) {
      $file_path = $path . '/' . $file;
      $file_url = $GLOBALS['base_url'] . '/' . $file_path;
      $expected = advagg_file_get_contents($file_path . '.optimized.css');
      $expected = advagg_test_remove_sniffer_comments($expected);
      $optimized_output = advagg_load_stylesheet($file_path, TRUE);
      $this
        ->assertEqual($optimized_output, $expected, format_string('Optimized CSS file has expected contents (@file)', array(
        '@file' => $file,
      )));
      $expected = advagg_file_get_contents($file_path . '.optimized.css');
      $expected = advagg_test_remove_sniffer_comments($expected);
      $optimized_output_url = advagg_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,
      )));
    }

    // Set all to FALSE.
    $GLOBALS['conf']['advagg_convert_absolute_to_relative_path'] = FALSE;
    $GLOBALS['conf']['advagg_convert_absolute_to_protocol_relative_path'] = FALSE;
    $GLOBALS['conf']['advagg_force_https_path'] = FALSE;
    $GLOBALS['conf']['advagg_skip_file_create_url_inside_css'] = FALSE;
    $settings_to_change = array(
      '' => '',
      'advagg_skip_file_create_url_inside_css' => TRUE,
      'advagg_convert_absolute_to_relative_path' => TRUE,
      'advagg_convert_absolute_to_protocol_relative_path' => TRUE,
      'advagg_force_https_path' => TRUE,
    );
    $advagg_path = drupal_get_path('module', 'advagg');
    $path = $advagg_path . '/tests/css_test_files';
    foreach ($settings_to_change as $name => $value) {
      $before = '';
      if (!empty($name)) {
        $before = variable_get($name, defined(strtoupper($name)) ? constant(strtoupper($name)) : NULL);
        $GLOBALS['conf'][$name] = $value;
      }

      // File. Tests: advagg.css
      // - Various url() tests.
      //   https://www.drupal.org/node/1514182
      //   https://www.drupal.org/node/1961340
      //   https://www.drupal.org/node/2362643
      //   https://www.drupal.org/node/2112067
      $testfiles = array(
        'advagg.css',
      );
      foreach ($testfiles as $testfile) {
        $base_url_before = $GLOBALS['base_url'];
        $GLOBALS['base_url'] = advagg_force_http_path($GLOBALS['base_url']);
        $aggregate_settings = array(
          'variables' => array(
            'is_https' => FALSE,
            'base_path' => $GLOBALS['base_path'] === '/checkout/' ? $GLOBALS['base_path'] : $GLOBALS['base_path'] . 'advagg_base_path_test/',
            'advagg_convert_absolute_to_relative_path' => $GLOBALS['conf']['advagg_convert_absolute_to_relative_path'],
            'advagg_convert_absolute_to_protocol_relative_path' => $GLOBALS['conf']['advagg_convert_absolute_to_protocol_relative_path'],
            'advagg_force_https_path' => $GLOBALS['conf']['advagg_force_https_path'],
            'advagg_skip_file_create_url_inside_css' => $GLOBALS['conf']['advagg_skip_file_create_url_inside_css'],
          ),
        );
        if (module_exists('cdn')) {
          $aggregate_settings['variables'][CDN_MODE_VARIABLE] = CDN_DISABLED;
          $aggregate_settings['variables'][CDN_STATUS_VARIABLE] = CDN_DISABLED;
        }
        $file_path = $path . '/' . $testfile;
        $files = array(
          'file' => $file_path,
          'external' => $GLOBALS['base_url'] . '/' . $file_path,
        );
        $expected = advagg_test_remove_sniffer_comments(advagg_file_get_contents($file_path . '.optimized.css'));
        foreach ($files as $type => $file) {
          $optimized_output = advagg_load_css_stylesheet($file, TRUE, $aggregate_settings);
          $mode = 0;
          if ($aggregate_settings['variables']['advagg_skip_file_create_url_inside_css'] && $type !== 'external') {
            $mode = "01";
            $optimized_output = str_replace($aggregate_settings['variables']['base_path'] . $advagg_path . '/', '', $optimized_output);
          }
          elseif (!$aggregate_settings['variables']['advagg_convert_absolute_to_relative_path'] && !$aggregate_settings['variables']['advagg_convert_absolute_to_protocol_relative_path'] && !$aggregate_settings['variables']['advagg_force_https_path']) {
            $mode = 4;
            $optimized_output = str_replace('http://' . $_SERVER['HTTP_HOST'] . $aggregate_settings['variables']['base_path'] . $advagg_path . '/', '', $optimized_output);
          }
          elseif ($aggregate_settings['variables']['advagg_convert_absolute_to_protocol_relative_path']) {
            $mode = 2;
            $optimized_output = str_replace('//' . $_SERVER['HTTP_HOST'] . $aggregate_settings['variables']['base_path'] . $advagg_path . '/', '', $optimized_output);
          }
          elseif ($aggregate_settings['variables']['advagg_force_https_path']) {
            $mode = 3;
            $optimized_output = str_replace('https://' . $_SERVER['HTTP_HOST'] . $aggregate_settings['variables']['base_path'] . $advagg_path . '/', '', $optimized_output);
          }
          else {
            $mode = 1;
            $optimized_output = str_replace($aggregate_settings['variables']['base_path'] . $advagg_path . '/', '', $optimized_output);
          }
          $this
            ->assertEqual($optimized_output, $expected, format_string("Optimized CSS file has expected contents (@file). Setting tested: @name; value before: @before, value after: @after.<br>mode: @mode. <p>!replacements</p> <p><code>!debug</code></p>", array(
            '@file' => $file,
            '@name' => $name,
            '@before' => is_bool($before) || strlen((string) $before) == 0 ? strtoupper(var_export($before, TRUE)) : $before,
            '@after' => is_bool($value) || strlen((string) $value) == 0 ? strtoupper(var_export($value, TRUE)) : $value,
            '@mode' => $mode,
            '!replacements' => "1: {$aggregate_settings['variables']['base_path']}{$advagg_path}/ <br> 2: //{$_SERVER['HTTP_HOST']}{$aggregate_settings['variables']['base_path']}{$advagg_path}/ <br> 3: https://{$_SERVER['HTTP_HOST']}{$aggregate_settings['variables']['base_path']}{$advagg_path}/ <br> 4: http://{$_SERVER['HTTP_HOST']}{$aggregate_settings['variables']['base_path']}{$advagg_path}/",
            '!debug' => nl2br(str_replace(' ', '&nbsp;', $optimized_output)),
          )));
          $GLOBALS['base_url'] = $base_url_before;
        }
      }
      if (!empty($name)) {
        $GLOBALS['conf'][$name] = $before;
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AdvAggCascadingStylesheetsTestCase::$bigUser protected property Create user.
AdvAggCascadingStylesheetsTestCase::$preprocessCss protected property Store configured value for CSS preprocessing.
AdvAggCascadingStylesheetsTestCase::$themes protected property Theme settings.
AdvAggCascadingStylesheetsTestCase::getInfo public static function Provide information to the UI for this test.
AdvAggCascadingStylesheetsTestCase::setUp public function Install the advagg module and include needed files. Overrides DrupalWebTestCase::setUp
AdvAggCascadingStylesheetsTestCase::tearDown public function Restore any variables we set. Overrides DrupalWebTestCase::tearDown
AdvAggCascadingStylesheetsTestCase::testRenderFile public function Tests rendering the stylesheets.
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGet protected function Retrieves a Drupal path or an absolute path.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser.
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1