1 | <?php |
---|
2 | module_load_include('test', 'feeds', 'tests/feeds_mapper'); |
---|
3 | |
---|
4 | /** |
---|
5 | * @file |
---|
6 | * Test case for taxonomy mapper mappers/taxonomy.inc. |
---|
7 | */ |
---|
8 | |
---|
9 | /** |
---|
10 | * Class for testing Feeds <em>content</em> mapper. |
---|
11 | */ |
---|
12 | class FeedsMapperTaxonomyTestCase extends FeedsMapperTestCase { |
---|
13 | public static function getInfo() { |
---|
14 | return array( |
---|
15 | 'name' => 'Mapper: Taxonomy', |
---|
16 | 'description' => 'Test Feeds Mapper support for Taxonomy.', |
---|
17 | 'group' => 'Feeds', |
---|
18 | ); |
---|
19 | } |
---|
20 | |
---|
21 | function setUp() { |
---|
22 | parent::setUp(); |
---|
23 | |
---|
24 | // Add a new taxonomy vocabulary, add to story content type. |
---|
25 | $edit = array( |
---|
26 | 'name' => 'Tags', |
---|
27 | 'tags' => TRUE, |
---|
28 | 'nodes[story]' => TRUE, |
---|
29 | 'nodes[page]' => TRUE, |
---|
30 | ); |
---|
31 | $this->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, 'Save'); |
---|
32 | // Create an importer configuration with basic mapping. |
---|
33 | $this->createImporterConfiguration('Syndication', 'syndication'); |
---|
34 | |
---|
35 | $this->addMappings('syndication', |
---|
36 | array( |
---|
37 | array( |
---|
38 | 'source' => 'title', |
---|
39 | 'target' => 'title', |
---|
40 | 'unique' => FALSE, |
---|
41 | ), |
---|
42 | array( |
---|
43 | 'source' => 'description', |
---|
44 | 'target' => 'body', |
---|
45 | 'unique' => FALSE, |
---|
46 | ), |
---|
47 | array( |
---|
48 | 'source' => 'timestamp', |
---|
49 | 'target' => 'created', |
---|
50 | 'unique' => FALSE, |
---|
51 | ), |
---|
52 | array( |
---|
53 | 'source' => 'url', |
---|
54 | 'target' => 'url', |
---|
55 | 'unique' => TRUE, |
---|
56 | ), |
---|
57 | array( |
---|
58 | 'source' => 'guid', |
---|
59 | 'target' => 'guid', |
---|
60 | 'unique' => TRUE, |
---|
61 | ), |
---|
62 | ) |
---|
63 | ); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * Test inheriting taxonomy from the feed node. |
---|
68 | */ |
---|
69 | function testInheritTaxonomy() { |
---|
70 | // Map feed node's taxonomy to feed item node's taxonomy. |
---|
71 | $this->addMappings('syndication', |
---|
72 | array( |
---|
73 | array( |
---|
74 | 'source' => 'parent:taxonomy:1', |
---|
75 | 'target' => 'taxonomy:1', |
---|
76 | ), |
---|
77 | ) |
---|
78 | ); |
---|
79 | // Turn off import on create, create feed node, tag, import. |
---|
80 | $edit = array( |
---|
81 | 'import_on_create' => FALSE, |
---|
82 | ); |
---|
83 | $this->drupalPost('admin/build/feeds/edit/syndication/settings', $edit, 'Save'); |
---|
84 | $this->assertText('Do not import on create'); |
---|
85 | $nid = $this->createFeedNode(); |
---|
86 | $terms = array('testterm1', 'testterm2', 'testterm3'); |
---|
87 | $edit = array( |
---|
88 | 'taxonomy[tags][1]' => implode(',', $terms), |
---|
89 | ); |
---|
90 | $this->drupalPost("node/$nid/edit", $edit, t('Save')); |
---|
91 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
92 | $count = db_result(db_query("SELECT COUNT(*) FROM {term_node}", $nid)); |
---|
93 | $this->assertEqual(33, $count, 'Found correct number of tags for all feed nodes and feed items.'); |
---|
94 | foreach ($terms as $term) { |
---|
95 | $this->assertTaxonomyTerm($term); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * Test aggregating RSS categories to taxonomy. |
---|
101 | */ |
---|
102 | function testRSSCategoriesToTaxonomy() { |
---|
103 | // Add mapping to tags vocabulary. |
---|
104 | $this->addMappings('syndication', |
---|
105 | array( |
---|
106 | array( |
---|
107 | 'source' => 'tags', |
---|
108 | 'target' => 'taxonomy:1', |
---|
109 | ), |
---|
110 | ) |
---|
111 | ); |
---|
112 | |
---|
113 | // Aggregate feed node with "Tag" vocabulary. |
---|
114 | $nid = $this->createFeedNode(); |
---|
115 | // Assert 10 items aggregated after creation of the node. |
---|
116 | $this->assertText('Created 10 Story nodes.'); |
---|
117 | // There should be 30 terms and 44 term-node relations. |
---|
118 | $this->assertEqual(30, db_result(db_query("SELECT count(*) FROM {term_data}")), "Found correct number of terms."); |
---|
119 | $this->assertEqual(44, db_result(db_query("SELECT count(*) FROM {term_node}")), "Found correct number of term-node relations."); |
---|
120 | |
---|
121 | // Take a look at the actual terms on frontpage. |
---|
122 | $this->drupalGet('node'); |
---|
123 | $terms = array( |
---|
124 | 'authentication', |
---|
125 | 'custom mapping', |
---|
126 | 'data visualization', |
---|
127 | 'Drupal', |
---|
128 | 'Drupal planet', |
---|
129 | 'faceted search', |
---|
130 | 'GeoDC', |
---|
131 | 'graphs', |
---|
132 | 'interface', |
---|
133 | 'intranet', |
---|
134 | 'localization', |
---|
135 | 'localization client', |
---|
136 | 'localization server', |
---|
137 | 'map-basec browser', |
---|
138 | 'mapbox', |
---|
139 | 'microfinance', |
---|
140 | 'MIX Market', |
---|
141 | 'open atrium', |
---|
142 | 'open data', |
---|
143 | 'open source', |
---|
144 | 'Peru', |
---|
145 | 'salesforce', |
---|
146 | 'siteminder', |
---|
147 | 'siteminder module', |
---|
148 | 'software freedom day', |
---|
149 | 'translation', |
---|
150 | 'translation server', |
---|
151 | 'usability', |
---|
152 | 'Washington DC', |
---|
153 | 'World Bank', |
---|
154 | ); |
---|
155 | foreach ($terms as $term) { |
---|
156 | $this->assertTaxonomyTerm($term); |
---|
157 | } |
---|
158 | |
---|
159 | // Delete all items, all associations are gone. |
---|
160 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
161 | $this->assertText('Deleted 10 nodes.'); |
---|
162 | $this->assertEqual(30, db_result(db_query("SELECT count(*) FROM {term_data}")), "Found correct number of terms."); |
---|
163 | $this->assertEqual(0, db_result(db_query("SELECT count(*) FROM {term_node}")), "Found correct number of term-node relations."); |
---|
164 | |
---|
165 | // Remove "Tag" setting, import again. |
---|
166 | $edit = array( |
---|
167 | 'tags' => FALSE, |
---|
168 | ); |
---|
169 | $this->drupalPost('admin/content/taxonomy/edit/vocabulary/1', $edit, 'Save'); |
---|
170 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
171 | $this->assertText('Created 10 Story nodes.'); |
---|
172 | |
---|
173 | // We should only get one term-node association per node. |
---|
174 | $this->assertEqual(30, db_result(db_query("SELECT count(*) FROM {term_data}")), "Found correct number of terms."); |
---|
175 | $this->assertEqual(10, db_result(db_query("SELECT count(*) FROM {term_node}")), "Found correct number of term-node relations."); |
---|
176 | |
---|
177 | // Delete all items. |
---|
178 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
179 | |
---|
180 | // Set vocabulary to multiple terms, import again. |
---|
181 | $edit = array( |
---|
182 | 'multiple' => TRUE, |
---|
183 | ); |
---|
184 | $this->drupalPost('admin/content/taxonomy/edit/vocabulary/1', $edit, 'Save'); |
---|
185 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
186 | $this->assertText('Created 10 Story nodes.'); |
---|
187 | |
---|
188 | // We should get all term-node associations again. |
---|
189 | $this->assertEqual(30, db_result(db_query("SELECT count(*) FROM {term_data}")), "Found correct number of terms."); |
---|
190 | $this->assertEqual(44, db_result(db_query("SELECT count(*) FROM {term_node}")), "Found correct number of term-node relations."); |
---|
191 | |
---|
192 | // Delete all items. |
---|
193 | $this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete'); |
---|
194 | |
---|
195 | // Remove a term, import again. |
---|
196 | $this->drupalPost('admin/content/taxonomy/edit/term/1', array(), 'Delete'); |
---|
197 | $this->drupalPost(NULL, array(), 'Delete'); |
---|
198 | $this->assertText('Deleted term'); |
---|
199 | $this->drupalPost('node/'. $nid .'/import', array(), 'Import'); |
---|
200 | $this->assertText('Created 10 Story nodes.'); |
---|
201 | |
---|
202 | // This term should now be missing from term-node associations. |
---|
203 | $this->assertEqual(29, db_result(db_query("SELECT count(*) FROM {term_data}")), "Found correct number of terms."); |
---|
204 | $this->assertEqual(39, db_result(db_query("SELECT count(*) FROM {term_node}")), "Found correct number of term-node relations.". db_result(db_query("SELECT count(*) FROM {term_node}"))); |
---|
205 | } |
---|
206 | |
---|
207 | /** |
---|
208 | * Helper, finds node style taxonomy term markup in DOM. |
---|
209 | */ |
---|
210 | public function assertTaxonomyTerm($term) { |
---|
211 | $term = check_plain($term); |
---|
212 | $this->assertPattern('/<a href="\/.*taxonomy\/term\/[0-9]+"[^>].*>' . $term . '<\/a>/', 'Found ' . $term); |
---|
213 | } |
---|
214 | } |
---|