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