feeds_fetcher_file.test 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 testPublicFiles() {
  21. // Set up an importer.
  22. $this->createImporterConfiguration('Node import', 'node');
  23. // Set and configure plugins and mappings.
  24. $this->setSettings('node', NULL, array('content_type' => ''));
  25. $this->setPlugin('node', 'FeedsFileFetcher');
  26. $this->setPlugin('node', 'FeedsCSVParser');
  27. $mappings = array(
  28. '0' => array(
  29. 'source' => 'title',
  30. 'target' => 'title',
  31. ),
  32. );
  33. $this->addMappings('node', $mappings);
  34. // Straight up upload is covered in other tests, focus on direct mode
  35. // and file batching here.
  36. $settings = array(
  37. 'direct' => TRUE,
  38. 'directory' => 'public://feeds',
  39. );
  40. $this->setSettings('node', 'FeedsFileFetcher', $settings);
  41. // Verify that invalid paths are not accepted.
  42. foreach (array('/tmp/') as $path) {
  43. $edit = array(
  44. 'feeds[FeedsFileFetcher][source]' => $path,
  45. );
  46. $this->drupalPost('import/node', $edit, t('Import'));
  47. $this->assertText("The file needs to reside within the site's files directory, its path needs to start with scheme://. Available schemes:");
  48. $count = db_query("SELECT COUNT(*) FROM {feeds_source} WHERE feed_nid = 0")->fetchField();
  49. $this->assertEqual($count, 0);
  50. }
  51. // Verify batching through directories.
  52. // Copy directory of files.
  53. $dir = 'public://batchtest';
  54. $this->copyDir($this->absolutePath() . '/tests/feeds/batch', $dir);
  55. // Ingest directory of files. Set limit to 5 to force processor to batch,
  56. // too.
  57. variable_set('feeds_process_limit', 5);
  58. $edit = array(
  59. 'feeds[FeedsFileFetcher][source]' => $dir,
  60. );
  61. $this->drupalPost('import/node', $edit, t('Import'));
  62. $this->assertText('Created 18 nodes');
  63. }
  64. /**
  65. * Test uploading private files.
  66. */
  67. public function testPrivateFiles() {
  68. // Set up an importer.
  69. $this->createImporterConfiguration('Node import', 'node');
  70. // Set and configure plugins and mappings.
  71. $edit = array(
  72. 'content_type' => '',
  73. );
  74. $this->drupalPost('admin/structure/feeds/node/settings', $edit, 'Save');
  75. $this->setPlugin('node', 'FeedsFileFetcher');
  76. $this->setPlugin('node', 'FeedsCSVParser');
  77. $mappings = array(
  78. '0' => array(
  79. 'source' => 'title',
  80. 'target' => 'title',
  81. ),
  82. );
  83. $this->addMappings('node', $mappings);
  84. // Straight up upload is covered in other tests, focus on direct mode
  85. // and file batching here.
  86. $settings = array(
  87. 'direct' => TRUE,
  88. 'directory' => 'private://feeds',
  89. );
  90. $this->setSettings('node', 'FeedsFileFetcher', $settings);
  91. // Verify batching through directories.
  92. // Copy directory of files.
  93. $dir = 'private://batchtest';
  94. $this->copyDir($this->absolutePath() . '/tests/feeds/batch', $dir);
  95. // Ingest directory of files. Set limit to 5 to force processor to batch,
  96. // too.
  97. variable_set('feeds_process_limit', 5);
  98. $edit = array(
  99. 'feeds[FeedsFileFetcher][source]' => $dir,
  100. );
  101. $this->drupalPost('import/node', $edit, t('Import'));
  102. $this->assertText('Created 18 nodes');
  103. }
  104. }