feeds_mapper_date_multiple.test 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @file
  4. * Contains FeedsMapperDateMultipleTestCase.
  5. */
  6. /**
  7. * Test case for CCK date multi-field mapper mappers/date.inc.
  8. *
  9. * @todo: Add test method iCal
  10. * @todo: Add test method for end date
  11. */
  12. class FeedsMapperDateMultipleTestCase extends FeedsMapperTestCase {
  13. public static function getInfo() {
  14. return array(
  15. 'name' => 'Mapper: Date, multi value fields',
  16. 'description' => 'Test Feeds Mapper support for CCK multi valiue Date fields.',
  17. 'group' => 'Feeds',
  18. 'dependencies' => array('date', 'feeds_xpathparser'),
  19. );
  20. }
  21. public function setUp() {
  22. parent::setUp(array('date_api', 'date', 'feeds_xpathparser'));
  23. variable_set('date_default_timezone', 'UTC');
  24. }
  25. /**
  26. * Testing import by loading a 4 item XML file.
  27. */
  28. public function test() {
  29. $this->drupalGet('admin/config/regional/settings');
  30. // Create content type.
  31. $typename = $this->createContentType(array(), array(
  32. 'date' => 'date',
  33. ));
  34. // Make the field hold unlimited values
  35. $edit = array(
  36. 'field[cardinality]' => -1,
  37. );
  38. $this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/field_date', $edit, 'Save settings');
  39. $this->assertText('Saved date_date_label configuration');
  40. // Create and configure importer.
  41. $this->createImporterConfiguration('Multi dates', 'multidates');
  42. $this->setSettings('multidates', NULL, array(
  43. 'content_type' => '',
  44. 'import_period' => FEEDS_SCHEDULE_NEVER,
  45. ));
  46. $this->setPlugin('multidates', 'FeedsFileFetcher');
  47. $this->setPlugin('multidates', 'FeedsXPathParserXML');
  48. $this->setSettings('multidates', 'FeedsNodeProcessor', array(
  49. 'bundle' => $typename,
  50. ));
  51. $this->addMappings('multidates', array(
  52. 0 => array(
  53. 'source' => 'xpathparser:0',
  54. 'target' => 'title',
  55. ),
  56. 1 => array(
  57. 'source' => 'xpathparser:1',
  58. 'target' => 'guid',
  59. ),
  60. 2 => array(
  61. 'source' => 'xpathparser:2',
  62. 'target' => 'field_date:start',
  63. ),
  64. ));
  65. $edit = array(
  66. 'xpath[context]' => '//item',
  67. 'xpath[sources][xpathparser:0]' => 'title',
  68. 'xpath[sources][xpathparser:1]' => 'guid',
  69. 'xpath[sources][xpathparser:2]' => 'date',
  70. 'xpath[allow_override]' => FALSE,
  71. );
  72. $this->setSettings('multidates', 'FeedsXPathParserXML', $edit);
  73. $edit = array(
  74. 'allowed_extensions' => 'xml',
  75. 'directory' => 'public://feeds',
  76. );
  77. $this->setSettings('multidates', 'FeedsFileFetcher', $edit);
  78. // Import XML file.
  79. $this->importFile('multidates', $this->absolutePath() . '/tests/feeds/multi-date.xml');
  80. $this->assertText('Created 4 nodes');
  81. // Check the imported nodes.
  82. $values = array(
  83. 1 => array(
  84. '01/06/2010 - 15:00',
  85. '01/07/2010 - 15:15',
  86. ),
  87. 2 => array(
  88. '01/06/2010 - 15:00',
  89. '01/07/2010 - 15:00',
  90. '01/08/2010 - 15:00',
  91. '01/09/2010 - 15:00',
  92. ),
  93. 3 => array(
  94. '', // Bogus date was filtered out.
  95. ),
  96. 4 => array(
  97. '01/06/2010 - 14:00',
  98. )
  99. );
  100. foreach ($values as $v => $key) {
  101. $this->drupalGet("node/$v/edit");
  102. foreach ($key as $delta => $value) {
  103. $this->assertFieldById('edit-field-date-und-' . $delta . '-value-date', $value);
  104. }
  105. }
  106. }
  107. }