feeds_mapper_unique.test 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @file
  4. * Contains FeedsMapperUniqueTestCase.
  5. */
  6. /**
  7. * Class for testing Feeds unique callbacks.
  8. */
  9. class FeedsMapperUniqueTestCase extends FeedsMapperTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Unique target callbacks',
  13. 'description' => 'Test unique target callbacks in mappers.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. /**
  18. * Test mapping target "unique_callbacks".
  19. */
  20. public function test() {
  21. // Create content type.
  22. $typename = $this->createContentType(array(), array('alpha' => 'text'));
  23. // Create two nodes. Put unique value into field field_alpha.
  24. $node1 = $this->drupalCreateNode(array(
  25. 'type' => $typename,
  26. 'field_alpha' => array(
  27. LANGUAGE_NONE => array(
  28. 0 => array(
  29. 'value' => 'Ut wisi',
  30. ),
  31. ),
  32. ),
  33. ));
  34. $node2 = $this->drupalCreateNode(array(
  35. 'type' => $typename,
  36. 'field_alpha' => array(
  37. LANGUAGE_NONE => array(
  38. 0 => array(
  39. 'value' => 'Lorem',
  40. ),
  41. ),
  42. ),
  43. ));
  44. // Create and configure importer.
  45. $this->createImporterConfiguration('Syndication', 'syndication');
  46. $this->setPlugin('syndication', 'FeedsFileFetcher');
  47. $this->setPlugin('syndication', 'FeedsCSVParser');
  48. $this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename, 'update_existing' => 2));
  49. $this->addMappings('syndication', array(
  50. 0 => array(
  51. 'source' => 'title',
  52. 'target' => 'title',
  53. ),
  54. 1 => array(
  55. 'source' => 'alpha',
  56. 'target' => 'test_unique_target',
  57. 'unique' => TRUE,
  58. ),
  59. ));
  60. // Import CSV file.
  61. $this->importFile('syndication', $this->absolutePath() . '/tests/feeds/content.csv');
  62. $this->assertText('Updated 2 nodes');
  63. // Ensure the updated nodes have the expected title now.
  64. $node1 = node_load($node1->nid, NULL, TRUE);
  65. $this->assertEqual('Ut wisi enim ad minim veniam', $node1->title, 'Node 1 has the expected title.');
  66. $node2 = node_load($node2->nid, NULL, TRUE);
  67. $this->assertEqual('Lorem ipsum', $node2->title, 'Node 2 has the expected title.');
  68. }
  69. }