Projet

Général

Profil

Révision ed9a13f1

Ajouté par Assos Assos il y a presque 4 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds/tests/feeds_mapper_field.test
10 10
 */
11 11
class FeedsMapperFieldTestCase extends FeedsMapperTestCase {
12 12

  
13
  /**
14
   * {@inheritdoc}
15
   */
13 16
  public static function getInfo() {
14 17
    return array(
15 18
      'name' => 'Mapper: Fields',
......
18 21
    );
19 22
  }
20 23

  
24
  /**
25
   * {@inheritdoc}
26
   */
21 27
  public function setUp() {
22 28
    parent::setUp(array('number'));
23 29
  }
......
273 279
    $this->assertText('alpha_text_label: the text may not be longer than 5 characters.');
274 280
  }
275 281

  
282
  /**
283
   * Tests integer field validation.
284
   */
285
  public function testIntegerFieldValidation() {
286
    // Create content type with a field with settings to validate.
287
    $typename = $this->createContentType(array(), array(
288
      'beta' => array(
289
        'type' => 'number_integer',
290
        'instance_settings' => array(
291
          'instance[settings][min]' => 30,
292
          'instance[settings][max]' => 40,
293
        ),
294
      ),
295
    ));
296

  
297
    // Create and configure importer.
298
    $this->createImporterConfiguration('CSV', 'csv');
299
    $this->setSettings('csv', NULL, array(
300
      'content_type' => '',
301
      'import_period' => FEEDS_SCHEDULE_NEVER,
302
    ));
303
    $this->setPlugin('csv', 'FeedsFileFetcher');
304
    $this->setPlugin('csv', 'FeedsCSVParser');
305
    $this->setSettings('csv', 'FeedsNodeProcessor', array(
306
      'bundle' => $typename,
307
    ));
308
    $this->addMappings('csv', array(
309
      0 => array(
310
        'source' => 'title',
311
        'target' => 'title',
312
      ),
313
      1 => array(
314
        'source' => 'beta',
315
        'target' => 'field_beta',
316
      ),
317
    ));
318
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
319
    $this->assertText('Created 1 node');
320
    $this->assertText('Failed importing 1 node.');
321
    $this->assertText("Field validation errors in item 'Lorem ipsum'");
322
    $this->assertText('beta_number_integer_label: the value may be no greater than 40.');
323
  }
324

  
276 325
  /**
277 326
   * Tests text field validation for nodes without a title.
278 327
   *
......
344 393
      'label' => 'alpha_text_label',
345 394
      'bundle' => 'addams',
346 395
      'widget' => array(
347
        'type' => 'textfield',
396
        'type' => 'text_textfield',
348 397
      ),
349 398
    ));
350 399

  
......
395 444
      'label' => 'alpha_text_label',
396 445
      'bundle' => 'user',
397 446
      'widget' => array(
398
        'type' => 'textfield',
447
        'type' => 'text_textfield',
399 448
      ),
400 449
    ));
401 450

  
......
479 528
    $this->assertText('alpha_text_label: this field cannot hold more than 6 values.');
480 529
  }
481 530

  
531
  /**
532
   * Tests that Feeds ignores validation of fields not mapped to.
533
   */
534
  public function testIgnoreUnmappedFieldsValidation() {
535
    // Include FeedsProcessor.inc so processor related constants are available.
536
    module_load_include('inc', 'feeds', 'plugins/FeedsProcessor');
537

  
538
    // Create content type with a field with settings to validate.
539
    $typename = $this->createContentType(array(), array(
540
      'alpha' => 'text',
541
      'beta' => array(
542
        'type' => 'number_integer',
543
        'instance_settings' => array(
544
          'instance[settings][min]' => 30,
545
          'instance[settings][max]' => 50,
546
        ),
547
      ),
548
    ));
549

  
550
    // Create a node of this type with an out of range integer value.
551
    $this->drupalCreateNode(array(
552
      'type' => $typename,
553
      'title' => 'Lorem ipsum',
554
      'field_beta' => array(
555
        LANGUAGE_NONE => array(
556
          0 => array(
557
            'value' => 25,
558
          ),
559
        ),
560
      ),
561
    ));
562

  
563
    // Create and configure importer.
564
    $this->createImporterConfiguration('CSV', 'csv');
565
    $this->setSettings('csv', NULL, array(
566
      'content_type' => '',
567
      'import_period' => FEEDS_SCHEDULE_NEVER,
568
    ));
569
    $this->setPlugin('csv', 'FeedsFileFetcher');
570
    $this->setPlugin('csv', 'FeedsCSVParser');
571
    $this->setSettings('csv', 'FeedsNodeProcessor', array(
572
      'bundle' => $typename,
573
      'update_existing' => FEEDS_UPDATE_EXISTING,
574
    ));
575
    $this->addMappings('csv', array(
576
      0 => array(
577
        'source' => 'title',
578
        'target' => 'title',
579
        'unique' => TRUE,
580
      ),
581
      1 => array(
582
        'source' => 'alpha',
583
        'target' => 'field_alpha',
584
      ),
585
    ));
586
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
587
    $this->assertText('Updated 1 node');
588
    $this->assertNoText('Field validation errors');
589
  }
590

  
482 591
}

Formats disponibles : Unified diff