Projet

Général

Profil

Paste
Télécharger (2,42 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / feeds_mapper_field.test @ 13755f8d

1
<?php
2

    
3
/**
4
 * @file
5
 * Test case for simple CCK field mapper mappers/content.inc.
6
 */
7

    
8
/**
9
 * Class for testing Feeds field mapper.
10
 */
11
class FeedsMapperFieldTestCase extends FeedsMapperTestCase {
12
  public static function getInfo() {
13
    return array(
14
      'name' => 'Mapper: Fields',
15
      'description' => 'Test Feeds Mapper support for fields.',
16
      'group' => 'Feeds',
17
    );
18
  }
19

    
20
  public function setUp() {
21
    parent::setUp(array('number'));
22
  }
23

    
24
  /**
25
   * Basic test loading a double entry CSV file.
26
   */
27
  function test() {
28
    // Create content type.
29
    $typename = $this->createContentType(array(), array(
30
      'alpha' => 'text',
31
      'beta' => 'number_integer',
32
      'gamma' => 'number_decimal',
33
      'delta' => 'number_float',
34
    ));
35

    
36
    // Create and configure importer.
37
    $this->createImporterConfiguration('Content CSV', 'csv');
38
    $this->setSettings('csv', NULL, array('content_type' => '', 'import_period' => FEEDS_SCHEDULE_NEVER));
39
    $this->setPlugin('csv', 'FeedsFileFetcher');
40
    $this->setPlugin('csv', 'FeedsCSVParser');
41
    $this->setSettings('csv', 'FeedsNodeProcessor', array('bundle' => $typename));
42
    $this->addMappings('csv', array(
43
      0 => array(
44
        'source' => 'title',
45
        'target' => 'title',
46
      ),
47
      1 => array(
48
        'source' => 'created',
49
        'target' => 'created',
50
      ),
51
      2 => array(
52
        'source' => 'body',
53
        'target' => 'body',
54
      ),
55
      3 => array(
56
        'source' => 'alpha',
57
        'target' => 'field_alpha',
58
      ),
59
      4 => array(
60
        'source' => 'beta',
61
        'target' => 'field_beta',
62
      ),
63
      5 => array(
64
        'source' => 'gamma',
65
        'target' => 'field_gamma',
66
      ),
67
      6 => array(
68
        'source' => 'delta',
69
        'target' => 'field_delta',
70
      ),
71
    ));
72

    
73
    // Import CSV file.
74
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
75
    $this->assertText('Created 2 nodes');
76

    
77
    // Check the two imported files.
78
    $this->drupalGet('node/1/edit');
79
    $this->assertNodeFieldValue('alpha', 'Lorem');
80
    $this->assertNodeFieldValue('beta', '42');
81
    $this->assertNodeFieldValue('gamma', '4.20');
82
    $this->assertNodeFieldValue('delta', '3.14159');
83

    
84
    $this->drupalGet('node/2/edit');
85
    $this->assertNodeFieldValue('alpha', 'Ut wisi');
86
    $this->assertNodeFieldValue('beta', '32');
87
    $this->assertNodeFieldValue('gamma', '1.20');
88
    $this->assertNodeFieldValue('delta', '5.62951');
89
  }
90
}