diff --git a/includes/FeedsSource.inc b/includes/FeedsSource.inc index 42f1be1..0fcf9e8 100644 --- a/includes/FeedsSource.inc +++ b/includes/FeedsSource.inc @@ -693,7 +693,7 @@ class FeedsSource extends FeedsConfigurable { $queue_created = db_select('queue') ->fields('queue', array('created')) ->condition('name', 'feeds_source_import') - ->condition('data', 's:4:"type";s:[0-9]*:"' . db_like($this->id) . '";s:2:"id";(i|s:[0-9]*):' . db_like($this->feed_nid), 'REGEXP') + ->condition('data', 's:4:"type";s:[0-9]*:"' . db_like($this->id) . '";s:2:"id";(i|s:[0-9]*):"?' . db_like($this->feed_nid) . '"?', 'REGEXP') ->execute() ->fetchField(); diff --git a/tests/feeds_scheduler.test b/tests/feeds_scheduler.test index c57b324..3f16487 100644 --- a/tests/feeds_scheduler.test +++ b/tests/feeds_scheduler.test @@ -241,6 +241,77 @@ class FeedsSchedulerTestCase extends FeedsWebTestCase { } /** + * Tests if the expected next import time is shown when the import is queued + * via background job. + */ + public function testNextImportTimeWhenQueuedViaBackgroundJob() { + // Create an importer that uses a background job to import. + $this->createImporterConfiguration('Node import', 'node'); + $edit = array( + 'content_type' => '', + 'import_on_create' => TRUE, + 'process_in_background' => TRUE, + ); + $this->drupalPost('admin/structure/feeds/node/settings', $edit, 'Save'); + $this->setPlugin('node', 'FeedsFileFetcher'); + $this->setPlugin('node', 'FeedsCSVParser'); + $mappings = array( + 0 => array( + 'source' => 'title', + 'target' => 'title', + ), + ); + $this->addMappings('node', $mappings); + + // Specify a file with many nodes. + $this->importFile('node', $this->absolutePath() . '/tests/feeds/many_nodes.csv'); + + // Verify that a queue item is created. + $count = db_query("SELECT COUNT(*) FROM {queue} WHERE name = 'feeds_source_import'")->fetchField(); + $this->assertEqual(1, $count, format_string('One import item is queued (actual: @count).', array( + '@count' => $count, + ))); + + // The page should say that import happens on next cron. + $this->assertText('Next import: on next cron run'); + } + + /** + * Tests if the expected next import time is shown when the import is queued + * via Job Scheduler. + */ + public function testNextImportTimeWhenQueuedViaJobScheduler() { + $this->initSyndication(); + $this->drupalLogin($this->admin_user); + + // Manually dispatch a job. + $job = db_select('job_schedule', NULL, array('fetch' => PDO::FETCH_ASSOC)) + ->fields('job_schedule') + ->condition('type', 'syndication') + ->condition('id', 18) + ->execute() + ->fetch(); + try { + JobScheduler::get($job['name'])->dispatch($job); + $this->pass('No exceptions occurred while dispatching a feeds job.'); + } + catch (Exception $e) { + watchdog_exception('feeds', $e); + $this->fail('No exceptions occurred while dispatching a feeds job.'); + } + + // Verify that a queue item is created. + $count = db_query("SELECT COUNT(*) FROM {queue} WHERE name = 'feeds_source_import'")->fetchField(); + $this->assertEqual(1, $count, format_string('One import item is queued (actual: @count).', array( + '@count' => $count, + ))); + + // The page should say that import happens on next cron. + $this->drupalGet('node/18/import'); + $this->assertText('Next import: on next cron run'); + } + + /** * Test batching on cron. */ function testBatching() {