1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains FeedsMapperDateTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test case for CCK date field mapper mappers/date.inc.
|
10
|
*
|
11
|
* @todo: Add test method iCal
|
12
|
* @todo: Add test method for end date
|
13
|
*/
|
14
|
class FeedsMapperDateTestCase extends FeedsMapperTestCase {
|
15
|
|
16
|
public static function getInfo() {
|
17
|
return array(
|
18
|
'name' => 'Mapper: Date',
|
19
|
'description' => 'Test Feeds Mapper support for CCK Date fields.',
|
20
|
'group' => 'Feeds',
|
21
|
'dependencies' => array('date'),
|
22
|
);
|
23
|
}
|
24
|
|
25
|
public function setUp() {
|
26
|
parent::setUp(array('date_api', 'date'));
|
27
|
variable_set('date_default_timezone', 'UTC');
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* Basic test loading a single entry CSV file.
|
32
|
*/
|
33
|
public function test() {
|
34
|
$this->drupalGet('admin/config/regional/settings');
|
35
|
|
36
|
// Create content type.
|
37
|
$typename = $this->createContentType(array(), array(
|
38
|
'date' => 'date',
|
39
|
'datestamp' => 'datestamp',
|
40
|
//'datetime' => 'datetime', // REMOVED because the field is broken ATM.
|
41
|
));
|
42
|
|
43
|
// Hack to get date fields to not round to every 15 minutes.
|
44
|
foreach (array('date', 'datestamp') as $field) {
|
45
|
$field = 'field_' . $field;
|
46
|
$edit = array(
|
47
|
'widget_type' => 'date_select',
|
48
|
);
|
49
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field . '/widget-type', $edit, 'Continue');
|
50
|
$edit = array(
|
51
|
'instance[widget][settings][increment]' => 1,
|
52
|
);
|
53
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field, $edit, 'Save settings');
|
54
|
$edit = array(
|
55
|
'widget_type' => 'date_text',
|
56
|
);
|
57
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field . '/widget-type', $edit, 'Continue');
|
58
|
}
|
59
|
|
60
|
// Create and configure importer.
|
61
|
$this->createImporterConfiguration('Date RSS', 'daterss');
|
62
|
$this->setSettings('daterss', NULL, array(
|
63
|
'content_type' => '',
|
64
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
65
|
));
|
66
|
$this->setPlugin('daterss', 'FeedsFileFetcher');
|
67
|
$this->setSettings('daterss', 'FeedsNodeProcessor', array(
|
68
|
'bundle' => $typename,
|
69
|
));
|
70
|
$this->addMappings('daterss', array(
|
71
|
0 => array(
|
72
|
'source' => 'title',
|
73
|
'target' => 'title',
|
74
|
),
|
75
|
1 => array(
|
76
|
'source' => 'description',
|
77
|
'target' => 'body',
|
78
|
),
|
79
|
2 => array(
|
80
|
'source' => 'timestamp',
|
81
|
'target' => 'field_date:start',
|
82
|
),
|
83
|
3 => array(
|
84
|
'source' => 'timestamp',
|
85
|
'target' => 'field_datestamp:start',
|
86
|
),
|
87
|
));
|
88
|
|
89
|
$edit = array(
|
90
|
'allowed_extensions' => 'rss2',
|
91
|
);
|
92
|
$this->drupalPost('admin/structure/feeds/daterss/settings/FeedsFileFetcher', $edit, 'Save');
|
93
|
|
94
|
// Import CSV file.
|
95
|
$this->importFile('daterss', $this->absolutePath() . '/tests/feeds/googlenewstz.rss2');
|
96
|
$this->assertText('Created 6 nodes');
|
97
|
|
98
|
// Check the imported nodes.
|
99
|
$values = array(
|
100
|
'01/06/2010 - 19:26',
|
101
|
'01/06/2010 - 10:21',
|
102
|
'01/06/2010 - 13:42',
|
103
|
'01/06/2010 - 06:05',
|
104
|
'01/06/2010 - 11:26',
|
105
|
'01/07/2010 - 00:26',
|
106
|
);
|
107
|
for ($i = 1; $i <= 6; $i++) {
|
108
|
$this->drupalGet("node/$i/edit");
|
109
|
$this->assertNodeFieldValue('date', $values[$i-1]);
|
110
|
$this->assertNodeFieldValue('datestamp', $values[$i-1]);
|
111
|
}
|
112
|
}
|
113
|
|
114
|
protected function getFormFieldsNames($field_name, $index) {
|
115
|
if (in_array($field_name, array('date', 'datetime', 'datestamp'))) {
|
116
|
return array("field_{$field_name}[und][{$index}][value][date]");
|
117
|
}
|
118
|
else {
|
119
|
return parent::getFormFieldsNames($field_name, $index);
|
120
|
}
|
121
|
}
|
122
|
|
123
|
/**
|
124
|
* Tests if values are cleared out when an empty value is provided.
|
125
|
*/
|
126
|
public function testClearOutValues() {
|
127
|
// Create content type.
|
128
|
$typename = $this->createContentType(array(), array(
|
129
|
'date' => 'date',
|
130
|
'datestamp' => 'datestamp',
|
131
|
'datetime' => 'datetime',
|
132
|
));
|
133
|
|
134
|
// Hack to get date fields to not round to every 15 minutes.
|
135
|
foreach (array('date', 'datestamp', 'datetime') as $field) {
|
136
|
$field = 'field_' . $field;
|
137
|
$edit = array(
|
138
|
'widget_type' => 'date_select',
|
139
|
);
|
140
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field . '/widget-type', $edit, 'Continue');
|
141
|
$edit = array(
|
142
|
'instance[widget][settings][increment]' => 1,
|
143
|
'field[settings][enddate_get]' => 1,
|
144
|
);
|
145
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field, $edit, 'Save settings');
|
146
|
$edit = array(
|
147
|
'widget_type' => 'date_text',
|
148
|
);
|
149
|
$this->drupalPost('admin/structure/types/manage/' . $typename . '/fields/' . $field . '/widget-type', $edit, 'Continue');
|
150
|
}
|
151
|
|
152
|
// Create and configure importer.
|
153
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
154
|
$this->setSettings('csv', NULL, array(
|
155
|
'content_type' => '',
|
156
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
157
|
));
|
158
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
159
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
160
|
$this->setSettings('csv', 'FeedsNodeProcessor', array(
|
161
|
'bundle' => $typename,
|
162
|
'update_existing' => 1,
|
163
|
));
|
164
|
$this->addMappings('csv', array(
|
165
|
0 => array(
|
166
|
'source' => 'title',
|
167
|
'target' => 'title',
|
168
|
'unique' => TRUE,
|
169
|
),
|
170
|
1 => array(
|
171
|
'source' => 'created',
|
172
|
'target' => 'field_date:start',
|
173
|
),
|
174
|
2 => array(
|
175
|
'source' => 'end',
|
176
|
'target' => 'field_date:end',
|
177
|
),
|
178
|
3 => array(
|
179
|
'source' => 'created',
|
180
|
'target' => 'field_datestamp:start',
|
181
|
),
|
182
|
4 => array(
|
183
|
'source' => 'end',
|
184
|
'target' => 'field_datestamp:end',
|
185
|
),
|
186
|
5 => array(
|
187
|
'source' => 'created',
|
188
|
'target' => 'field_datetime:start',
|
189
|
),
|
190
|
6 => array(
|
191
|
'source' => 'end',
|
192
|
'target' => 'field_datetime:end',
|
193
|
),
|
194
|
));
|
195
|
|
196
|
// Import CSV file.
|
197
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_date.csv');
|
198
|
$this->assertText('Created 2 nodes');
|
199
|
|
200
|
// Check the imported nodes.
|
201
|
$date_values = array(
|
202
|
1 => array(
|
203
|
'created' => '09/03/2009 - 00:12',
|
204
|
'end' => '11/03/2012 - 09:58',
|
205
|
),
|
206
|
2 => array(
|
207
|
'created' => '09/02/2009 - 22:59',
|
208
|
'end' => '11/03/2012 - 08:46',
|
209
|
),
|
210
|
);
|
211
|
for ($i = 1; $i <= 2; $i++) {
|
212
|
$this->drupalGet("node/$i/edit");
|
213
|
$this->assertNodeFieldValue('date', $date_values[$i]['created']);
|
214
|
$this->assertFieldByName('field_date[und][0][value2][date]', $date_values[$i]['end']);
|
215
|
$this->assertNodeFieldValue('datestamp', $date_values[$i]['created']);
|
216
|
$this->assertFieldByName('field_datestamp[und][0][value2][date]', $date_values[$i]['end']);
|
217
|
$this->assertNodeFieldValue('datetime', $date_values[$i]['created']);
|
218
|
$this->assertFieldByName('field_datetime[und][0][value2][date]', $date_values[$i]['end']);
|
219
|
}
|
220
|
|
221
|
// Import CSV file with empty values.
|
222
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
|
223
|
$this->assertText('Updated 2 nodes');
|
224
|
|
225
|
// Check if all values were cleared out for both nodes.
|
226
|
for ($i = 1; $i <= 2; $i++) {
|
227
|
$this->drupalGet("node/$i/edit");
|
228
|
$this->assertNoNodeFieldValue('date', $date_values[$i]['created']);
|
229
|
$this->assertNoFieldByName('field_date[und][0][value2][date]', $date_values[$i]['end']);
|
230
|
$this->assertNoNodeFieldValue('datestamp', $date_values[$i]['created']);
|
231
|
$this->assertNoFieldByName('field_datestamp[und][0][value2][date]', $date_values[$i]['end']);
|
232
|
$this->assertNoNodeFieldValue('datetime', $date_values[$i]['created']);
|
233
|
$this->assertNoFieldByName('field_datetime[und][0][value2][date]', $date_values[$i]['end']);
|
234
|
$this->drupalGet("node/$i");
|
235
|
$this->assertNoText('date_label');
|
236
|
$this->assertNoText('datestamp_label');
|
237
|
$this->assertNoText('datetime_label');
|
238
|
}
|
239
|
|
240
|
// Re-import the first file again and check if the values returned.
|
241
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_date.csv');
|
242
|
$this->assertText('Updated 2 nodes');
|
243
|
for ($i = 1; $i <= 2; $i++) {
|
244
|
$this->drupalGet("node/$i/edit");
|
245
|
$this->assertNodeFieldValue('date', $date_values[$i]['created']);
|
246
|
$this->assertFieldByName('field_date[und][0][value2][date]', $date_values[$i]['end']);
|
247
|
$this->assertNodeFieldValue('datestamp', $date_values[$i]['created']);
|
248
|
$this->assertFieldByName('field_datestamp[und][0][value2][date]', $date_values[$i]['end']);
|
249
|
$this->assertNodeFieldValue('datetime', $date_values[$i]['created']);
|
250
|
$this->assertFieldByName('field_datetime[und][0][value2][date]', $date_values[$i]['end']);
|
251
|
}
|
252
|
|
253
|
// Import CSV file with non-existent values.
|
254
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
|
255
|
$this->assertText('Updated 2 nodes');
|
256
|
|
257
|
// Check if all values were cleared out for node 1.
|
258
|
$this->drupalGet('node/1/edit');
|
259
|
$this->assertNoNodeFieldValue('date', $date_values[1]['created']);
|
260
|
$this->assertNoFieldByName('field_date[und][0][value2][date]', $date_values[1]['end']);
|
261
|
$this->assertNoNodeFieldValue('datestamp', $date_values[1]['created']);
|
262
|
$this->assertNoFieldByName('field_datestamp[und][0][value2][date]', $date_values[1]['end']);
|
263
|
$this->assertNoNodeFieldValue('datetime', $date_values[1]['created']);
|
264
|
$this->assertNoFieldByName('field_datetime[und][0][value2][date]', $date_values[1]['end']);
|
265
|
// Check if labels for fields that should be cleared out are not shown.
|
266
|
$this->drupalGet('node/1');
|
267
|
$this->assertNoText('date_label');
|
268
|
$this->assertNoText('datestamp_label');
|
269
|
$this->assertNoText('datetime_label');
|
270
|
}
|
271
|
|
272
|
}
|