function FeedsSchedulerTestCase::testBatching in Feeds 6
Same name and namespace in other branches
- 7.2 tests/feeds_scheduler.test \FeedsSchedulerTestCase::testBatching()
- 7 tests/feeds_scheduler.test \FeedsSchedulerTestCase::testBatching()
Test batching on cron.
File
- tests/
feeds_scheduler.test, line 216 - Feeds tests.
Class
- FeedsSchedulerTestCase
- Test cron scheduling.
Code
function testBatching() {
// Set up an importer.
$this
->createImporterConfiguration();
// Verify that there are 150 nodes total.
$nid = $this
->createFeedNode('syndication', $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/many_items.rss2');
$this
->assertText('Created 150 Story nodes.');
$this
->drupalPost('node/' . $nid . '/delete-items', array(), 'Delete');
$this
->assertText('Deleted 150 nodes.');
// Set next time to 0 to simulate updates.
db_query("UPDATE {job_schedule} SET next = 0");
// Hit cron 3 times, assert correct number of story nodes.
for ($i = 1; $i <= 3; $i++) {
$this
->cronRun();
sleep(1);
// 50 == FEEDS_NODE_BATCH_SIZE
$this
->assertEqual(50 * $i, db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'story'")));
$this
->assertEqual(0, db_result(db_query("SELECT period FROM {job_schedule} WHERE type = 'syndication' AND id = %d", $nid)));
}
// Run one more time to cause the batch to reset, check period back to 1800.
$this
->cronRun();
$this
->assertEqual(1800, db_result(db_query("SELECT period FROM {job_schedule} WHERE type = 'syndication' AND id = %d", $nid)));
// Delete a couple of nodes, then hit cron again. They should not be replaced
// as the minimum update time is 30 minutes.
$result = db_query_range("SELECT nid FROM {node} WHERE type = 'story'", 0, 2);
while ($node = db_fetch_object($result)) {
$this
->drupalPost("node/{$node->nid}/delete", array(), 'Delete');
}
$this
->assertEqual(148, db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'story'")));
$this
->cronRun();
$this
->assertEqual(148, db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = 'story'")));
}