1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains FeedsMapperProfileTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test suite for profile mapper mappers/profile.inc.
|
10
|
*/
|
11
|
class FeedsMapperProfileTestCase extends FeedsMapperTestCase {
|
12
|
|
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
|
public 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
|
public function test() {
|
30
|
// Create profile fields.
|
31
|
$edit = array(
|
32
|
'category' => 'test',
|
33
|
'title' => 'color',
|
34
|
'name' => 'profile_textfield_test',
|
35
|
'register' => 1,
|
36
|
);
|
37
|
$name = $this->drupalPost('admin/config/people/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
|
'register' => 1,
|
44
|
);
|
45
|
$name = $this->drupalPost('admin/config/people/profile/add/selection', $edit, t('Save field'));
|
46
|
|
47
|
// Create an importer.
|
48
|
$this->createImporterConfiguration('Profile import', 'profile_import');
|
49
|
|
50
|
// Set and configure plugins.
|
51
|
$this->setPlugin('profile_import', 'FeedsFileFetcher');
|
52
|
$this->setPlugin('profile_import', 'FeedsCSVParser');
|
53
|
$this->setPlugin('profile_import', 'FeedsUserProcessor');
|
54
|
|
55
|
// Go to mapping page and create a couple of mappings.
|
56
|
$mappings = array(
|
57
|
'0' => array(
|
58
|
'source' => 'name',
|
59
|
'target' => 'name',
|
60
|
'unique' => 0,
|
61
|
),
|
62
|
'1' => array(
|
63
|
'source' => 'mail',
|
64
|
'target' => 'mail',
|
65
|
'unique' => 1,
|
66
|
),
|
67
|
'2' => array(
|
68
|
'source' => 'color',
|
69
|
'target' => 'profile_textfield_test',
|
70
|
),
|
71
|
'3' => array(
|
72
|
'source' => 'letter',
|
73
|
'target' => 'profile_select_test',
|
74
|
),
|
75
|
);
|
76
|
$this->addMappings('profile_import', $mappings);
|
77
|
|
78
|
// Change some of the basic configuration.
|
79
|
$edit = array(
|
80
|
'content_type' => '',
|
81
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
82
|
);
|
83
|
$this->drupalPost('admin/structure/feeds/profile_import/settings', $edit, 'Save');
|
84
|
|
85
|
// Import CSV file.
|
86
|
$this->importFile('profile_import', $this->absolutePath() .'/tests/feeds/profile.csv');
|
87
|
$this->assertText('Created 2 users.');
|
88
|
|
89
|
// Check the two imported users.
|
90
|
$this->drupalGet('admin/people');
|
91
|
$this->assertText('magna');
|
92
|
$this->assertText('rhoncus');
|
93
|
|
94
|
$account = user_load_by_name('magna');
|
95
|
$this->assertEqual($account->profile_textfield_test, 'red', 'User profile_textfield_test is correct');
|
96
|
$this->assertEqual($account->profile_select_test, 'alpha', 'User profile_select_test is correct');
|
97
|
|
98
|
$account = user_load_by_name('rhoncus');
|
99
|
$this->assertEqual($account->profile_textfield_test, 'blue', 'User profile_textfield_test is correct');
|
100
|
$this->assertEqual($account->profile_select_test, 'beta', 'User profile_select_test is correct');
|
101
|
}
|
102
|
|
103
|
}
|