public function FeedsFileHTTPTestCase::testCachedFilesCleanupOnHTTPCacheOverride in Feeds 7.2
Tests if cached files are cleaned up even when a different cache class is used.
File
- tests/
feeds_fetcher_http.test, line 349 - Contains FeedsFileHTTPTestCase.
Class
- FeedsFileHTTPTestCase
- HTTP fetcher test class.
Code
public function testCachedFilesCleanupOnHTTPCacheOverride() {
// Revert back to the default cache class.
variable_set('cache_class_cache_feeds_http', 'DrupalDatabaseCache');
// Create a real cached file by performing an import.
$this
->setUpImporter();
$source_url = url('testing/feeds/nodes.csv', array(
'absolute' => TRUE,
));
$edit = array(
'feeds[FeedsHTTPFetcher][source]' => $source_url,
);
$this
->drupalPost('import/node', $edit, t('Import'));
$this
->assertText('Created 9 nodes');
$file_url_with_cache_record = 'private://feeds/cache/' . hash('sha256', $source_url);
// Write a dummy cached file.
$dir = 'private://feeds/cache';
$file_url_no_cache_record = $dir . '/abc123';
file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
file_put_contents($file_url_no_cache_record, static::randomString());
// Trigger cleanup of orphaned cached files.
variable_del('feeds_sync_cache_feeds_http_last_check');
$this
->cronRun();
// Assert that the dummy cached file has been cleaned up and the other file
// still exists.
$this
->assertFalse(file_exists($file_url_no_cache_record), format_string('The file @file_url no longer exists.', array(
'@file_url' => $file_url_no_cache_record,
)));
$this
->assertTrue(file_exists($file_url_with_cache_record), format_string('The file @file_url still exists.', array(
'@file_url' => $file_url_with_cache_record,
)));
}