Example #1
0
 public function testCron()
 {
     // Run cron once before, so any other bookkeeping can get done.
     $this->cronRun();
     $this->type->setImportPeriod(3600);
     $mappings = $this->type->getMappings();
     unset($mappings[2]['unique']);
     $this->type->setMappings($mappings);
     $this->type->save();
     $filepath = drupal_get_path('module', 'feeds') . '/tests/resources/googlenewstz.rss2';
     $feed = Feed::create(['title' => $this->randomString(), 'source' => file_create_url($filepath), 'type' => $this->type->id()]);
     $feed->save();
     // Verify initial values.
     $feed = $this->reloadFeed($feed->id());
     $this->assertEqual($feed->getImportedTime(), 0);
     $this->assertEqual($feed->getNextImportTime(), 0);
     $this->assertEqual($feed->getItemCount(), 0);
     // Cron should import some nodes.
     // Clear the download cache so that the http fetcher doesn't trick us.
     \Drupal::cache('feeds_download')->deleteAll();
     sleep(1);
     $this->cronRun();
     // Run cron twice for testbot.
     $this->cronRun();
     $feed = $this->reloadFeed($feed->id());
     $this->assertEqual($feed->getItemCount(), 6);
     $imported = $feed->getImportedTime();
     $this->assertTrue($imported > 0);
     $this->assertEqual($feed->getNextImportTime(), $imported + 3600);
     // Nothing should change on this cron run.
     \Drupal::cache('feeds_download')->deleteAll();
     sleep(1);
     $this->cronRun();
     $feed = $this->reloadFeed($feed->id());
     $this->assertEqual($feed->getItemCount(), 6);
     $this->assertEqual($feed->getImportedTime(), $imported);
     $this->assertEqual($feed->getNextImportTime(), $imported + 3600);
     // Check that items import normally.
     \Drupal::cache('feeds_download')->deleteAll();
     sleep(1);
     $this->drupalPostForm('feed/' . $feed->id() . '/import', [], t('Import'));
     $feed = $this->reloadFeed($feed->id());
     $this->assertEqual($feed->getItemCount(), 12);
     $this->assertTrue($feed->getImportedTime() > $imported);
     $this->assertEqual($feed->getNextImportTime(), $feed->getImportedTime() + 3600);
 }