Révision ec2b0e7b
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/feeds/tests/feeds_mapper_field.test | ||
---|---|---|
230 | 230 |
$this->assertNoText('delta_number_float_label'); |
231 | 231 |
} |
232 | 232 |
|
233 |
/** |
|
234 |
* Tests text field validation. |
|
235 |
*/ |
|
236 |
public function testTextFieldValidation() { |
|
237 |
// Create a field with settings to validate. |
|
238 |
$max_length = 5; |
|
239 |
$typename = $this->createContentType(array(), array( |
|
240 |
'alpha' => array( |
|
241 |
'type' => 'text', |
|
242 |
'settings' => array( |
|
243 |
'field[settings][max_length]' => $max_length, |
|
244 |
), |
|
245 |
), |
|
246 |
)); |
|
247 |
|
|
248 |
// Create and configure importer. |
|
249 |
$this->createImporterConfiguration('Content CSV', 'csv'); |
|
250 |
$this->setSettings('csv', NULL, array( |
|
251 |
'content_type' => '', |
|
252 |
'import_period' => FEEDS_SCHEDULE_NEVER, |
|
253 |
)); |
|
254 |
$this->setPlugin('csv', 'FeedsFileFetcher'); |
|
255 |
$this->setPlugin('csv', 'FeedsCSVParser'); |
|
256 |
$this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $typename)); |
|
257 |
$this->addMappings('csv', array( |
|
258 |
0 => array( |
|
259 |
'source' => 'title', |
|
260 |
'target' => 'title', |
|
261 |
), |
|
262 |
1 => array( |
|
263 |
'source' => 'alpha', |
|
264 |
'target' => 'field_alpha', |
|
265 |
), |
|
266 |
)); |
|
267 |
|
|
268 |
// Import CSV file. |
|
269 |
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv'); |
|
270 |
$this->assertText('Created 1 node'); |
|
271 |
$this->assertText('Failed importing 1 node.'); |
|
272 |
$this->assertText("Field validation errors in item 'Ut wisi enim ad minim veniam'"); |
|
273 |
$this->assertText('alpha_text_label: the text may not be longer than 5 characters.'); |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Tests text field validation for nodes without a title. |
|
278 |
* |
|
279 |
* The error message should refer the GUID of an item if the entity has no |
|
280 |
* label. |
|
281 |
*/ |
|
282 |
public function testTextFieldValidationWithoutNodeTitle() { |
|
283 |
// Create a field with settings to validate. |
|
284 |
$max_length = 5; |
|
285 |
$typename = $this->createContentType(array(), array( |
|
286 |
'alpha' => array( |
|
287 |
'type' => 'text', |
|
288 |
'settings' => array( |
|
289 |
'field[settings][max_length]' => $max_length, |
|
290 |
), |
|
291 |
), |
|
292 |
)); |
|
293 |
|
|
294 |
// Create and configure importer. |
|
295 |
$this->createImporterConfiguration('Content CSV', 'csv'); |
|
296 |
$this->setSettings('csv', NULL, array( |
|
297 |
'content_type' => '', |
|
298 |
'import_period' => FEEDS_SCHEDULE_NEVER, |
|
299 |
)); |
|
300 |
$this->setPlugin('csv', 'FeedsFileFetcher'); |
|
301 |
$this->setPlugin('csv', 'FeedsCSVParser'); |
|
302 |
$this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $typename)); |
|
303 |
$this->addMappings('csv', array( |
|
304 |
0 => array( |
|
305 |
'source' => 'guid', |
|
306 |
'target' => 'guid', |
|
307 |
), |
|
308 |
1 => array( |
|
309 |
'source' => 'alpha', |
|
310 |
'target' => 'field_alpha', |
|
311 |
), |
|
312 |
)); |
|
313 |
|
|
314 |
// Import CSV file. |
|
315 |
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv'); |
|
316 |
$this->assertText('Created 1 node'); |
|
317 |
$this->assertText('Failed importing 1 node.'); |
|
318 |
$this->assertText("Field validation errors in item '2'"); |
|
319 |
$this->assertText('alpha_text_label: the text may not be longer than 5 characters.'); |
|
320 |
} |
|
321 |
|
|
322 |
/** |
|
323 |
* Tests text field validation for taxonomy terms. |
|
324 |
*/ |
|
325 |
public function testTextFieldValidationForTaxonomyTerms() { |
|
326 |
// Create vocabulary. |
|
327 |
$edit = array( |
|
328 |
'name' => 'Addams vocabulary', |
|
329 |
'machine_name' => 'addams', |
|
330 |
); |
|
331 |
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); |
|
332 |
|
|
333 |
// Create a field with settings to validate. |
|
334 |
field_create_field(array( |
|
335 |
'field_name' => 'field_alpha', |
|
336 |
'type' => 'text', |
|
337 |
'settings' => array( |
|
338 |
'max_length' => 5, |
|
339 |
), |
|
340 |
)); |
|
341 |
field_create_instance(array( |
|
342 |
'field_name' => 'field_alpha', |
|
343 |
'entity_type' => 'taxonomy_term', |
|
344 |
'label' => 'alpha_text_label', |
|
345 |
'bundle' => 'addams', |
|
346 |
'widget' => array( |
|
347 |
'type' => 'textfield', |
|
348 |
), |
|
349 |
)); |
|
350 |
|
|
351 |
// Create and configure importer. |
|
352 |
$this->createImporterConfiguration('Content CSV', 'csv'); |
|
353 |
$this->setSettings('csv', NULL, array( |
|
354 |
'content_type' => '', |
|
355 |
'import_period' => FEEDS_SCHEDULE_NEVER, |
|
356 |
)); |
|
357 |
$this->setPlugin('csv', 'FeedsFileFetcher'); |
|
358 |
$this->setPlugin('csv', 'FeedsCSVParser'); |
|
359 |
$this->setPlugin('csv', 'FeedsTermProcessor'); |
|
360 |
$this->setSettings('csv', 'FeedsTermProcessor', array('bundle' => 'addams')); |
|
361 |
$this->addMappings('csv', array( |
|
362 |
0 => array( |
|
363 |
'source' => 'title', |
|
364 |
'target' => 'name', |
|
365 |
), |
|
366 |
1 => array( |
|
367 |
'source' => 'alpha', |
|
368 |
'target' => 'field_alpha', |
|
369 |
), |
|
370 |
)); |
|
371 |
|
|
372 |
// Import CSV file. |
|
373 |
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv'); |
|
374 |
$this->assertText('Created 1 taxonomy term.'); |
|
375 |
$this->assertText('Failed importing 1 taxonomy term.'); |
|
376 |
$this->assertText("Field validation errors in item 'Ut wisi enim ad minim veniam'"); |
|
377 |
$this->assertText('alpha_text_label: the text may not be longer than 5 characters.'); |
|
378 |
} |
|
379 |
|
|
380 |
/** |
|
381 |
* Tests text field validation for users. |
|
382 |
*/ |
|
383 |
public function testTextFieldValidationForUsers() { |
|
384 |
// Create a field with settings to validate. |
|
385 |
field_create_field(array( |
|
386 |
'field_name' => 'field_alpha', |
|
387 |
'type' => 'text', |
|
388 |
'settings' => array( |
|
389 |
'max_length' => 5, |
|
390 |
), |
|
391 |
)); |
|
392 |
field_create_instance(array( |
|
393 |
'field_name' => 'field_alpha', |
|
394 |
'entity_type' => 'user', |
|
395 |
'label' => 'alpha_text_label', |
|
396 |
'bundle' => 'user', |
|
397 |
'widget' => array( |
|
398 |
'type' => 'textfield', |
|
399 |
), |
|
400 |
)); |
|
401 |
|
|
402 |
// Create and configure importer. |
|
403 |
$this->createImporterConfiguration('Content CSV', 'csv'); |
|
404 |
$this->setSettings('csv', NULL, array( |
|
405 |
'content_type' => '', |
|
406 |
'import_period' => FEEDS_SCHEDULE_NEVER, |
|
407 |
)); |
|
408 |
$this->setPlugin('csv', 'FeedsFileFetcher'); |
|
409 |
$this->setPlugin('csv', 'FeedsCSVParser'); |
|
410 |
$this->setPlugin('csv', 'FeedsUserProcessor'); |
|
411 |
$this->addMappings('csv', array( |
|
412 |
0 => array( |
|
413 |
'source' => 'title', |
|
414 |
'target' => 'name', |
|
415 |
), |
|
416 |
1 => array( |
|
417 |
'source' => 'alpha', |
|
418 |
'target' => 'field_alpha', |
|
419 |
), |
|
420 |
)); |
|
421 |
|
|
422 |
// Import CSV file. Users should fail to import because mail address is |
|
423 |
// missing. |
|
424 |
$this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv'); |
|
425 |
$this->assertText('Failed importing 2 users.'); |
|
426 |
$this->assertText('User name missing or email not valid.'); |
|
427 |
$this->assertText("Field validation errors in item 'Ut wisi enim ad minim veniam'"); |
|
428 |
$this->assertText('alpha_text_label: the text may not be longer than 5 characters.'); |
|
429 |
} |
|
430 |
|
|
431 |
/** |
|
432 |
* Tests cardinality validation. |
|
433 |
*/ |
|
434 |
public function testCardinalityValidation() { |
|
435 |
// Create a field with settings to validate. |
|
436 |
$cardinality = 6; |
|
437 |
$typename = $this->createContentType(array(), array( |
|
438 |
'alpha' => array( |
|
439 |
'type' => 'text', |
|
440 |
'instance_settings' => array( |
|
441 |
'field[cardinality]' => $cardinality, |
|
442 |
), |
|
443 |
), |
|
444 |
)); |
|
445 |
|
|
446 |
// Create and configure importer. |
|
447 |
$this->createImporterConfiguration('Syndication', 'syndication'); |
|
448 |
$this->setSettings('syndication', NULL, array( |
|
449 |
'content_type' => '', |
|
450 |
'import_period' => FEEDS_SCHEDULE_NEVER, |
|
451 |
)); |
|
452 |
$this->setPlugin('syndication', 'FeedsHTTPFetcher'); |
|
453 |
$this->setPlugin('syndication', 'FeedsSyndicationParser'); |
|
454 |
$this->setSettings('syndication', 'FeedsNodeProcessor', array('bundle' => $typename)); |
|
455 |
$this->addMappings('syndication', array( |
|
456 |
0 => array( |
|
457 |
'source' => 'title', |
|
458 |
'target' => 'title', |
|
459 |
), |
|
460 |
1 => array( |
|
461 |
'source' => 'tags', |
|
462 |
'target' => 'field_alpha', |
|
463 |
), |
|
464 |
)); |
|
465 |
|
|
466 |
// Import RSS. |
|
467 |
// Three items of the RSS contain more than 6 categories. Because categories |
|
468 |
// are mapped to field_alpha and field_alpha may only hold 6 values, they |
|
469 |
// should fail to import. |
|
470 |
$edit = array( |
|
471 |
'feeds[FeedsHTTPFetcher][source]' => $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed.rss2', |
|
472 |
); |
|
473 |
$this->drupalPost('import/syndication', $edit, 'Import'); |
|
474 |
$this->assertText('Created 7 nodes'); |
|
475 |
$this->assertText('Failed importing 3 nodes.'); |
|
476 |
$this->assertText("Field validation errors in item 'Open Atrium Translation Workflow: Two Way Translation Updates'"); |
|
477 |
$this->assertText("Field validation errors in item 'Mapping Innovation at the World Bank with Open Atrium'"); |
|
478 |
$this->assertText("Field validation errors in item 'Open Data for Microfinance: The New MIXMarket.org'"); |
|
479 |
$this->assertText('alpha_text_label: this field cannot hold more than 6 values.'); |
|
480 |
} |
|
481 |
|
|
233 | 482 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules