Newer
Older
Alex Barth
committed
<?php
* Contains FeedsMapperLinkTestCase.
Alex Barth
committed
/**
* Test case for CCK link mapper mappers/date.inc.
Alex Barth
committed
*/
class FeedsMapperLinkTestCase extends FeedsMapperTestCase {
/**
* Title for link fields with a static title.
*
* @var string
*/
private $staticTitle;
/**
* Name of created content type.
*
* @var string
*/
private $contentType;
Alex Barth
committed
public static function getInfo() {
return array(
Dave Reid
committed
'name' => 'Mapper: Link',
'description' => 'Test Feeds Mapper support for Link fields.',
'group' => 'Feeds',
'dependencies' => array('link'),
Alex Barth
committed
);
}
public function setUp() {
parent::setUp(array('link'));
Alex Barth
committed
$this->staticTitle = $this->randomName();
Alex Barth
committed
// Create content type.
$this->contentType = $this->createContentType(array(), array(
Alex Barth
committed
'alpha' => array(
'instance_settings' => array(
'instance[settings][title]' => 'required',
Alex Barth
committed
),
),
'beta' => array(
'instance_settings' => array(
'instance[settings][title]' => 'none',
Alex Barth
committed
),
),
'gamma' => array(
'instance_settings' => array(
'instance[settings][title]' => 'optional',
Alex Barth
committed
),
),
'omega' => array(
'instance_settings' => array(
'instance[settings][title]' => 'value',
'instance[settings][title_value]' => $this->staticTitle,
Alex Barth
committed
),
),
));
Alex Barth
committed
/**
* Basic test loading a single entry CSV file.
*/
public function test() {
// Create importer configuration.
$this->createImporterConfiguration(); //Create a default importer configuration
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $this->contentType)); //Processor settings
Alex Barth
committed
$this->addMappings('syndication', array(
niklas
committed
0 => array(
Alex Barth
committed
'source' => 'title',
'target' => 'title'
),
niklas
committed
1 => array(
Alex Barth
committed
'source' => 'timestamp',
'target' => 'created'
),
niklas
committed
2 => array(
Alex Barth
committed
'source' => 'description',
'target' => 'body'
),
niklas
committed
3 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_alpha:url'
),
niklas
committed
4 => array(
Alex Barth
committed
'source' => 'title',
'target' => 'field_alpha:title'
),
niklas
committed
5 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_beta:url'
),
niklas
committed
6 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_gamma:url'
),
niklas
committed
7 => array(
Alex Barth
committed
'source' => 'title',
'target' => 'field_gamma:title'
),
niklas
committed
8 => array(
Alex Barth
committed
'source' => 'url',
'target' => 'field_omega:url'
),
));
// Import RSS file.
$nid = $this->createFeedNode();
// Assert 10 items aggregated after creation of the node.
$this->assertText('Created 10 nodes');
Alex Barth
committed
// Edit the imported node.
$this->drupalGet('node/2/edit');
$url = 'http://developmentseed.org/blog/2009/oct/06/open-atrium-translation-workflow-two-way-updating';
$title = 'Open Atrium Translation Workflow: Two Way Translation Updates';
$this->assertNodeFieldValue('alpha', array('url' => $url, 'static' => $title));
$this->assertNodeFieldValue('beta', array('url' => $url));
$this->assertNodeFieldValue('gamma', array('url' => $url, 'static' => $title));
$this->assertNodeFieldValue('omega', array('url' => $url, 'static' => $this->staticTitle));
Alex Barth
committed
// Test the static title.
$this->drupalGet('node/2');
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
$this->assertText($this->staticTitle, 'Static title link found.');
}
/**
* Tests if values are cleared out when an empty value or no value
* is provided.
*/
public function testClearOutValues() {
// Create and configure importer.
$this->createImporterConfiguration('Content CSV', 'csv');
$this->setSettings('csv', NULL, array(
'content_type' => '',
'import_period' => FEEDS_SCHEDULE_NEVER,
));
$this->setPlugin('csv', 'FeedsFileFetcher');
$this->setPlugin('csv', 'FeedsCSVParser');
$this->setSettings('csv', 'FeedsNodeProcessor', array(
'bundle' => $this->contentType,
'update_existing' => 1,
));
$this->addMappings('csv', array(
0 => array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
1 => array(
'source' => 'title',
'target' => 'title'
),
2 => array(
'source' => 'url',
'target' => 'field_alpha:url'
),
3 => array(
'source' => 'link_title',
'target' => 'field_alpha:title'
),
4 => array(
'source' => 'url',
'target' => 'field_beta:url'
),
5 => array(
'source' => 'link_title',
'target' => 'field_beta:title'
),
6 => array(
'source' => 'url',
'target' => 'field_gamma:url'
),
7 => array(
'source' => 'link_title',
'target' => 'field_gamma:title'
),
8 => array(
'source' => 'url',
'target' => 'field_omega:url'
),
9 => array(
'source' => 'link_title',
'target' => 'field_omega:title'
),
));
// Import CSV file.
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_link.csv');
$this->assertText('Created 2 nodes');
// Check the imported nodes.
$link_values = array(
1 => array(
'title' => 'Feeds',
'url' => 'https://www.drupal.org/project/feeds',
),
2 => array(
'title' => 'Framework for expected behavior when importing empty/blank values',
'url' => 'https://www.drupal.org/node/1107522',
),
);
for ($i = 1; $i <= 2; $i++) {
$this->drupalGet("node/$i/edit");
$this->assertNodeFieldValue('alpha', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this->assertNodeFieldValue('beta', array(
'url' => $link_values[$i]['url'],
));
$this->assertNodeFieldValue('gamma', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this->assertNodeFieldValue('omega', array(
'url' => $link_values[$i]['url'],
));
// Test static title.
$this->drupalGet("node/$i");
$this->assertText($this->staticTitle, 'Static title link found.');
}
// Import CSV file with empty values.
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
$this->assertText('Updated 2 nodes');
// Check if all values were cleared out for both nodes.
for ($i = 1; $i <= 2; $i++) {
$this->drupalGet("node/$i/edit");
$this->assertNoNodeFieldValue('alpha', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this->assertNoNodeFieldValue('beta', array(
'url' => $link_values[$i]['url'],
));
$this->assertNoNodeFieldValue('gamma', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this->assertNoNodeFieldValue('omega', array(
'url' => $link_values[$i]['url'],
));
// Check labels.
$this->drupalGet('node/' . $i);
$this->assertNoText('alpha_link_field_label');
$this->assertNoText('beta_link_field_label');
$this->assertNoText('gamma_link_field_label');
$this->assertNoText('omega_link_field_label');
// Assert that the static title is no longer shown.
$this->assertNoText($this->staticTitle, 'Static title link not found.');
}
// Re-import the first file again and check if the values returned.
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_link.csv');
$this->assertText('Updated 2 nodes');
for ($i = 1; $i <= 2; $i++) {
$this->drupalGet("node/$i/edit");
$this->assertNodeFieldValue('alpha', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this->assertNodeFieldValue('beta', array(
'url' => $link_values[$i]['url'],
));
$this->assertNodeFieldValue('gamma', array(
'url' => $link_values[$i]['url'],
'title' => $link_values[$i]['title'],
));
$this->assertNodeFieldValue('omega', array(
'url' => $link_values[$i]['url'],
));
}
// Import CSV file with non-existent values.
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
$this->assertText('Updated 2 nodes');
// Check if all values were cleared out for node 1.
$this->drupalGet("node/1/edit");
$this->assertNoNodeFieldValue('alpha', array(
'url' => $link_values[1]['url'],
'title' => $link_values[1]['title'],
));
$this->assertNoNodeFieldValue('beta', array(
'url' => $link_values[1]['url'],
));
$this->assertNoNodeFieldValue('gamma', array(
'url' => $link_values[1]['url'],
'title' => $link_values[1]['title'],
));
$this->assertNoNodeFieldValue('omega', array(
'url' => $link_values[1]['url'],
));
$this->drupalGet('node/1');
$this->assertNoText('alpha_link_field_label');
$this->assertNoText('beta_link_field_label');
$this->assertNoText('gamma_link_field_label');
$this->assertNoText('omega_link_field_label');
Alex Barth
committed
// Assert that the static title is no longer shown.
$this->assertNoText($this->staticTitle, 'Static title link not found.');
Alex Barth
committed
}
/**
* Override parent::getFormFieldsNames().
*/
protected function getFormFieldsNames($field_name, $index) {
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
$fields = array("field_{$field_name}[und][{$index}][url]");
Alex Barth
committed
if (in_array($field_name, array('alpha', 'gamma'))) {
$fields[] = "field_{$field_name}[und][{$index}][title]";
Alex Barth
committed
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
}
return $fields;
}
else {
return parent::getFormFieldsNames($field_name, $index);
}
}
/**
* Override parent::getFormFieldsValues().
*/
protected function getFormFieldsValues($field_name, $value) {
if (in_array($field_name, array('alpha', 'beta', 'gamma', 'omega'))) {
if (!is_array($value)) {
$value = array('url' => $value);
}
$values = array($value['url']);
if (in_array($field_name, array('alpha', 'gamma'))) {
$values[] = isset($value['title']) ? $value['title'] : '';
}
return $values;
}
else {
return parent::getFormFieldsValues($field_name, $index);
}
}