Projet

Général

Profil

Révision a192dc0b

Ajouté par Assos Assos il y a environ 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/feeds/tests/feeds_processor_term.test
120 120
    $this->assertText(t('No vocabulary defined for Taxonomy Term processor.'));
121 121
  }
122 122

  
123
  /**
124
   * Tests that terms mapped to their parent by GUID are from the same vocabulary.
125
   */
126
  public function testParentTargetByGUID() {
127
    // Create an other vocabulary.
128
    $vocabulary1 = 'addams';
129
    $vocabulary2 = strtolower($this->randomName());
130
    $edit = array(
131
      'name' => $this->randomString(),
132
      'machine_name' => $vocabulary2,
133
    );
134
    $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
135

  
136
    // Add mappings for the first importer.
137
    $this->addMappings('term_import',
138
      array(
139
        0 => array(
140
          'source' => 'guid',
141
          'target' => 'guid',
142
          'unique' => TRUE,
143
        ),
144
        1 => array(
145
          'source' => 'name',
146
          'target' => 'name',
147
        ),
148
        2 => array(
149
          'source' => 'parentguid',
150
          'target' => 'parentguid',
151
        ),
152
      )
153
    );
154

  
155
    // Create a second importer.
156
    $this->createImporterConfiguration('Term import 2', 'term_import2');
157
    $this->setSettings('term_import2', NULL, array('content_type' => ''));
158

  
159
    // Set and configure plugins and mappings.
160
    $this->setPlugin('term_import2', 'FeedsFileFetcher');
161
    $this->setPlugin('term_import2', 'FeedsCSVParser');
162
    $this->setPlugin('term_import2', 'FeedsTermProcessor');
163
    $this->setSettings('term_import2', 'FeedsTermProcessor', array('bundle' => $vocabulary2));
164

  
165
    // Add mappings for the second importer.
166
    $this->addMappings('term_import2',
167
      array(
168
        0 => array(
169
          'source' => 'guid',
170
          'target' => 'guid',
171
          'unique' => TRUE,
172
        ),
173
        1 => array(
174
          'source' => 'name',
175
          'target' => 'name',
176
        ),
177
        2 => array(
178
          'source' => 'parentguid',
179
          'target' => 'parentguid',
180
        ),
181
      )
182
    );
183

  
184
    $values = array(
185
      1 => 'Europe',
186
      2 => 'Belgium',
187
    );
188

  
189
    // Import file using the first importer.
190
    $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/terms.csv');
191
    $this->assertText('Created 2 terms.');
192

  
193
    // Assert that two terms were created in the first vocabulary.
194
    $terms = entity_load('taxonomy_term', array_keys($values));
195
    foreach ($terms as $tid => $term) {
196
      $this->assertEqual($values[$tid], $term->name);
197
      $this->assertEqual($vocabulary1, $term->vocabulary_machine_name);
198
    }
199
    // Assert that the second term's parent is the first term.
200
    $parents = taxonomy_get_parents($terms[2]->tid);
201
    $message = format_string('The term @term is correctly linked to its parent.', array('@term' => $terms[2]->name));
202
    if (!empty($parents)) {
203
      $parent = current($parents);
204
      $this->assertEqual(1, $parent->tid, $message);
205
    }
206
    else {
207
      $this->fail($message);
208
    }
209

  
210
    $values = array(
211
      3 => 'Europe',
212
      4 => 'Belgium',
213
    );
214

  
215
    // Now import the file using the second importer.
216
    $this->importFile('term_import2', $this->absolutePath() . '/tests/feeds/terms.csv');
217
    $this->assertText('Created 2 terms.');
218

  
219
    // Assert that two terms were created in the second vocabulary.
220
    $terms = entity_load('taxonomy_term', array_keys($values));
221
    foreach ($terms as $tid => $term) {
222
      $this->assertEqual($values[$tid], $term->name);
223
      $this->assertEqual($vocabulary2, $term->vocabulary_machine_name);
224
    }
225
    // Assert that the second term's parent is the first term.
226
    $parents = taxonomy_get_parents($terms[4]->tid);
227
    $message = format_string('The term @term is correctly linked to its parent.', array('@term' => $terms[4]->name));
228
    if (!empty($parents)) {
229
      $parent = current($parents);
230
      $this->assertEqual(3, $parent->tid, $message);
231
    }
232
    else {
233
      $this->fail($message);
234
    }
235
  }
236

  
237
  /**
238
   * Tests that terms mapped to their parent by GUID are from the same vocabulary.
239
   */
240
  public function testParentTargetByName() {
241
    // Create an other vocabulary.
242
    $vocabulary1 = 'addams';
243
    $vocabulary2 = strtolower($this->randomName());
244
    $edit = array(
245
      'name' => $this->randomString(),
246
      'machine_name' => $vocabulary2,
247
    );
248
    $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
249

  
250
    // Add mappings for the first importer.
251
    $this->addMappings('term_import',
252
      array(
253
        0 => array(
254
          'source' => 'guid',
255
          'target' => 'guid',
256
          'unique' => TRUE,
257
        ),
258
        1 => array(
259
          'source' => 'name',
260
          'target' => 'name',
261
        ),
262
        2 => array(
263
          'source' => 'parent',
264
          'target' => 'parent',
265
        ),
266
      )
267
    );
268

  
269
    // Create a second importer.
270
    $this->createImporterConfiguration('Term import 2', 'term_import2');
271
    $this->setSettings('term_import2', NULL, array('content_type' => ''));
272

  
273
    // Set and configure plugins and mappings.
274
    $this->setPlugin('term_import2', 'FeedsFileFetcher');
275
    $this->setPlugin('term_import2', 'FeedsCSVParser');
276
    $this->setPlugin('term_import2', 'FeedsTermProcessor');
277
    $this->setSettings('term_import2', 'FeedsTermProcessor', array('bundle' => $vocabulary2));
278

  
279
    // Add mappings for the second importer.
280
    $this->addMappings('term_import2',
281
      array(
282
        0 => array(
283
          'source' => 'guid',
284
          'target' => 'guid',
285
          'unique' => TRUE,
286
        ),
287
        1 => array(
288
          'source' => 'name',
289
          'target' => 'name',
290
        ),
291
        2 => array(
292
          'source' => 'parent',
293
          'target' => 'parent',
294
        ),
295
      )
296
    );
297

  
298
    $values = array(
299
      1 => 'Europe',
300
      2 => 'Belgium',
301
    );
302

  
303
    // Import file using the first importer.
304
    $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/terms.csv');
305
    $this->assertText('Created 2 terms.');
306

  
307
    // Assert that two terms were created in the first vocabulary.
308
    $terms = entity_load('taxonomy_term', array_keys($values));
309
    foreach ($terms as $tid => $term) {
310
      $this->assertEqual($values[$tid], $term->name);
311
      $this->assertEqual($vocabulary1, $term->vocabulary_machine_name);
312
    }
313
    // Assert that the second term's parent is the first term.
314
    $parents = taxonomy_get_parents($terms[2]->tid);
315
    $message = format_string('The term @term is correctly linked to its parent.', array('@term' => $terms[2]->name));
316
    if (!empty($parents)) {
317
      $parent = current($parents);
318
      $this->assertEqual(1, $parent->tid, $message);
319
    }
320
    else {
321
      $this->fail($message);
322
    }
323

  
324
    $values = array(
325
      3 => 'Europe',
326
      4 => 'Belgium',
327
    );
328

  
329
    // Now import the file using the second importer.
330
    $this->importFile('term_import2', $this->absolutePath() . '/tests/feeds/terms.csv');
331
    $this->assertText('Created 2 terms.');
332

  
333
    // Assert that two terms were created in the second vocabulary.
334
    $terms = entity_load('taxonomy_term', array_keys($values));
335
    foreach ($terms as $tid => $term) {
336
      $this->assertEqual($values[$tid], $term->name);
337
      $this->assertEqual($vocabulary2, $term->vocabulary_machine_name);
338
    }
339
    // Assert that the second term's parent is the first term.
340
    $parents = taxonomy_get_parents($terms[4]->tid);
341
    $message = format_string('The term @term is correctly linked to its parent.', array('@term' => $terms[4]->name));
342
    if (!empty($parents)) {
343
      $parent = current($parents);
344
      $this->assertEqual(3, $parent->tid, $message);
345
    }
346
    else {
347
      $this->fail($message);
348
    }
349
  }
350

  
351
  /**
352
   * Test replacing terms on subsequent imports.
353
   */
354
  public function testReplaceTerms() {
355
    $mappings = array(
356
      0 => array(
357
        'source' => 'name',
358
        'target' => 'name',
359
        'unique' => 1,
360
      ),
361
    );
362
    $this->addMappings('term_import', $mappings);
363

  
364
    // Configure the processor to "Replace existing terms".
365
    $this->setSettings('term_import', 'FeedsTermProcessor', array(
366
      'skip_hash_check' => TRUE,
367
      'update_existing' => 1,
368
    ));
369

  
370
    // Import first time.
371
    $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
372
    $this->assertText('Created 5 terms');
373

  
374
    // Import again to replace terms.
375
    $this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
376
    $this->assertText('Updated 5 terms.');
377
  }
378

  
123 379
}

Formats disponibles : Unified diff