1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Contains FeedsMapperLinkTestCase.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test case for CCK link mapper mappers/date.inc.
|
10
|
*/
|
11
|
class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
|
12
|
|
13
|
/**
|
14
|
* Title for link fields with a static title.
|
15
|
*
|
16
|
* @var string
|
17
|
*/
|
18
|
private $staticTitle;
|
19
|
|
20
|
/**
|
21
|
* Name of created content type.
|
22
|
*
|
23
|
* @var string
|
24
|
*/
|
25
|
private $contentType;
|
26
|
|
27
|
/**
|
28
|
* {@inheritdoc}
|
29
|
*/
|
30
|
public static function getInfo() {
|
31
|
return array(
|
32
|
'name' => 'Mapper: Link',
|
33
|
'description' => 'Test Feeds Mapper support for Link fields.',
|
34
|
'group' => 'Feeds',
|
35
|
'dependencies' => array('link'),
|
36
|
);
|
37
|
}
|
38
|
|
39
|
/**
|
40
|
* {@inheritdoc}
|
41
|
*/
|
42
|
public function setUp() {
|
43
|
parent::setUp(array('link'));
|
44
|
|
45
|
$this->staticTitle = $this->randomName();
|
46
|
|
47
|
// Create content type.
|
48
|
$this->contentType = $this->createContentType(array(), array(
|
49
|
'alpha' => array(
|
50
|
'type' => 'link_field',
|
51
|
'instance_settings' => array(
|
52
|
'instance[settings][title]' => 'required',
|
53
|
),
|
54
|
),
|
55
|
'beta' => array(
|
56
|
'type' => 'link_field',
|
57
|
'instance_settings' => array(
|
58
|
'instance[settings][title]' => 'none',
|
59
|
),
|
60
|
),
|
61
|
'gamma' => array(
|
62
|
'type' => 'link_field',
|
63
|
'instance_settings' => array(
|
64
|
'instance[settings][title]' => 'optional',
|
65
|
),
|
66
|
),
|
67
|
'omega' => array(
|
68
|
'type' => 'link_field',
|
69
|
'instance_settings' => array(
|
70
|
'instance[settings][title]' => 'value',
|
71
|
'instance[settings][title_value]' => $this->staticTitle,
|
72
|
),
|
73
|
),
|
74
|
));
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* Basic test loading a single entry CSV file.
|
79
|
*/
|
80
|
public function test() {
|
81
|
// Create importer configuration.
|
82
|
// Create a default importer configuration.
|
83
|
$this->createImporterConfiguration();
|
84
|
// Processor settings.
|
85
|
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $this->contentType));
|
86
|
$this->addMappings('syndication', array(
|
87
|
0 => array(
|
88
|
'source' => 'title',
|
89
|
'target' => 'title',
|
90
|
),
|
91
|
1 => array(
|
92
|
'source' => 'timestamp',
|
93
|
'target' => 'created',
|
94
|
),
|
95
|
2 => array(
|
96
|
'source' => 'description',
|
97
|
'target' => 'body',
|
98
|
),
|
99
|
3 => array(
|
100
|
'source' => 'url',
|
101
|
'target' => 'field_alpha:url',
|
102
|
),
|
103
|
4 => array(
|
104
|
'source' => 'title',
|
105
|
'target' => 'field_alpha:title',
|
106
|
),
|
107
|
5 => array(
|
108
|
'source' => 'url',
|
109
|
'target' => 'field_beta:url',
|
110
|
),
|
111
|
6 => array(
|
112
|
'source' => 'url',
|
113
|
'target' => 'field_gamma:url',
|
114
|
),
|
115
|
7 => array(
|
116
|
'source' => 'title',
|
117
|
'target' => 'field_gamma:title',
|
118
|
),
|
119
|
8 => array(
|
120
|
'source' => 'url',
|
121
|
'target' => 'field_omega:url',
|
122
|
),
|
123
|
));
|
124
|
|
125
|
// Import RSS file.
|
126
|
$nid = $this->createFeedNode();
|
127
|
// Assert 10 items aggregated after creation of the node.
|
128
|
$this->assertText('Created 10 nodes');
|
129
|
|
130
|
// Edit the imported node.
|
131
|
$this->drupalGet('node/2/edit');
|
132
|
|
133
|
$url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating';
|
134
|
$title = 'Open Atrium Translation Workflow: Two Way Translation Updates';
|
135
|
$this->assertNodeFieldValue('alpha', array('url' => $url, 'static' => $title));
|
136
|
$this->assertNodeFieldValue('beta', array('url' => $url));
|
137
|
$this->assertNodeFieldValue('gamma', array('url' => $url, 'static' => $title));
|
138
|
$this->assertNodeFieldValue('omega', array('url' => $url, 'static' => $this->staticTitle));
|
139
|
|
140
|
// Test the static title.
|
141
|
$this->drupalGet('node/2');
|
142
|
$this->assertText($this->staticTitle, 'Static title link found.');
|
143
|
}
|
144
|
|
145
|
/**
|
146
|
* Tests if values are cleared out when an empty value or no value
|
147
|
* is provided.
|
148
|
*/
|
149
|
public function testClearOutValues() {
|
150
|
// Create and configure importer.
|
151
|
$this->createImporterConfiguration('Content CSV', 'csv');
|
152
|
$this->setSettings('csv', NULL, array(
|
153
|
'content_type' => '',
|
154
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
155
|
));
|
156
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
157
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
158
|
$this->setSettings('csv', 'FeedsNodeProcessor', array(
|
159
|
'bundle' => $this->contentType,
|
160
|
'update_existing' => 1,
|
161
|
));
|
162
|
$this->addMappings('csv', array(
|
163
|
0 => array(
|
164
|
'source' => 'guid',
|
165
|
'target' => 'guid',
|
166
|
'unique' => TRUE,
|
167
|
),
|
168
|
1 => array(
|
169
|
'source' => 'title',
|
170
|
'target' => 'title',
|
171
|
),
|
172
|
2 => array(
|
173
|
'source' => 'url',
|
174
|
'target' => 'field_alpha:url',
|
175
|
),
|
176
|
3 => array(
|
177
|
'source' => 'link_title',
|
178
|
'target' => 'field_alpha:title',
|
179
|
),
|
180
|
4 => array(
|
181
|
'source' => 'url',
|
182
|
'target' => 'field_beta:url',
|
183
|
),
|
184
|
5 => array(
|
185
|
'source' => 'link_title',
|
186
|
'target' => 'field_beta:title',
|
187
|
),
|
188
|
6 => array(
|
189
|
'source' => 'url',
|
190
|
'target' => 'field_gamma:url',
|
191
|
),
|
192
|
7 => array(
|
193
|
'source' => 'link_title',
|
194
|
'target' => 'field_gamma:title',
|
195
|
),
|
196
|
8 => array(
|
197
|
'source' => 'url',
|
198
|
'target' => 'field_omega:url',
|
199
|
),
|
200
|
9 => array(
|
201
|
'source' => 'link_title',
|
202
|
'target' => 'field_omega:title',
|
203
|
),
|
204
|
));
|
205
|
|
206
|
// Import CSV file.
|
207
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_link.csv');
|
208
|
$this->assertText('Created 2 nodes');
|
209
|
|
210
|
// Check the imported nodes.
|
211
|
$link_values = array(
|
212
|
1 => array(
|
213
|
'title' => 'Feeds',
|
214
|
'url' => 'https://www.drupal.org/project/feeds',
|
215
|
),
|
216
|
2 => array(
|
217
|
'title' => 'Framework for expected behavior when importing empty/blank values',
|
218
|
'url' => 'https://www.drupal.org/node/1107522',
|
219
|
),
|
220
|
);
|
221
|
|
222
|
for ($i = 1; $i <= 2; $i++) {
|
223
|
$this->drupalGet("node/$i/edit");
|
224
|
$this->assertNodeFieldValue('alpha', array(
|
225
|
'url' => $link_values[$i]['url'],
|
226
|
'title' => $link_values[$i]['title'],
|
227
|
));
|
228
|
$this->assertNodeFieldValue('beta', array(
|
229
|
'url' => $link_values[$i]['url'],
|
230
|
));
|
231
|
$this->assertNodeFieldValue('gamma', array(
|
232
|
'url' => $link_values[$i]['url'],
|
233
|
'title' => $link_values[$i]['title'],
|
234
|
));
|
235
|
$this->assertNodeFieldValue('omega', array(
|
236
|
'url' => $link_values[$i]['url'],
|
237
|
));
|
238
|
|
239
|
// Test static title.
|
240
|
$this->drupalGet("node/$i");
|
241
|
$this->assertText($this->staticTitle, 'Static title link found.');
|
242
|
}
|
243
|
|
244
|
// Import CSV file with empty values.
|
245
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
|
246
|
$this->assertText('Updated 2 nodes');
|
247
|
|
248
|
// Check if all values were cleared out for both nodes.
|
249
|
for ($i = 1; $i <= 2; $i++) {
|
250
|
$this->drupalGet("node/$i/edit");
|
251
|
$this->assertNoNodeFieldValue('alpha', array(
|
252
|
'url' => $link_values[$i]['url'],
|
253
|
'title' => $link_values[$i]['title'],
|
254
|
));
|
255
|
$this->assertNoNodeFieldValue('beta', array(
|
256
|
'url' => $link_values[$i]['url'],
|
257
|
));
|
258
|
$this->assertNoNodeFieldValue('gamma', array(
|
259
|
'url' => $link_values[$i]['url'],
|
260
|
'title' => $link_values[$i]['title'],
|
261
|
));
|
262
|
$this->assertNoNodeFieldValue('omega', array(
|
263
|
'url' => $link_values[$i]['url'],
|
264
|
));
|
265
|
// Check labels.
|
266
|
$this->drupalGet('node/' . $i);
|
267
|
$this->assertNoText('alpha_link_field_label');
|
268
|
$this->assertNoText('beta_link_field_label');
|
269
|
$this->assertNoText('gamma_link_field_label');
|
270
|
$this->assertNoText('omega_link_field_label');
|
271
|
|
272
|
// Assert that the static title is no longer shown.
|
273
|
$this->assertNoText($this->staticTitle, 'Static title link not found.');
|
274
|
}
|
275
|
|
276
|
// Re-import the first file again and check if the values returned.
|
277
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_link.csv');
|
278
|
$this->assertText('Updated 2 nodes');
|
279
|
for ($i = 1; $i <= 2; $i++) {
|
280
|
$this->drupalGet("node/$i/edit");
|
281
|
$this->assertNodeFieldValue('alpha', array(
|
282
|
'url' => $link_values[$i]['url'],
|
283
|
'title' => $link_values[$i]['title'],
|
284
|
));
|
285
|
$this->assertNodeFieldValue('beta', array(
|
286
|
'url' => $link_values[$i]['url'],
|
287
|
));
|
288
|
$this->assertNodeFieldValue('gamma', array(
|
289
|
'url' => $link_values[$i]['url'],
|
290
|
'title' => $link_values[$i]['title'],
|
291
|
));
|
292
|
$this->assertNodeFieldValue('omega', array(
|
293
|
'url' => $link_values[$i]['url'],
|
294
|
));
|
295
|
}
|
296
|
|
297
|
// Import CSV file with non-existent values.
|
298
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
|
299
|
$this->assertText('Updated 2 nodes');
|
300
|
|
301
|
// Check if all values were cleared out for node 1.
|
302
|
$this->drupalGet("node/1/edit");
|
303
|
$this->assertNoNodeFieldValue('alpha', array(
|
304
|
'url' => $link_values[1]['url'],
|
305
|
'title' => $link_values[1]['title'],
|
306
|
));
|
307
|
$this->assertNoNodeFieldValue('beta', array(
|
308
|
'url' => $link_values[1]['url'],
|
309
|
));
|
310
|
$this->assertNoNodeFieldValue('gamma', array(
|
311
|
'url' => $link_values[1]['url'],
|
312
|
'title' => $link_values[1]['title'],
|
313
|
));
|
314
|
$this->assertNoNodeFieldValue('omega', array(
|
315
|
'url' => $link_values[1]['url'],
|
316
|
));
|
317
|
$this->drupalGet('node/1');
|
318
|
$this->assertNoText('alpha_link_field_label');
|
319
|
$this->assertNoText('beta_link_field_label');
|
320
|
$this->assertNoText('gamma_link_field_label');
|
321
|
$this->assertNoText('omega_link_field_label');
|
322
|
|
323
|
// Assert that the static title is no longer shown.
|
324
|
$this->assertNoText($this->staticTitle, 'Static title link not found.');
|
325
|
}
|
326
|
|
327
|
/**
|
328
|
* Tests link field validation.
|
329
|
*/
|
330
|
public function testLinkFieldValidation() {
|
331
|
// Create and configure importer.
|
332
|
$this->createImporterConfiguration('CSV', 'csv');
|
333
|
$this->setSettings('csv', NULL, array(
|
334
|
'content_type' => '',
|
335
|
'import_period' => FEEDS_SCHEDULE_NEVER,
|
336
|
));
|
337
|
$this->setPlugin('csv', 'FeedsFileFetcher');
|
338
|
$this->setPlugin('csv', 'FeedsCSVParser');
|
339
|
$this->setSettings('csv', 'FeedsNodeProcessor', array(
|
340
|
'bundle' => $this->contentType,
|
341
|
));
|
342
|
$this->addMappings('csv', array(
|
343
|
0 => array(
|
344
|
'source' => 'title',
|
345
|
'target' => 'title',
|
346
|
),
|
347
|
1 => array(
|
348
|
'source' => 'alpha',
|
349
|
'target' => 'field_alpha:title',
|
350
|
),
|
351
|
2 => array(
|
352
|
'source' => 'alpha',
|
353
|
'target' => 'field_alpha:url',
|
354
|
),
|
355
|
));
|
356
|
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
|
357
|
$this->assertText('Failed importing 1 node.');
|
358
|
$this->assertText("Field validation errors in item 'Ut wisi enim ad minim veniam'");
|
359
|
$this->assertText('The value Ut wisi provided for alpha_link_field_label is not a valid URL.');
|
360
|
}
|
361
|
|
362
|
/**
|
363
|
* Override parent::getFormFieldsNames().
|
364
|
*/
|
365
|
protected function getFormFieldsNames($field_name, $index) {
|
366
|
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
|
367
|
$fields = array("field_{$field_name}[und][{$index}][url]");
|
368
|
if (in_array($field_name, array('alpha', 'gamma'))) {
|
369
|
$fields[] = "field_{$field_name}[und][{$index}][title]";
|
370
|
}
|
371
|
return $fields;
|
372
|
}
|
373
|
else {
|
374
|
return parent::getFormFieldsNames($field_name, $index);
|
375
|
}
|
376
|
}
|
377
|
|
378
|
/**
|
379
|
* Override parent::getFormFieldsValues().
|
380
|
*/
|
381
|
protected function getFormFieldsValues($field_name, $value) {
|
382
|
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
|
383
|
if (!is_array($value)) {
|
384
|
$value = array('url' => $value);
|
385
|
}
|
386
|
$values = array($value['url']);
|
387
|
if (in_array($field_name, array('alpha', 'gamma'))) {
|
388
|
$values[] = isset($value['title']) ? $value['title'] : '';
|
389
|
}
|
390
|
return $values;
|
391
|
}
|
392
|
else {
|
393
|
return parent::getFormFieldsValues($field_name, $index);
|
394
|
}
|
395
|
}
|
396
|
|
397
|
}
|