1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Tests for plugins/FeedsTermProcessor.inc
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Test aggregating a feed as data records.
|
10
|
*/
|
11
|
class FeedsCSVtoTermsTest extends FeedsWebTestCase {
|
12
|
public static function getInfo() {
|
13
|
return array(
|
14
|
'name' => 'CSV import to taxonomy',
|
15
|
'description' => 'Tests a standalone import configuration that uses file fetcher and CSV parser to import taxonomy terms from a CSV file.',
|
16
|
'group' => 'Feeds',
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* Set up test.
|
22
|
*/
|
23
|
public function setUp() {
|
24
|
parent::setUp();
|
25
|
|
26
|
// Create an importer.
|
27
|
$this->createImporterConfiguration('Term import', 'term_import');
|
28
|
|
29
|
// Set and configure plugins and mappings.
|
30
|
$this->setPlugin('term_import', 'FeedsFileFetcher');
|
31
|
$this->setPlugin('term_import', 'FeedsCSVParser');
|
32
|
$this->setPlugin('term_import', 'FeedsTermProcessor');
|
33
|
|
34
|
// Create vocabulary.
|
35
|
$edit = array(
|
36
|
'name' => 'Addams vocabulary',
|
37
|
'machine_name' => 'addams',
|
38
|
);
|
39
|
$this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save'));
|
40
|
|
41
|
$this->setSettings('term_import', 'FeedsTermProcessor', array('bundle' => 'addams'));
|
42
|
|
43
|
// Use standalone form.
|
44
|
$this->setSettings('term_import', NULL, array('content_type' => ''));
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
* Test term creation, refreshing/deleting feeds and feed items.
|
49
|
*/
|
50
|
public function test() {
|
51
|
|
52
|
$mappings = array(
|
53
|
0 => array(
|
54
|
'source' => 'name',
|
55
|
'target' => 'name',
|
56
|
'unique' => 1,
|
57
|
),
|
58
|
);
|
59
|
$this->addMappings('term_import', $mappings);
|
60
|
|
61
|
// Import and assert.
|
62
|
$this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
|
63
|
$this->assertText('Created 5 terms');
|
64
|
$this->drupalGet('admin/structure/taxonomy/addams');
|
65
|
$this->assertText('Morticia');
|
66
|
$this->assertText('Fester');
|
67
|
$this->assertText('Gomez');
|
68
|
$this->assertText('Pugsley');
|
69
|
|
70
|
// Import again.
|
71
|
$this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
|
72
|
$this->assertText('There are no new terms.');
|
73
|
|
74
|
// Force update.
|
75
|
$this->setSettings('term_import', 'FeedsTermProcessor', array(
|
76
|
'skip_hash_check' => TRUE,
|
77
|
'update_existing' => 2,
|
78
|
));
|
79
|
$this->importFile('term_import', $this->absolutePath() . '/tests/feeds/users.csv');
|
80
|
$this->assertText('Updated 5 terms.');
|
81
|
|
82
|
// Add a term manually, delete all terms, this term should still stand.
|
83
|
$edit = array(
|
84
|
'name' => 'Cousin Itt',
|
85
|
);
|
86
|
$this->drupalPost('admin/structure/taxonomy/addams/add', $edit, t('Save'));
|
87
|
$this->drupalPost('import/term_import/delete-items', array(), t('Delete'));
|
88
|
$this->drupalGet('admin/structure/taxonomy/addams');
|
89
|
$this->assertText('Cousin Itt');
|
90
|
$this->assertNoText('Morticia');
|
91
|
$this->assertNoText('Fester');
|
92
|
$this->assertNoText('Gomez');
|
93
|
$this->assertNoText('Pugsley');
|
94
|
}
|
95
|
}
|