You are here

public function AggregatorCronTestCase::testCron in Drupal 7

Adds feeds and updates them via cron process.

File

modules/aggregator/aggregator.test, line 874
Tests for aggregator.module.

Class

AggregatorCronTestCase
Tests functionality of the cron process in the Aggregator module.

Code

public function testCron() {

  // Create feed and test basic updating on cron.
  global $base_url;
  $key = variable_get('cron_key', 'drupal');
  $this
    ->createSampleNodes();
  $feed = $this
    ->createFeed();
  $this
    ->drupalGet($base_url . '/cron.php', array(
    'external' => TRUE,
    'query' => array(
      'cron_key' => $key,
    ),
  ));
  $this
    ->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(
    ':fid' => $feed->fid,
  ))
    ->fetchField(), 'Expected number of items in database.');
  $this
    ->removeFeedItems($feed);
  $this
    ->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(
    ':fid' => $feed->fid,
  ))
    ->fetchField(), 'Expected number of items in database.');
  $this
    ->drupalGet($base_url . '/cron.php', array(
    'external' => TRUE,
    'query' => array(
      'cron_key' => $key,
    ),
  ));
  $this
    ->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(
    ':fid' => $feed->fid,
  ))
    ->fetchField(), 'Expected number of items in database.');

  // Test feed locking when queued for update.
  $this
    ->removeFeedItems($feed);
  db_update('aggregator_feed')
    ->condition('fid', $feed->fid)
    ->fields(array(
    'queued' => REQUEST_TIME,
  ))
    ->execute();
  $this
    ->drupalGet($base_url . '/cron.php', array(
    'external' => TRUE,
    'query' => array(
      'cron_key' => $key,
    ),
  ));
  $this
    ->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(
    ':fid' => $feed->fid,
  ))
    ->fetchField(), 'Expected number of items in database.');
  db_update('aggregator_feed')
    ->condition('fid', $feed->fid)
    ->fields(array(
    'queued' => 0,
  ))
    ->execute();
  $this
    ->drupalGet($base_url . '/cron.php', array(
    'external' => TRUE,
    'query' => array(
      'cron_key' => $key,
    ),
  ));
  $this
    ->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(
    ':fid' => $feed->fid,
  ))
    ->fetchField(), 'Expected number of items in database.');
}