public function ImagecacheExternalTestCase::testCachingCronCleanup in Imagecache External 7.2
Test the cron cleanup job.
File
- ./
imagecache_external.test, line 268 - Tests for Imagecache External.
Class
- ImagecacheExternalTestCase
- Tests the functions for working with public/private file schemes.
Code
public function testCachingCronCleanup() {
$external_image_files = array();
$source_image_files = array_slice($this
->drupalGetTestFiles('image'), 0, 2);
$externals_directory = file_build_uri(variable_get('imagecache_directory', 'externals'));
// Ensure the externals directory exists.
file_prepare_directory($externals_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Move two images to the externals directory.
foreach ($source_image_files as $source_image_file) {
$destination_uri = $externals_directory . DIRECTORY_SEPARATOR . drupal_basename($source_image_file->uri);
file_unmanaged_copy($source_image_file->uri, $destination_uri);
$external_image_files[] = $destination_uri;
}
$this
->assertExternalsCacheContains(2);
drupal_cron_run();
// Assert that there are still two images (default should be no change).
$this
->assertExternalsCacheContains(2);
// Set the cron threshold to be seven days.
variable_set('imagecache_external_cron_flush_threshold', 7);
// Set one image to be two weeks old (over the threshold).
touch(drupal_realpath($external_image_files[0]), time() - 3600 * 24 * 14);
// Run cron again without resetting the last run time.
drupal_cron_run();
// Assert that there are still two images (i.e. cron hasn't run).
$this
->assertExternalsCacheContains(2);
// Now reset the last run time and run cron again.
variable_set('imagecache_external_cron_last_run', 0);
drupal_cron_run();
$this
->assertExternalsCacheContains(1);
}