feeds_mapper_field.test 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @file
  4. * Test case for simple CCK field mapper mappers/content.inc.
  5. */
  6. /**
  7. * Class for testing Feeds field mapper.
  8. */
  9. class FeedsMapperFieldTestCase extends FeedsMapperTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Mapper: Fields',
  13. 'description' => 'Test Feeds Mapper support for fields.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. public function setUp() {
  18. parent::setUp(array('number'));
  19. }
  20. /**
  21. * Basic test loading a double entry CSV file.
  22. */
  23. function test() {
  24. // Create content type.
  25. $typename = $this->createContentType(array(), array(
  26. 'alpha' => 'text',
  27. 'beta' => 'number_integer',
  28. 'gamma' => 'number_decimal',
  29. 'delta' => 'number_float',
  30. ));
  31. // Create and configure importer.
  32. $this->createImporterConfiguration('Content CSV', 'csv');
  33. $this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
  34. $this->setPlugin('csv', 'FeedsFileFetcher');
  35. $this->setPlugin('csv', 'FeedsCSVParser');
  36. $this->setSettings('csv', 'FeedsNodeProcessor', array('content_type' => $typename));
  37. $this->addMappings('csv', array(
  38. 0 => array(
  39. 'source' => 'title',
  40. 'target' => 'title',
  41. ),
  42. 1 => array(
  43. 'source' => 'created',
  44. 'target' => 'created',
  45. ),
  46. 2 => array(
  47. 'source' => 'body',
  48. 'target' => 'body',
  49. ),
  50. 3 => array(
  51. 'source' => 'alpha',
  52. 'target' => 'field_alpha',
  53. ),
  54. 4 => array(
  55. 'source' => 'beta',
  56. 'target' => 'field_beta',
  57. ),
  58. 5 => array(
  59. 'source' => 'gamma',
  60. 'target' => 'field_gamma',
  61. ),
  62. 6 => array(
  63. 'source' => 'delta',
  64. 'target' => 'field_delta',
  65. ),
  66. ));
  67. // Import CSV file.
  68. $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
  69. $this->assertText('Created 2 nodes');
  70. // Check the two imported files.
  71. $this->drupalGet('node/1/edit');
  72. $this->assertNodeFieldValue('alpha', 'Lorem');
  73. $this->assertNodeFieldValue('beta', '42');
  74. $this->assertNodeFieldValue('gamma', '4.20');
  75. $this->assertNodeFieldValue('delta', '3.14159');
  76. $this->drupalGet('node/2/edit');
  77. $this->assertNodeFieldValue('alpha', 'Ut wisi');
  78. $this->assertNodeFieldValue('beta', '32');
  79. $this->assertNodeFieldValue('gamma', '1.20');
  80. $this->assertNodeFieldValue('delta', '5.62951');
  81. }
  82. }