diff --git a/tests/feeds_fetcher_http.test b/tests/feeds_fetcher_http.test index 7df8318..5fc5239 100644 --- a/tests/feeds_fetcher_http.test +++ b/tests/feeds_fetcher_http.test @@ -198,9 +198,6 @@ class FeedsFileHTTPTestCase extends FeedsWebTestCase { // Revert back to the default cache class. variable_set('cache_class_cache_feeds_http', 'DrupalDatabaseCache'); - // Include http request functions. - feeds_include_library('http_request.inc', 'http_request'); - // Import. We cannot test with a simple http_request_get() call here, // because there is no way to override a cache class on a single request. // @see _cache_get_object(). @@ -228,6 +225,43 @@ class FeedsFileHTTPTestCase extends FeedsWebTestCase { } /** + * Tests if cached files are cleaned up even when a different cache class is + * used. + */ + 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. + $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, + ))); + } + + /** * Tests if a source is not refetched on a second import when the source did * not change. */