public function FeedsFileHTTPTestCase::testImportSourceWithMultipleCronRuns in Feeds 7.2
Tests importing source that needs multiple cron runs.
Make sure that:
- The content is not saved in the feeds_source table.
- That the source is not refetched while the import has not completed yet.
File
- tests/
feeds_fetcher_http.test, line 534 - Contains FeedsFileHTTPTestCase.
Class
- FeedsFileHTTPTestCase
- HTTP fetcher test class.
Code
public function testImportSourceWithMultipleCronRuns() {
$source_url = url('testing/feeds/nodes.csv', array(
'absolute' => TRUE,
));
$this
->setUpMultipleCronRuns($source_url);
// Run cron. Five nodes should be imported.
$this
->cronRun();
// Assert that only one file was created in the in_progress dir.
$this
->getInProgressFile();
// Assert that five nodes have been created now.
$this
->assertNodeCount(5);
// Assert that the content is *not* saved in the feeds_source table.
$source = db_select('feeds_source')
->fields('feeds_source', array())
->condition('id', 'node')
->execute()
->fetch();
$this
->assertTrue(strpos($source->fetcher_result, 'Title,Body,published,GUID') === FALSE, 'The content has not been saved in the feeds_source table.');
// Now change the source to test if the source is not refetched while the
// import hasn't been finished yet. The following is different:
// - Items 1 and 4 changed.
// - Items 2 and 7 were removed.
variable_set('feeds_tests_nodes_changed', TRUE);
// Run cron again. Another four nodes should be imported.
$this
->cronRun();
$this
->assertNodeCount(9);
// Check if the imported nodes match that from the original source.
$node = node_load(1);
$this
->assertEqual('Ut wisi enim ad minim veniam', $node->title);
$this
->assertTrue(strpos($node->body[LANGUAGE_NONE][0]['value'], 'CHANGE') === FALSE);
$node = node_load(4);
$this
->assertEqual('Typi non habent', $node->title);
$this
->assertTrue(strpos($node->body[LANGUAGE_NONE][0]['value'], 'CHANGE') === FALSE);
$node = node_load(7);
$this
->assertEqual('Claritas est etiam', $node->title);
$node = node_load(9);
$this
->assertEqual('Eodem modo typi', $node->title);
}