feeds_processor_term.test 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @file
  4. * Tests for plugins/FeedsTermProcessor.inc
  5. */
  6. /**
  7. * Test aggregating a feed as data records.
  8. */
  9. class FeedsCSVtoTermsTest extends FeedsWebTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'CSV import to taxonomy',
  13. 'description' => 'Tests a standalone import configuration that uses file fetcher and CSV parser to import taxonomy terms from a CSV file.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. /**
  18. * Test node creation, refreshing/deleting feeds and feed items.
  19. */
  20. public function test() {
  21. // Create an importer.
  22. $this->createImporterConfiguration('Term import', 'term_import');
  23. // Set and configure plugins and mappings.
  24. $this->setPlugin('term_import', 'FeedsFileFetcher');
  25. $this->setPlugin('term_import', 'FeedsCSVParser');
  26. $this->setPlugin('term_import', 'FeedsTermProcessor');
  27. $mappings = array(
  28. 0 => array(
  29. 'source' => 'name',
  30. 'target' => 'name',
  31. 'unique' => 1,
  32. ),
  33. );
  34. $this->addMappings('term_import', $mappings);
  35. // Use standalone form.
  36. $edit = array(
  37. 'content_type' => '',
  38. );
  39. $this->drupalPost('admin/structure/feeds/term_import/settings', $edit, 'Save');
  40. $edit = array(
  41. 'name' => 'Addams vocabulary',
  42. 'machine_name' => 'addams',
  43. );
  44. $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
  45. $edit = array(
  46. 'vocabulary' => 'addams',
  47. );
  48. $this->drupalPost('admin/structure/feeds/term_import/settings/FeedsTermProcessor', $edit, t('Save'));
  49. // Import and assert.
  50. $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
  51. $this->assertText('Created 5 terms');
  52. $this->drupalGet('admin/structure/taxonomy/addams');
  53. $this->assertText('Morticia');
  54. $this->assertText('Fester');
  55. $this->assertText('Gomez');
  56. $this->assertText('Pugsley');
  57. // Import again.
  58. $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
  59. $this->assertText('There are no new terms.');
  60. // Force update.
  61. $this->setSettings('term_import', 'FeedsTermProcessor', array(
  62. 'skip_hash_check' => TRUE,
  63. 'update_existing' => 2,
  64. ));
  65. $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
  66. $this->assertText('Updated 5 terms.');
  67. // Add a term manually, delete all terms, this term should still stand.
  68. $edit = array(
  69. 'name' => 'Cousin Itt',
  70. );
  71. $this->drupalPost('admin/structure/taxonomy/addams/add', $edit, t('Save'));
  72. $this->drupalPost('import/term_import/delete-items', array(), t('Delete'));
  73. $this->drupalGet('admin/structure/taxonomy/addams');
  74. $this->assertText('Cousin Itt');
  75. $this->assertNoText('Morticia');
  76. $this->assertNoText('Fester');
  77. $this->assertNoText('Gomez');
  78. $this->assertNoText('Pugsley');
  79. }
  80. }