feeds_fetcher_file.test 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @file
  4. * File fetcher tests.
  5. */
  6. /**
  7. * File fetcher test class.
  8. */
  9. class FeedsFileFetcherTestCase extends FeedsWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'File fetcher',
  13. 'description' => 'Tests for file fetcher plugin.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. /**
  18. * Test scheduling on cron.
  19. */
  20. public function test() {
  21. // Set up an importer.
  22. $this->createImporterConfiguration('Node import', 'node');
  23. // Set and configure plugins and mappings.
  24. $edit = array(
  25. 'content_type' => '',
  26. );
  27. $this->drupalPost('admin/structure/feeds/node/settings', $edit, 'Save');
  28. $this->setPlugin('node', 'FeedsFileFetcher');
  29. $this->setPlugin('node', 'FeedsCSVParser');
  30. $mappings = array(
  31. '0' => array(
  32. 'source' => 'title',
  33. 'target' => 'title',
  34. ),
  35. );
  36. $this->addMappings('node', $mappings);
  37. // Straight up upload is covered in other tests, focus on direct mode
  38. // and file batching here.
  39. $this->setSettings('node', 'FeedsFileFetcher', array('direct' => TRUE));
  40. // Verify that invalid paths are not accepted.
  41. foreach (array('private://', '/tmp/') as $path) {
  42. $edit = array(
  43. 'feeds[FeedsFileFetcher][source]' => $path,
  44. );
  45. $this->drupalPost('import/node', $edit, t('Import'));
  46. $this->assertText("File needs to reside within the site's file directory, its path needs to start with public://.");
  47. $count = db_query("SELECT COUNT(*) FROM {feeds_source} WHERE feed_nid = 0")->fetchField();
  48. $this->assertEqual($count, 0);
  49. }
  50. // Verify batching through directories.
  51. // Copy directory of files.
  52. $dir = 'public://batchtest';
  53. $this->copyDir($this->absolutePath() . '/tests/feeds/batch', $dir);
  54. // Ingest directory of files. Set limit to 5 to force processor to batch,
  55. // too.
  56. variable_set('feeds_process_limit', 5);
  57. $edit = array(
  58. 'feeds[FeedsFileFetcher][source]' => $dir,
  59. );
  60. $this->drupalPost('import/node', $edit, t('Import'));
  61. $this->assertText('Created 18 nodes');
  62. }
  63. }