diff --git a/includes/FeedsSource.inc b/includes/FeedsSource.inc index 58a628d..1dddbc1 100644 --- a/includes/FeedsSource.inc +++ b/includes/FeedsSource.inc @@ -651,7 +651,7 @@ class FeedsSource extends FeedsConfigurable { * Clears states. */ protected function clearStates() { - if ($this->fetcher_result instanceof FetcherResult) { + if ($this->fetcher_result instanceof FeedsFetcherResult) { $this->fetcher_result->cleanUp(); } $this->state = array(); diff --git a/tests/feeds_fetcher_http.test b/tests/feeds_fetcher_http.test index ceafcaa..672003a 100644 --- a/tests/feeds_fetcher_http.test +++ b/tests/feeds_fetcher_http.test @@ -77,9 +77,16 @@ class FeedsFileHTTPTestCase extends FeedsWebTestCase { // Set up importer. $this->setUpImporter(); + + // Turn off periodic import. + $this->setSettings('node', NULL, array( + 'import_period' => FEEDS_SCHEDULE_NEVER, + )); + // Only import during cron runs, not immediately. $this->setSettings('node', NULL, array( - 'import_on_create' => FALSE, + 'import_on_create' => TRUE, + 'process_in_background' => TRUE, )); // Set source file to import. @@ -641,9 +648,34 @@ class FeedsFileHTTPTestCase extends FeedsWebTestCase { } /** - * Tests that the temporary file gets cleaned up if the import gets aborted. + * Tests that the temporary file gets cleaned up when unlocking a feed. + */ + public function testTemporaryFileCleanUpWhenUnlockingFeed() { + $source_url = url('testing/feeds/nodes.csv', array('absolute' => TRUE)); + $this->setUpMultipleCronRuns($source_url); + + // Run the first cron. + $this->cronRun(); + $this->assertNodeCount(5); + + // Assert that a file exists in the in_progress dir. + $file = $this->getInProgressFile(); + + // Abort the import by unlocking the feeds source. + feeds_source('node')->unlock(); + + // Assert that the temporary file no longer exists at this point. + $this->assertFalse(file_exists($file->uri), format_string('The file @uri no longer exists.', array( + '@uri' => $file->uri, + ))); + + // After this point, the import task remains in the queue. + } + + /** + * Tests that the temporary file gets cleaned up if the import gets aborted abruptly. */ - public function testTemporaryFileCleanUpWhenAbortingImport() { + public function testTemporaryFileCleanUpWhenAbortingImportAbruptly() { $source_url = url('testing/feeds/nodes.csv', array('absolute' => TRUE)); $this->setUpMultipleCronRuns($source_url); @@ -659,10 +691,9 @@ class FeedsFileHTTPTestCase extends FeedsWebTestCase { ->fields(array('timestamp' => REQUEST_TIME - 86400)) ->execute(); - // Abort the import. - db_update('feeds_source') + // Abort the import by deleting the feeds source in the database. + db_delete('feeds_source') ->condition('id', 'node') - ->fields(array('state' => FALSE)) ->execute(); // Run cron again.