function FeedsSchedulerTestCase::testBatching in Feeds 7
Same name and namespace in other branches
- 6 tests/feeds_scheduler.test \FeedsSchedulerTestCase::testBatching()
- 7.2 tests/feeds_scheduler.test \FeedsSchedulerTestCase::testBatching()
Test batching on cron.
File
- tests/
feeds_scheduler.test, line 227 - Feeds tests.
Class
- FeedsSchedulerTestCase
- Test cron scheduling.
Code
function testBatching() {
// 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 Article 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 article nodes.
for ($i = 0; $i < 3; $i++) {
$this
->runCron(1);
// 50 == FEEDS_NODE_BATCH_SIZE
$this
->assertEqual(50 * ($i + 1), db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField());
$this
->assertEqual(0, db_query("SELECT period FROM {job_schedule} WHERE type = 'syndication' AND id = :nid", array(
':nid' => $nid,
))
->fetchField());
}
// Run one more time to cause the batch to reset, check period back to 1800.
$this
->runCron();
$this
->assertEqual(1800, db_query("SELECT period FROM {job_schedule} WHERE type = 'syndication' AND id = :nid", array(
':nid' => $nid,
))
->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(148, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField());
$this
->runCron();
$this
->assertEqual(148, db_query("SELECT COUNT(*) FROM {node} WHERE type = 'article'")
->fetchField());
}