public function FeedsSchedulerTestCase::testBatching in Feeds 7.2
Same name and namespace in other branches
- 6 tests/feeds_scheduler.test \FeedsSchedulerTestCase::testBatching()
- 7 tests/feeds_scheduler.test \FeedsSchedulerTestCase::testBatching()
Test batching on cron.
File
- tests/
feeds_scheduler.test, line 320 - Feeds tests.
Class
- FeedsSchedulerTestCase
- Test cron scheduling.
Code
public function testBatching() {
// Set up an importer.
$this
->createImporterConfiguration('Node import', 'node');
// Set and configure plugins and mappings.
$edit = array(
'content_type' => '',
);
$this
->drupalPost('admin/structure/feeds/node/settings', $edit, 'Save');
$this
->setPlugin('node', 'FeedsFileFetcher');
$this
->setPlugin('node', 'FeedsCSVParser');
$mappings = array(
0 => array(
'source' => 'title',
'target' => 'title',
),
);
$this
->addMappings('node', $mappings);
// Verify that there are 86 nodes total.
$this
->importFile('node', $this
->absolutePath() . '/tests/feeds/many_nodes.csv');
$this
->assertText('Created 86 nodes');
// Set queue time to a minimum.
variable_set('feeds_tests_feeds_source_import_queue_time', 1);
// Run batch twice with two different process limits.
// 50 = FEEDS_PROCESS_LIMIT.
foreach (array(
10,
50,
) as $limit) {
variable_set('feeds_process_limit', $limit);
db_query("UPDATE {job_schedule} SET next = 0");
$this
->drupalPost('import/node/delete-items', array(), 'Delete');
$node_count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField();
$this
->assertEqual(0, $node_count);
// Hit cron for importing, until we have all items or when we are running
// out of cron runs.
$max_runs = ceil(86 / $limit);
$ran = 0;
while ($node_count < 86 && $ran < $max_runs) {
$this
->cronRun();
$node_count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField();
$ran++;
}
// Assert that 86 nodes exist now.
$node_count = db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField();
$this
->assertEqual(86, $node_count, format_string('86 nodes exist after batched importing via cron (actual: @actual).', array(
'@actual' => $node_count,
)));
// Import should be rescheduled for 1800 seconds.
$this
->assertEqual(1800, db_query("SELECT period FROM {job_schedule} WHERE type = 'node' AND id = 0")
->fetchField());
}
// Delete a couple of nodes, then hit cron again. They should not be
// replaced as the minimum update time is 30 minutes.
$nodes = db_query_range("SELECT nid FROM {node} WHERE type = 'article'", 0, 2);
foreach ($nodes as $node) {
$this
->drupalPost("node/{$node->nid}/delete", array(), 'Delete');
}
$this
->assertEqual(84, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField());
$this
->cronRun();
$this
->assertEqual(84, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField());
}