db2a06c57d5b8575bbe2b910a60c38346f40476d
6 * Tests for plugins/FeedsNodeProcessor.inc.
9 // Require FeedsWebTestCase class definition.
10 require_once(dirname(__FILE__
) .
'/feeds.test.inc');
13 * Test aggregating a feed as node items.
15 class FeedsRSStoNodesTest
extends FeedsWebTestCase
{
20 public
function getInfo() {
22 'name' => t('RSS import to nodes'),
23 'description' => t('Tests a feed configuration that is attached to a content type, uses HTTP fetcher, common syndication parser and a node processor. Repeats the same test for an importer configuration that is not attached to a content type and for a configuration that is attached to a content type and uses the file fetcher.'),
24 'group' => t('Feeds'),
31 public
function setUp() {
32 parent
::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler');
34 $this->drupalCreateUser(
36 'administer feeds', 'administer nodes', 'administer content types',
43 * Test node creation, refreshing/deleting feeds and feed items.
45 public
function test() {
46 // Set the teaser length to unlimited otherwise tests looking for text on
51 $this->drupalPost('admin/content/node-settings', $edit, 'Save configuration');
53 // Create an importer configuration.
54 $this->createImporterConfiguration('Syndication', 'syndication');
55 $this->addMappings('syndication',
63 'source' => 'description',
68 'source' => 'timestamp',
69 'target' => 'created',
85 $nid = $this->createFeedNode();
86 // Assert 10 items aggregated after creation of the node.
87 $this->assertText('Created 10 Story nodes.');
89 // Navigate to feed node, there should be Feeds tabs visible.
90 $this->drupalGet('node/'.
$nid);
91 $this->assertRaw('node/'.
$nid .
'/import');
92 $this->assertRaw('node/'.
$nid .
'/delete-items');
94 // Navigate to a non-feed node, there should be no Feeds tabs visible.
95 $story_nid = db_query_range('SELECT nid FROM {node} WHERE type = "story"', 0, 1)->fetchField();
96 $this->drupalGet('node/'.
$story_nid);
97 $this->assertNoRaw('node/'.
$story_nid .
'/import');
98 $this->assertNoRaw('node/'.
$story_nid .
'/delete-items');
99 $this->assertEqual("Created/updated by FeedsNodeProcessor", db_query("SELECT nr.log FROM {node} n JOIN {node_revisions} nr ON n.vid = nr.vid WHERE n.nid = :nid", array(':nid' => $story_nid))->fetchField());
101 // Assert accuracy of aggregated information.
102 $this->drupalGet('node');
103 $this->assertPattern('/<span class="submitted">(.*?)Anonymous<\/span>/');
104 $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
105 $this->assertText('Tue, 10/06/2009');
106 $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal');
107 $this->assertText('Week in DC Tech: October 5th Edition');
108 $this->assertText('Mon, 10/05/2009');
109 $this->assertText('There are some great technology events happening this week');
110 $this->assertText('Mapping Innovation at the World Bank with Open Atrium');
111 $this->assertText('Fri, 10/02/2009');
112 $this->assertText('Open Atrium is being used as a base platform for collaboration');
113 $this->assertText('September GeoDC Meetup Tonight');
114 $this->assertText('Wed, 09/30/2009');
115 $this->assertText('Today is the last Wednesday of the month');
116 $this->assertText('Week in DC Tech: September 28th Edition');
117 $this->assertText('Mon, 09/28/2009');
118 $this->assertText('Looking to geek out this week? There are a bunch of');
119 $this->assertText('Open Data for Microfinance: The New MIXMarket.org');
120 $this->assertText('Thu, 09/24/2009');
121 $this->assertText('There are profiles for every country that the MIX Market is hosting.');
122 $this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet');
123 $this->assertText('Tue, 09/22/2009');
124 $this->assertText('In addition to authentication, the Siteminder system');
125 $this->assertText('Week in DC Tech: September 21 Edition');
126 $this->assertText('Mon, 09/21/2009');
127 $this->assertText('an interesting variety of technology events happening in Washington, DC ');
128 $this->assertText('s Software Freedom Day: Impressions & Photos');
129 $this->assertText('Mon, 09/21/2009');
130 $this->assertText('Presenting on Features in Drupal and Open Atrium');
131 $this->assertText('Scaling the Open Atrium UI');
132 $this->assertText('Fri, 09/18/2009');
133 $this->assertText('The first major change is switching');
136 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")->fetchField();
137 $this->assertEqual($count, 10, 'Accurate number of items in database.');
139 // Assert default input format on first imported feed node.
140 $format = db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revisions} nr ON n.vid = nr.vid", 0, 1)->fetchField();
141 $this->assertEqual($format, filter_fallback_format(), 'Using default Input format.');
144 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
145 $this->assertText('There is no new content.');
147 // Assert DB status, there still shouldn't be more than 10 items.
148 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")->fetchField();
149 $this->assertEqual($count, 10, 'Accurate number of items in database.');
151 // All of the above tests should have produced published nodes, set default
152 // to unpublished, import again.
153 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 1")->fetchField();
154 $this->assertEqual($count, 10, 'All items are published.');
156 'node_options[status]' => FALSE
,
158 $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type'));
159 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
160 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
161 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 0")->fetchField();
162 $this->assertEqual($count, 10, 'No items are published.');
164 'node_options[status]' => TRUE
,
166 $this->drupalPost('admin/content/node-type/story', $edit, t('Save content type'));
167 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
169 // Enable replace existing and import updated feed file.
170 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
171 $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1));
172 $feed_url = $GLOBALS['base_url'] .
'/'.
drupal_get_path('module', 'feeds') .
'/tests/feeds/developmentseed_changes.rss2';
173 $this->editFeedNode($nid, $feed_url);
174 $this->drupalPost('node/' .
$nid .
'/import', array(), 'Import');
175 $this->assertText('Updated 2 Story nodes.');
177 // Assert accuracy of aggregated content (check 2 updates, one original).
178 $this->drupalGet('node');
179 $this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
180 $this->assertText('Presenting on Features in Drupal and Managing News');
181 $this->assertText('Scaling the Open Atrium UI');
184 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
185 $this->assertText('There is no new content.');
187 // Assert DB status, there still shouldn't be more than 10 items.
188 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
189 $this->assertEqual($count, 10, 'Accurate number of items in database.');
191 // Now delete all items.
192 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
193 $this->assertText('Deleted 10 nodes.');
195 // Assert DB status, now there should be no items.
196 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
197 $this->assertEqual($count, 0, 'Accurate number of items in database.');
200 $author = $this->drupalCreateUser();
201 $this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $author->name
));
203 // Change input format.
204 $this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => filter_fallback_format() + 1));
207 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
208 $this->assertText('Created 10 Story nodes.');
211 $this->drupalGet('node');
212 $this->assertPattern('/<span class="submitted">(.*?)'.
check_plain($author->name
) .
'<\/span>/');
213 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid WHERE n.uid = :uid", array(':uid' => $author->uid
))->fetchField();
214 $this->assertEqual($count, 10, 'Accurate number of items in database.');
216 // Assert input format.
217 $format = db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revisions} nr ON n.vid = nr.vid", 0, 1)->fetchField();
218 $this->assertEqual($format, filter_fallback_format() + 1, 'Set non-default Input format.');
220 // Set to update existing, remove authorship of above nodes and import again.
221 $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 2));
222 db_query("UPDATE {node} n JOIN {feeds_node_item} fi ON n.nid = fi.nid SET n.uid = 0, fi.hash=''");
223 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
224 $this->drupalGet('node');
225 $this->assertNoPattern('/<span class="submitted">(.*?)'.
check_plain($author->name
) .
'<\/span>/');
226 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid WHERE n.uid = :uid", array(':uid' => $author->uid
))->fetchField();
227 $this->assertEqual($count, 0, 'Accurate number of items in database.');
229 // Map feed node's author to feed item author, update - feed node's items
230 // should now be assigned to feed node author.
231 $this->addMappings('syndication',
234 'source' => 'parent:uid',
239 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
240 $this->drupalGet('node');
241 $this->assertNoPattern('/<span class="submitted">(.*?)'.
check_plain($author->name
) .
'<\/span>/');
242 $uid = db_query("SELECT uid FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
243 $count = db_query("SELECT COUNT(*) FROM {node} WHERE uid = :uid", array(':uid' =>$uid))->fetchField();
244 $this->assertEqual($count, 11, 'All feed item nodes are assigned to feed node author.');
246 // Login with new user with only access content permissions.
248 $this->drupalCreateUser()
250 // Navigate to feed node, there should be no Feeds tabs visible.
251 $this->drupalGet('node/'.
$nid);
252 $this->assertNoRaw('node/'.
$nid .
'/import');
253 $this->assertNoRaw('node/'.
$nid .
'/delete-items');
255 // Now create a second feed configuration that is not attached to a content
256 // type and run tests on importing/purging.
258 // Login with sufficient permissions.
260 $this->drupalCreateUser(array('administer feeds', 'administer nodes'))
262 // Remove all items again so that next test can check for them.
263 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
265 // Create an importer, not attached to content type.
266 $this->createImporterConfiguration('Syndication standalone', 'syndication_standalone');
268 'content_type' => '',
270 $this->drupalPost('admin/structure/feeds/edit/syndication_standalone/settings', $edit, 'Save');
271 $this->addMappings('syndication_standalone',
279 'source' => 'description',
284 'source' => 'timestamp',
285 'target' => 'created',
301 // Import, assert 10 items aggregated after creation of the node.
302 $this->importURL('syndication_standalone');
303 $this->assertText('Created 10 Story nodes.');
305 // Assert accuracy of aggregated information.
306 $this->drupalGet('node');
307 $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
308 $this->assertText('Tue, 10/06/2009');
309 $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal');
310 $this->assertText('Week in DC Tech: October 5th Edition');
311 $this->assertText('Mon, 10/05/2009');
312 $this->assertText('There are some great technology events happening this week');
313 $this->assertText('Mapping Innovation at the World Bank with Open Atrium');
314 $this->assertText('Fri, 10/02/2009');
315 $this->assertText('Open Atrium is being used as a base platform for collaboration');
316 $this->assertText('September GeoDC Meetup Tonight');
317 $this->assertText('Wed, 09/30/2009');
318 $this->assertText('Today is the last Wednesday of the month');
319 $this->assertText('Week in DC Tech: September 28th Edition');
320 $this->assertText('Mon, 09/28/2009');
321 $this->assertText('Looking to geek out this week? There are a bunch of');
322 $this->assertText('Open Data for Microfinance: The New MIXMarket.org');
323 $this->assertText('Thu, 09/24/2009');
324 $this->assertText('There are profiles for every country that the MIX Market is hosting.');
325 $this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet');
326 $this->assertText('Tue, 09/22/2009');
327 $this->assertText('In addition to authentication, the Siteminder system');
328 $this->assertText('Week in DC Tech: September 21 Edition');
329 $this->assertText('Mon, 09/21/2009');
330 $this->assertText('an interesting variety of technology events happening in Washington, DC ');
331 $this->assertText('s Software Freedom Day: Impressions & Photos');
332 $this->assertText('Mon, 09/21/2009');
333 $this->assertText('Presenting on Features in Drupal and Open Atrium');
334 $this->assertText('Scaling the Open Atrium UI');
335 $this->assertText('Fri, 09/18/2009');
336 $this->assertText('The first major change is switching');
339 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
340 $this->assertEqual($count, 10, 'Accurate number of items in database.');
343 $this->drupalPost('import/syndication_standalone', array(), 'Import');
344 $this->assertText('There is no new content.');
346 // Assert DB status, there still shouldn't be more than 10 items.
347 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
348 $this->assertEqual($count, 10, 'Accurate number of items in database.');
350 // Enable replace existing and import updated feed file.
351 $this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => 1));
352 $feed_url = $GLOBALS['base_url'] .
'/'.
drupal_get_path('module', 'feeds') .
'/tests/feeds/developmentseed_changes.rss2';
353 $this->importURL('syndication_standalone', $feed_url);
354 $this->assertText('Updated 2 Story nodes.');
356 // Assert accuracy of aggregated information (check 2 updates, one orig).
357 $this->drupalGet('node');
358 $this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
359 $this->assertText('Presenting on Features in Drupal and Managing News');
360 $this->assertText('Scaling the Open Atrium UI');
363 $this->drupalPost('import/syndication_standalone', array(), 'Import');
364 $this->assertText('There is no new content.');
366 // Assert DB status, there still shouldn't be more than 10 items.
367 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
368 $this->assertEqual($count, 10, 'Accurate number of items in database.');
370 // Now delete all items.
371 $this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
372 $this->assertText('Deleted 10 nodes.');
374 // Assert DB status, now there should be no items.
375 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
376 $this->assertEqual($count, 0, 'Accurate number of items in database.');
378 // Import again, we should find new content.
379 $this->drupalPost('import/syndication_standalone', array(), 'Import');
380 $this->assertText('Created 10 Story nodes.');
382 // Assert DB status, there should be 10 again.
383 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
384 $this->assertEqual($count, 10, 'Accurate number of items in database.');
386 // Login with new user with only access content permissions.
388 $this->drupalCreateUser()
390 // Navigate to feed import form, access should be denied.
391 $this->drupalGet('import/syndication_standalone');
392 $this->assertResponse(403);
396 $this->drupalCreateUser(array('administer feeds', 'administer nodes'))
398 $this->setPlugin('syndication', 'FeedsFileFetcher');
399 // Create a feed node.
401 'files[feeds]' => $this->absolutePath() .
'/tests/feeds/drupalplanet.rss2',
403 $this->drupalPost('node/add/page', $edit, 'Save');
404 $this->assertText('has been created.');
405 $this->assertText('Created 25 Story nodes.');