You are here

protected function FeedsSchedulerTestCase::initSyndication in Feeds 7.2

Initialize scheduling.

5 calls to FeedsSchedulerTestCase::initSyndication()
FeedsSchedulerTestCase::testNextImportTime in tests/feeds_scheduler.test
Tests if the expected next import time is shown for scheduled imports.
FeedsSchedulerTestCase::testNextImportTimeWhenQueuedViaJobScheduler in tests/feeds_scheduler.test
Tests if the expected next import time is shown when the import is queued via Job Scheduler.
FeedsSchedulerTestCase::testRescheduling in tests/feeds_scheduler.test
Test if existing feed nodes get rescheduled upon save.
FeedsSchedulerTestCase::testScheduling in tests/feeds_scheduler.test
Test scheduling of enabled import on cron.
FeedsSchedulerTestCase::testSchedulingWithDisabledImporter in tests/feeds_scheduler.test
Test scheduling of disabled import on cron.

File

tests/feeds_scheduler.test, line 414
Feeds tests.

Class

FeedsSchedulerTestCase
Test cron scheduling.

Code

protected function initSyndication() {

  // Create importer configuration.
  $this
    ->createImporterConfiguration();
  $this
    ->addMappings('syndication', array(
    0 => array(
      'source' => 'title',
      'target' => 'title',
      'unique' => FALSE,
    ),
    1 => array(
      'source' => 'description',
      'target' => 'body',
    ),
    2 => array(
      'source' => 'timestamp',
      'target' => 'created',
    ),
    3 => array(
      'source' => 'url',
      'target' => 'url',
      'unique' => TRUE,
    ),
    4 => array(
      'source' => 'guid',
      'target' => 'guid',
      'unique' => TRUE,
    ),
  ));

  // Create 10 feed nodes. Turn off import on create before doing that.
  $edit = array(
    'import_on_create' => FALSE,
  );
  $this
    ->drupalPost('admin/structure/feeds/syndication/settings', $edit, 'Save');
  $this
    ->assertText('Do not import on submission');
  $nids = $this
    ->createFeedNodes();

  // This implicitly tests the import_on_create node setting being 0.
  $this
    ->assertTrue($nids[0] == 1 && $nids[1] == 2, 'Node ids sequential.');

  // Check whether feed got properly added to scheduler.
  foreach ($nids as $nid) {
    $this
      ->assertEqual(1, db_query("SELECT COUNT(*) FROM {job_schedule} WHERE type = 'syndication' AND id = :nid AND name = 'feeds_source_import' AND last <> 0 AND scheduled = 0 AND period = 1800 AND periodic = 1", array(
      ':nid' => $nid,
    ))
      ->fetchField());
  }

  // Take time for comparisons.
  $time = time();
  sleep(1);

  // Log out and run cron, no changes.
  $this
    ->drupalLogout();
  $this
    ->cronRun();
  $count = db_query("SELECT COUNT(*) FROM {job_schedule} WHERE last > :time", array(
    ':time' => $time,
  ))
    ->fetchField();
  $this
    ->assertEqual($count, 0, '0 feeds refreshed on cron.' . $count);

  // Set next time to 0 to simulate updates.
  db_query("UPDATE {job_schedule} SET next = 0");
  return array(
    'time' => $time,
    'nids' => $nids,
    'count' => $count,
  );
}