1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains FeedsMapperFieldTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test case for simple CCK field mapper mappers/content.inc.
|
10
|
*/
|
11
|
class FeedsMapperFieldTestCase extends FeedsMapperTestCase {
|
12
|
|
13
|
public static function getInfo() {
|
14
|
return array(
|
15
|
'name' => 'Mapper: Fields',
|
16
|
'description' => 'Test Feeds Mapper support for fields.',
|
17
|
'group' => 'Feeds',
|
18
|
);
|
19
|
}
|
20
|
|
21
|
public function setUp() {
|
22
|
parent::setUp(array('number'));
|
23
|
}
|
24
|
|
25
|
/**
|
26
|
* Basic test loading a double entry CSV file.
|
27
|
*/
|
28
|
public function test() {
|
29
|
// Create content type.
|
30
|
$typename = $this->createContentType(array(), array(
|
31
|
'alpha' => 'text',
|
32
|
'beta' => 'number_integer',
|
33
|
'gamma' => 'number_decimal',
|
34
|
'delta' => 'number_float',
|
35
|
));
|
36
|
|
37
|
// Create and configure importer.
|
38
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
39
|
$this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
|
40
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
41
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
42
|
$this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $typename));
|
43
|
$this->addMappings('csv', array(
|
44
|
0 => array(
|
45
|
'source' => 'title',
|
46
|
'target' => 'title',
|
47
|
),
|
48
|
1 => array(
|
49
|
'source' => 'created',
|
50
|
'target' => 'created',
|
51
|
),
|
52
|
2 => array(
|
53
|
'source' => 'body',
|
54
|
'target' => 'body',
|
55
|
),
|
56
|
3 => array(
|
57
|
'source' => 'alpha',
|
58
|
'target' => 'field_alpha',
|
59
|
),
|
60
|
4 => array(
|
61
|
'source' => 'beta',
|
62
|
'target' => 'field_beta',
|
63
|
),
|
64
|
5 => array(
|
65
|
'source' => 'gamma',
|
66
|
'target' => 'field_gamma',
|
67
|
),
|
68
|
6 => array(
|
69
|
'source' => 'delta',
|
70
|
'target' => 'field_delta',
|
71
|
),
|
72
|
));
|
73
|
|
74
|
// Import CSV file.
|
75
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
|
76
|
$this->assertText('Created 2 nodes');
|
77
|
|
78
|
// Check the two imported files.
|
79
|
$this->drupalGet('node/1/edit');
|
80
|
$this->assertNodeFieldValue('alpha', 'Lorem');
|
81
|
$this->assertNodeFieldValue('beta', '42');
|
82
|
$this->assertNodeFieldValue('gamma', '4.20');
|
83
|
$this->assertNodeFieldValue('delta', '3.14159');
|
84
|
|
85
|
$this->drupalGet('node/2/edit');
|
86
|
$this->assertNodeFieldValue('alpha', 'Ut wisi');
|
87
|
$this->assertNodeFieldValue('beta', '32');
|
88
|
$this->assertNodeFieldValue('gamma', '1.20');
|
89
|
$this->assertNodeFieldValue('delta', '5.62951');
|
90
|
}
|
91
|
|
92
|
/**
|
93
|
* Tests if values are cleared out when an empty value is provided.
|
94
|
*/
|
95
|
public function testClearOutValues() {
|
96
|
// Create content type.
|
97
|
$typename = $this->createContentType(array(), array(
|
98
|
'alpha' => 'text',
|
99
|
'beta' => 'number_integer',
|
100
|
'gamma' => 'number_decimal',
|
101
|
'delta' => 'number_float',
|
102
|
));
|
103
|
|
104
|
// Create and configure importer.
|
105
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
106
|
$this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
|
107
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
108
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
109
|
$this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $typename, 'update_existing' => 1));
|
110
|
$this->addMappings('csv', array(
|
111
|
array(
|
112
|
'source' => 'guid',
|
113
|
'target' => 'guid',
|
114
|
'unique' => TRUE,
|
115
|
),
|
116
|
array(
|
117
|
'source' => 'title',
|
118
|
'target' => 'title',
|
119
|
),
|
120
|
array(
|
121
|
'source' => 'created',
|
122
|
'target' => 'created',
|
123
|
),
|
124
|
array(
|
125
|
'source' => 'body',
|
126
|
'target' => 'body',
|
127
|
),
|
128
|
array(
|
129
|
'source' => 'alpha',
|
130
|
'target' => 'field_alpha',
|
131
|
),
|
132
|
array(
|
133
|
'source' => 'beta',
|
134
|
'target' => 'field_beta',
|
135
|
),
|
136
|
array(
|
137
|
'source' => 'gamma',
|
138
|
'target' => 'field_gamma',
|
139
|
),
|
140
|
array(
|
141
|
'source' => 'delta',
|
142
|
'target' => 'field_delta',
|
143
|
),
|
144
|
));
|
145
|
|
146
|
// Import CSV file.
|
147
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
|
148
|
$this->assertText('Created 2 nodes');
|
149
|
|
150
|
// Check the two imported nodes.
|
151
|
$this->drupalGet('node/1/edit');
|
152
|
$this->assertNodeFieldValue('alpha', 'Lorem');
|
153
|
$this->assertNodeFieldValue('beta', '42');
|
154
|
$this->assertNodeFieldValue('gamma', '4.20');
|
155
|
$this->assertNodeFieldValue('delta', '3.14159');
|
156
|
$this->assertFieldByName('body[und][0][value]', 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
|
157
|
$this->drupalGet('node/2/edit');
|
158
|
$this->assertNodeFieldValue('alpha', 'Ut wisi');
|
159
|
$this->assertNodeFieldValue('beta', '32');
|
160
|
$this->assertNodeFieldValue('gamma', '1.20');
|
161
|
$this->assertNodeFieldValue('delta', '5.62951');
|
162
|
$this->assertFieldByName('body[und][0][value]', 'Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.');
|
163
|
|
164
|
// Import CSV file with empty values.
|
165
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
|
166
|
$this->assertText('Updated 2 nodes');
|
167
|
|
168
|
// Check if all values were cleared out for node 1.
|
169
|
$this->drupalGet('node/1/edit');
|
170
|
$this->assertNoNodeFieldValue('alpha', 'Lorem');
|
171
|
$this->assertNoNodeFieldValue('beta', '42');
|
172
|
$this->assertNoNodeFieldValue('gamma', '4.20');
|
173
|
$this->assertNoNodeFieldValue('delta', '3.14159');
|
174
|
$this->assertFieldByName('body[und][0][value]', '');
|
175
|
// Check if labels for fields that should be cleared out are not shown.
|
176
|
$this->drupalGet('node/1');
|
177
|
$this->assertNoText('alpha_text_label');
|
178
|
$this->assertNoText('beta_number_integer_label');
|
179
|
$this->assertNoText('gamma_number_decimal_label');
|
180
|
$this->assertNoText('delta_number_float_label');
|
181
|
|
182
|
// Check if zero's didn't cleared out values for node 2.
|
183
|
$this->drupalGet('node/2/edit');
|
184
|
$this->assertNodeFieldValue('alpha', 0);
|
185
|
$this->assertNodeFieldValue('beta', 0);
|
186
|
$this->assertNodeFieldValue('gamma', 0);
|
187
|
$this->assertNodeFieldValue('delta', 0);
|
188
|
$this->assertFieldByName('body[und][0][value]', 0);
|
189
|
// Check if labels for fields of node 2 are still shown.
|
190
|
$this->drupalGet('node/2');
|
191
|
$this->assertText('alpha_text_label');
|
192
|
$this->assertText('beta_number_integer_label');
|
193
|
$this->assertText('gamma_number_decimal_label');
|
194
|
$this->assertText('delta_number_float_label');
|
195
|
|
196
|
// Re-import the first file again.
|
197
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
|
198
|
$this->assertText('Updated 2 nodes');
|
199
|
|
200
|
// Check if the two imported nodes have content again.
|
201
|
$this->drupalGet('node/1/edit');
|
202
|
$this->assertNodeFieldValue('alpha', 'Lorem');
|
203
|
$this->assertNodeFieldValue('beta', '42');
|
204
|
$this->assertNodeFieldValue('gamma', '4.20');
|
205
|
$this->assertNodeFieldValue('delta', '3.14159');
|
206
|
$this->assertFieldByName('body[und][0][value]', 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.');
|
207
|
$this->drupalGet('node/2/edit');
|
208
|
$this->assertNodeFieldValue('alpha', 'Ut wisi');
|
209
|
$this->assertNodeFieldValue('beta', '32');
|
210
|
$this->assertNodeFieldValue('gamma', '1.20');
|
211
|
$this->assertNodeFieldValue('delta', '5.62951');
|
212
|
$this->assertFieldByName('body[und][0][value]', 'Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.');
|
213
|
|
214
|
// Import CSV file with non-existent values.
|
215
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
|
216
|
$this->assertText('Updated 2 nodes');
|
217
|
|
218
|
// Check if all values were cleared out for node 1.
|
219
|
$this->drupalGet('node/1/edit');
|
220
|
$this->assertNoNodeFieldValue('alpha', 'Lorem');
|
221
|
$this->assertNoNodeFieldValue('beta', '42');
|
222
|
$this->assertNoNodeFieldValue('gamma', '4.20');
|
223
|
$this->assertNoNodeFieldValue('delta', '3.14159');
|
224
|
$this->assertFieldByName('body[und][0][value]', '');
|
225
|
// Check if labels for fields that should be cleared out are not shown.
|
226
|
$this->drupalGet('node/1');
|
227
|
$this->assertNoText('alpha_text_label');
|
228
|
$this->assertNoText('beta_number_integer_label');
|
229
|
$this->assertNoText('gamma_number_decimal_label');
|
230
|
$this->assertNoText('delta_number_float_label');
|
231
|
}
|
232
|
|
233
|
}
|