Projet

Général

Profil

Paste
Télécharger (6,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / tests / feeds_mapper_list.test @ ed9a13f1

1
<?php
2

    
3
/**
4
 * @file
5
 * Contains FeedsMapperListTestCase.
6
 */
7

    
8
/**
9
 * Test case for List field mappers in mappers/list.inc.
10
 */
11
class FeedsMapperListTestCase extends FeedsMapperTestCase {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public static function getInfo() {
17
    return array(
18
      'name' => 'Mapper: List and Boolean',
19
      'description' => 'Test Feeds Mapper support for List and Boolean fields.',
20
      'group' => 'Feeds',
21
      'dependencies' => array('list'),
22
    );
23
  }
24

    
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function setUp() {
29
    parent::setUp(array('list'));
30
  }
31

    
32
  /**
33
   * Tests if values are cleared out when an empty value is provided.
34
   */
35
  public function testClearOutValues() {
36
    // Create content type.
37
    $typename = $this->createContentType(array(), array(
38
      'alpha' => array(
39
        'type' => 'list_text',
40
        'settings' => array(
41
          'field[settings][allowed_values]' => "0\nLorem\nUt wisi",
42
        ),
43
      ),
44
      'beta' => array(
45
        'type' => 'list_integer',
46
        'settings' => array(
47
          'field[settings][allowed_values]' => "0\n42\n32",
48
        ),
49
      ),
50
      'delta' => array(
51
        'type' => 'list_float',
52
        'settings' => array(
53
          'field[settings][allowed_values]' => "0\n3.14159\n5.62951",
54
        ),
55
      ),
56
      'epsilon' => 'list_boolean',
57
    ));
58

    
59
    // Create and configure importer.
60
    $this->createImporterConfiguration('Content CSV', 'csv');
61
    $this->setSettings('csv', NULL, array(
62
      'content_type' => '',
63
      'import_period' => FEEDS_SCHEDULE_NEVER,
64
    ));
65
    $this->setPlugin('csv', 'FeedsFileFetcher');
66
    $this->setPlugin('csv', 'FeedsCSVParser');
67
    $this->setSettings('csv', 'FeedsNodeProcessor', array(
68
      'bundle' => $typename,
69
      'update_existing' => 1,
70
    ));
71
    $this->addMappings('csv', array(
72
      array(
73
        'source' => 'guid',
74
        'target' => 'guid',
75
        'unique' => TRUE,
76
      ),
77
      array(
78
        'source' => 'title',
79
        'target' => 'title',
80
      ),
81
      array(
82
        'source' => 'alpha',
83
        'target' => 'field_alpha',
84
      ),
85
      array(
86
        'source' => 'beta',
87
        'target' => 'field_beta',
88
      ),
89
      array(
90
        'source' => 'delta',
91
        'target' => 'field_delta',
92
      ),
93
      array(
94
        'source' => 'epsilon',
95
        'target' => 'field_epsilon',
96
      ),
97
    ));
98

    
99
    // Import CSV file.
100
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
101
    $this->assertText('Created 2 nodes');
102

    
103
    // Check the two imported nodes.
104
    $this->drupalGet('node/1/edit');
105
    $this->assertOptionSelected('edit-field-alpha-und', 'Lorem');
106
    $this->assertOptionSelected('edit-field-beta-und', '42');
107
    $this->assertOptionSelected('edit-field-delta-und', '3.14159');
108
    $this->assertFieldChecked('edit-field-epsilon-und');
109
    $this->drupalGet('node/2/edit');
110
    $this->assertOptionSelected('edit-field-alpha-und', 'Ut wisi');
111
    $this->assertOptionSelected('edit-field-beta-und', '32');
112
    $this->assertOptionSelected('edit-field-delta-und', '5.62951');
113
    $this->assertNoFieldChecked('edit-field-epsilon-und');
114

    
115
    // Import CSV file with empty values.
116
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
117
    $this->assertText('Updated 2 nodes');
118

    
119
    // Check if all values were cleared out for node 1.
120
    $this->drupalGet('node/1/edit');
121
    $this->assertNoOptionSelected('edit-field-alpha-und', 'Lorem');
122
    $this->assertNoOptionSelected('edit-field-beta-und', '42');
123
    $this->assertNoOptionSelected('edit-field-delta-und', '3.14159');
124
    $this->assertNoFieldChecked('edit-field-epsilon-und');
125
    // Check if labels for fields that should be cleared out are not shown.
126
    $this->drupalGet('node/1');
127
    $this->assertNoText('alpha_list_text_label');
128
    $this->assertNoText('beta_list_integer_label');
129
    $this->assertNoText('delta_list_float_label');
130
    $this->assertNoText('epsilon_list_boolean_label');
131
    // Load node 1 and check if the boolean field does *not* have a value.
132
    $node = node_load(1, NULL, TRUE);
133
    $this->assertTrue(empty($node->field_epsilon[LANGUAGE_NONE]), 'The field field_epsilon is empty.');
134

    
135
    // Check if zero's didn't cleared out values for node 2.
136
    $this->drupalGet('node/2/edit');
137
    $this->assertOptionSelected('edit-field-alpha-und', '0');
138
    $this->assertOptionSelected('edit-field-beta-und', '0');
139
    $this->assertOptionSelected('edit-field-delta-und', '0');
140
    $this->assertNoFieldChecked('edit-field-epsilon-und');
141
    // Check if labels for fields of node 2 are still shown.
142
    $this->drupalGet('node/2');
143
    $this->assertText('alpha_list_text_label');
144
    $this->assertText('beta_list_integer_label');
145
    $this->assertText('delta_list_float_label');
146
    $this->assertText('epsilon_list_boolean_label');
147
    // Load node 2 and check if the boolean field *does* have a value.
148
    $node = node_load(2, NULL, TRUE);
149
    $this->assertEqual('0', $node->field_epsilon[LANGUAGE_NONE][0]['value']);
150

    
151
    // Re-import the first file again.
152
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
153
    $this->assertText('Updated 2 nodes');
154

    
155
    // Check if the two imported nodes have content again.
156
    $this->drupalGet('node/1/edit');
157
    $this->assertOptionSelected('edit-field-alpha-und', 'Lorem');
158
    $this->assertOptionSelected('edit-field-beta-und', '42');
159
    $this->assertOptionSelected('edit-field-delta-und', '3.14159');
160
    $this->assertFieldChecked('edit-field-epsilon-und');
161
    $this->drupalGet('node/2/edit');
162
    $this->assertOptionSelected('edit-field-alpha-und', 'Ut wisi');
163
    $this->assertOptionSelected('edit-field-beta-und', '32');
164
    $this->assertOptionSelected('edit-field-delta-und', '5.62951');
165
    $this->assertNoFieldChecked('edit-field-epsilon-und');
166

    
167
    // Import CSV file with non-existent values.
168
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
169
    $this->assertText('Updated 2 nodes');
170

    
171
    // Check if all values were cleared out for node 1.
172
    $this->drupalGet('node/1/edit');
173
    $this->assertNoOptionSelected('edit-field-alpha-und', 'Lorem');
174
    $this->assertNoOptionSelected('edit-field-beta-und', '42');
175
    $this->assertNoOptionSelected('edit-field-delta-und', '3.14159');
176
    $this->assertNoFieldChecked('edit-field-epsilon-und');
177
    // Check if labels for fields that should be cleared out are not shown.
178
    $this->drupalGet('node/1');
179
    $this->assertNoText('alpha_list_text_label');
180
    $this->assertNoText('beta_list_integer_label');
181
    $this->assertNoText('delta_list_float_label');
182
    $this->assertNoText('epsilon_list_boolean_label');
183
    // Load node 1 and check if the boolean field does *not* have a value.
184
    $node = node_load(1, NULL, TRUE);
185
    $this->assertTrue(empty($node->field_epsilon[LANGUAGE_NONE]), 'The field field_epsilon is empty.');
186
  }
187

    
188
}