You are here

public function CleanerTestFilesClearing::testFilesClearing in Cleaner 7

Test clearing CSS/JS files.

File

tests/cleaner_files.test, line 37
Test Clearing CSS/JS files.

Class

CleanerTestFilesClearing
Class CleanerTestFilesClearing.

Code

public function testFilesClearing() {

  // Prepare a Cleaner settings.
  $settings = array(
    'cleaner_clean_cssdir' => 1,
    'cleaner_clean_jsdir' => 1,
  );
  $this
    ->cleanerSettings($settings);

  // Enable CSS/JS files aggregation.
  $settings = array(
    'preprocess_css' => 1,
    'preprocess_js' => 1,
    'page_compression' => 1,
  );
  $this
    ->drupalPost('admin/config/development/performance', $settings, t('Save configuration'));

  // Refresh default homepage for generate a CSS/JS files by aggregation.
  for ($i = 0; $i < 50; $i++) {
    $this
      ->drupalGet('node');

    // Assert response.
    $this
      ->assertResponse(200);
  }

  // Change file modification time.
  self::changeFilesModificationTime();

  // Save an initial file count.
  $initial_count = self::countFiles();

  // Execute Cleaner run.
  $this
    ->cleanerExecute();

  // Get files count after clearing.
  $count = self::countFiles();
  if ($count < $initial_count) {
    $this
      ->pass("CSS/JS files has been successfully cleared.");
  }
  else {
    $this
      ->fail("CSS/JS files has not been cleared.");
  }

  // Get logs.
  $this
    ->cleanerGetLog();

  // Check if CSS/JS files clearing has been successfully written to the log.
  $this
    ->assertText('Cleared old temporary CSS files by Cleaner', "CSS files clearing logged to watchdog");
  $this
    ->assertText('Cleared old temporary JS files by Cleaner', "JS files clearing logged to watchdog");
}