AggregatorCronTest.php 1.54 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\aggregator\Tests;

5
/**
6 7 8
 * Update feeds on cron.
 *
 * @group aggregator
9
 */
10 11
class AggregatorCronTest extends AggregatorTestBase {
  /**
12
   * Adds feeds and updates them via cron process.
13 14 15 16 17 18
   */
  public function testCron() {
    // Create feed and test basic updating on cron.
    $this->createSampleNodes();
    $feed = $this->createFeed();
    $this->cronRun();
19
    $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
20
    $this->deleteFeedItems($feed);
21
    $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
22
    $this->cronRun();
23
    $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
24 25

    // Test feed locking when queued for update.
26
    $this->deleteFeedItems($feed);
27
    db_update('aggregator_feed')
28
      ->condition('fid', $feed->id())
29 30 31 32 33
      ->fields(array(
        'queued' => REQUEST_TIME,
      ))
      ->execute();
    $this->cronRun();
34
    $this->assertEqual(0, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
35
    db_update('aggregator_feed')
36
      ->condition('fid', $feed->id())
37 38 39 40 41
      ->fields(array(
        'queued' => 0,
      ))
      ->execute();
    $this->cronRun();
42
    $this->assertEqual(5, db_query('SELECT COUNT(*) FROM {aggregator_item} WHERE fid = :fid', array(':fid' => $feed->id()))->fetchField());
43
  }
44

45
}