feeds_mapper_profile.test 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * @file
  4. * Contains FeedsMapperProfileTestCase.
  5. */
  6. /**
  7. * Test suite for profile mapper mappers/profile.inc.
  8. */
  9. class FeedsMapperProfileTestCase extends FeedsMapperTestCase {
  10. public static function getInfo() {
  11. return array(
  12. 'name' => 'Mapper: Profile',
  13. 'description' => 'Test Feeds Mapper support for profile fields.',
  14. 'group' => 'Feeds',
  15. );
  16. }
  17. public function setUp() {
  18. // Call parent setup with required modules.
  19. parent::setUp(array('profile'));
  20. }
  21. /**
  22. * Basic test loading a double entry CSV file.
  23. */
  24. public function test() {
  25. // Create profile fields.
  26. $edit = array(
  27. 'category' => 'test',
  28. 'title' => 'color',
  29. 'name' => 'profile_textfield_test',
  30. 'register' => 1,
  31. );
  32. $name = $this->drupalPost('admin/config/people/profile/add/textfield', $edit, t('Save field'));
  33. $edit = array(
  34. 'category' => 'test',
  35. 'title' => 'letter',
  36. 'name' => 'profile_select_test',
  37. 'options' => 'alpha' . "\n" . 'beta' . "\n" . 'gamma',
  38. 'register' => 1,
  39. );
  40. $name = $this->drupalPost('admin/config/people/profile/add/selection', $edit, t('Save field'));
  41. // Create an importer.
  42. $this->createImporterConfiguration('Profile import', 'profile_import');
  43. // Set and configure plugins.
  44. $this->setPlugin('profile_import', 'FeedsFileFetcher');
  45. $this->setPlugin('profile_import', 'FeedsCSVParser');
  46. $this->setPlugin('profile_import', 'FeedsUserProcessor');
  47. // Go to mapping page and create a couple of mappings.
  48. $mappings = array(
  49. '0' => array(
  50. 'source' => 'name',
  51. 'target' => 'name',
  52. 'unique' => 0,
  53. ),
  54. '1' => array(
  55. 'source' => 'mail',
  56. 'target' => 'mail',
  57. 'unique' => 1,
  58. ),
  59. '2' => array(
  60. 'source' => 'color',
  61. 'target' => 'profile_textfield_test',
  62. ),
  63. '3' => array(
  64. 'source' => 'letter',
  65. 'target' => 'profile_select_test',
  66. ),
  67. );
  68. $this->addMappings('profile_import', $mappings);
  69. // Change some of the basic configuration.
  70. $edit = array(
  71. 'content_type' => '',
  72. 'import_period' => FEEDS_SCHEDULE_NEVER,
  73. );
  74. $this->drupalPost('admin/structure/feeds/profile_import/settings', $edit, 'Save');
  75. // Import CSV file.
  76. $this->importFile('profile_import', $this->absolutePath() .'/tests/feeds/profile.csv');
  77. $this->assertText('Created 2 users.');
  78. // Check the two imported users.
  79. $this->drupalGet('admin/people');
  80. $this->assertText('magna');
  81. $this->assertText('rhoncus');
  82. $account = user_load_by_name('magna');
  83. $this->assertEqual($account->profile_textfield_test, 'red', 'User profile_textfield_test is correct');
  84. $this->assertEqual($account->profile_select_test, 'alpha', 'User profile_select_test is correct');
  85. $account = user_load_by_name('rhoncus');
  86. $this->assertEqual($account->profile_textfield_test, 'blue', 'User profile_textfield_test is correct');
  87. $this->assertEqual($account->profile_select_test, 'beta', 'User profile_select_test is correct');
  88. }
  89. }