Projet

Général

Profil

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

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

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
  public static function getInfo() {
13
    return array(
14
      'name' => 'Mapper: List and Boolean',
15
      'description' => 'Test Feeds Mapper support for List and Boolean fields.',
16
      'group' => 'Feeds',
17
      'dependencies' => array('list'),
18
    );
19
  }
20

    
21
  public function setUp() {
22
    parent::setUp(array('list'));
23
  }
24

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

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

    
92
    // Import CSV file.
93
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
94
    $this->assertText('Created 2 nodes');
95

    
96
    // Check the two imported nodes.
97
    $this->drupalGet('node/1/edit');
98
    $this->assertOptionSelected('edit-field-alpha-und', 'Lorem');
99
    $this->assertOptionSelected('edit-field-beta-und', '42');
100
    $this->assertOptionSelected('edit-field-delta-und', '3.14159');
101
    $this->assertFieldChecked('edit-field-epsilon-und');
102
    $this->drupalGet('node/2/edit');
103
    $this->assertOptionSelected('edit-field-alpha-und', 'Ut wisi');
104
    $this->assertOptionSelected('edit-field-beta-und', '32');
105
    $this->assertOptionSelected('edit-field-delta-und', '5.62951');
106
    $this->assertNoFieldChecked('edit-field-epsilon-und');
107

    
108
    // Import CSV file with empty values.
109
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_empty.csv');
110
    $this->assertText('Updated 2 nodes');
111

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

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

    
144
    // Re-import the first file again.
145
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content.csv');
146
    $this->assertText('Updated 2 nodes');
147

    
148
    // Check if the two imported nodes have content again.
149
    $this->drupalGet('node/1/edit');
150
    $this->assertOptionSelected('edit-field-alpha-und', 'Lorem');
151
    $this->assertOptionSelected('edit-field-beta-und', '42');
152
    $this->assertOptionSelected('edit-field-delta-und', '3.14159');
153
    $this->assertFieldChecked('edit-field-epsilon-und');
154
    $this->drupalGet('node/2/edit');
155
    $this->assertOptionSelected('edit-field-alpha-und', 'Ut wisi');
156
    $this->assertOptionSelected('edit-field-beta-und', '32');
157
    $this->assertOptionSelected('edit-field-delta-und', '5.62951');
158
    $this->assertNoFieldChecked('edit-field-epsilon-und');
159

    
160
    // Import CSV file with non-existent values.
161
    $this->importFile('csv', $this->absolutePath() . '/tests/feeds/content_non_existent.csv');
162
    $this->assertText('Updated 2 nodes');
163

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