public function FeedsFileFetcherTestCase::testRemoveFileAfterImportInBackground in Feeds 7.2
Tests if files can be removed after import when running the import in background.
File
- tests/
feeds_fetcher_file.test, line 134 - File fetcher tests.
Class
- FeedsFileFetcherTestCase
- File fetcher test class.
Code
public function testRemoveFileAfterImportInBackground() {
// Configure to import in background and import as often as possible.
$this
->setSettings('node', NULL, array(
'import_period' => 0,
'import_on_create' => FALSE,
'process_in_background' => TRUE,
));
$this
->setSettings('node', 'FeedsFileFetcher', array(
'delete_uploaded_file' => TRUE,
'directory' => 'private://feeds',
));
// Make sure that the import cannot be completed in one run.
variable_set('feeds_process_limit', 5);
// Set variable to enforce that only five items get imported per cron run.
// @see feeds_tests_cron_queue_alter()
// @see feeds_tests_feeds_after_save()
variable_set('feeds_tests_feeds_source_import_queue_time', 5);
variable_set('feeds_tests_feeds_after_save_sleep', 1);
// Import a file with 9 nodes.
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/nodes.csv', 'Schedule import');
// Assert that the file has been created.
$this
->assertTrue(file_exists('private://feeds/nodes.csv'), 'The imported file is created.');
// Run cron and assert that five nodes have been created.
$this
->cronRun();
$node_count = db_select('node')
->fields('node', array())
->countQuery()
->execute()
->fetchField();
$this
->assertEqual(5, $node_count, format_string('Five nodes have been created (actual: @count).', array(
'@count' => $node_count,
)));
// Assert that the file to import still exists as the import hasn't finished
// yet.
drupal_flush_all_caches();
$this
->assertTrue(file_exists('private://feeds/nodes.csv'), 'The imported file still exists.');
// Run cron again to import the remaining 4 nodes and assert that 9 nodes
// exist in total.
$this
->cronRun();
$node_count = db_select('node')
->fields('node', array())
->countQuery()
->execute()
->fetchField();
$this
->assertEqual(9, $node_count, format_string('Nine nodes have been created (actual: @count).', array(
'@count' => $node_count,
)));
// Assert that the file to import finally has been removed now.
drupal_flush_all_caches();
$this
->assertFalse(file_exists('private://feeds/nodes.csv'), 'The imported file no longer exists.');
// Assert that running a second import does not result into errors.
$this
->cronRun();
// Assert that the file is no longer shown on the import form.
$this
->drupalGet('import/node');
$this
->assertNoText('nodes.csv');
}