5 * Tests for plugins/FeedsNodeProcessor.inc.
8 // Require FeedsWebTestCase class definition.
9 require_once(dirname(__FILE__
) .
'/feeds.test.inc');
12 * Test aggregating a feed as node items.
14 class FeedsRSStoNodesTest
extends FeedsWebTestCase
{
19 public
function getInfo() {
21 'name' => t('RSS import to nodes'),
22 '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.'),
23 'group' => t('Feeds'),
30 public
function setUp() {
31 parent
::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler');
32 $user = $this->drupalCreateUser(array(
33 'administer site configuration',
36 'administer content types',
37 'create page content',
38 'edit any page content',
40 $this->drupalLogin($user);
44 * Test node creation, refreshing/deleting feeds and feed items.
46 public
function test() {
47 // Set the teaser length display to unlimited otherwise tests looking for
48 // text on nodes will fail.
49 $edit['fields[body][type]'] = 'text_default';
50 $this->drupalPost('admin/structure/types/manage/article/display/teaser', $edit, 'Save');
52 // Create an importer configuration.
53 $this->createImporterConfiguration('Syndication', 'syndication');
54 $this->addMappings('syndication',
62 'source' => 'description',
67 'source' => 'timestamp',
68 'target' => 'created',
84 $nid = $this->createFeedNode();
86 // Assert 10 items aggregated after creation of the node.
87 $this->assertText('Created 10 Article 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 $article_nid = db_query_range("SELECT nid FROM {node} WHERE type = 'article'", 0, 1)->fetchField();
96 $this->drupalGet('node/'.
$article_nid);
97 $this->assertNoRaw('node/'.
$article_nid .
'/import');
98 $this->assertNoRaw('node/'.
$article_nid .
'/delete-items');
99 $this->assertEqual("Created/updated by FeedsNodeProcessor", db_query("SELECT nr.log FROM {node} n JOIN {node_revision} nr ON n.vid = nr.vid WHERE n.nid = :nid", array(':nid' => $article_nid))->fetchField());
101 // Assert accuracy of aggregated information.
102 $this->drupalGet('node');
103 $this->assertRaw('<span class="username">Anonymous (not verified)</span>');
104 $this->assertDevseedFeedContent();
107 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")->fetchField();
108 $this->assertEqual($count, 10, 'Accurate number of items in database.');
110 // Assert default input format on first imported feed node.
113 $format = db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revision} nr ON n.vid = nr.vid", 0, 1)->fetchField();
114 $this->assertEqual($format, filter_fallback_format(), 'Using default Input format.');
118 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
119 $this->assertText('There is no new content.');
121 // Assert DB status, there still shouldn't be more than 10 items.
122 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")->fetchField();
123 $this->assertEqual($count, 10, 'Accurate number of items in database.');
125 // All of the above tests should have produced published nodes, set default
126 // to unpublished, import again.
127 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 1")->fetchField();
128 $this->assertEqual($count, 10, 'All items are published.');
130 'node_options[status]' => FALSE
,
132 $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
133 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
134 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
135 $count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 0")->fetchField();
136 $this->assertEqual($count, 10, 'No items are published.');
138 'node_options[status]' => TRUE
,
140 $this->drupalPost('admin/structure/types/manage/article', $edit, t('Save content type'));
141 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
143 // Enable replace existing and import updated feed file.
144 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
145 $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1));
146 $feed_url = $GLOBALS['base_url'] .
'/'.
drupal_get_path('module', 'feeds') .
'/tests/feeds/developmentseed_changes.rss2';
147 $this->editFeedNode($nid, $feed_url);
148 $this->drupalPost('node/' .
$nid .
'/import', array(), 'Import');
149 $this->assertText('Updated 2 Article nodes.');
151 // Assert accuracy of aggregated content (check 2 updates, one original).
152 $this->drupalGet('node');
153 $this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
154 $this->assertText('Presenting on Features in Drupal and Managing News');
155 $this->assertText('Scaling the Open Atrium UI');
158 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
159 $this->assertText('There is no new content.');
161 // Assert DB status, there still shouldn't be more than 10 items.
162 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
163 $this->assertEqual($count, 10, 'Accurate number of items in database.');
165 // Now delete all items.
166 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
167 $this->assertText('Deleted 10 nodes.');
169 // Assert DB status, now there should be no items.
170 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
171 $this->assertEqual($count, 0, 'Accurate number of items in database.');
174 $author = $this->drupalCreateUser();
175 $this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $author->name
));
177 // Change input format.
178 $this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => filter_fallback_format() + 1));
181 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
182 $this->assertText('Created 10 Article nodes.');
185 $this->drupalGet('node');
186 $this->assertPattern('/<span class="username">' .
check_plain($author->name
) .
'<\/span>/');
187 $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();
188 $this->assertEqual($count, 10, 'Accurate number of items in database.');
190 // Assert input format.
193 $format = db_query_range("SELECT nr.format FROM {feeds_node_item} fi JOIN {node} n ON fi.nid = n.nid JOIN {node_revision} nr ON n.vid = nr.vid", 0, 1)->fetchField();
194 $this->assertEqual($format, filter_fallback_format() + 1, 'Set non-default Input format.');
197 // Set to update existing, remove authorship of above nodes and import again.
198 $this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 2));
199 db_query("UPDATE {node} n JOIN {feeds_node_item} fi ON n.nid = fi.nid SET n.uid = 0, fi.hash=''");
200 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
201 $this->drupalGet('node');
202 $this->assertNoPattern('/<span class="username">' .
check_plain($author->name
) .
'<\/span>/');
203 $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();
204 $this->assertEqual($count, 0, 'Accurate number of items in database.');
206 // Map feed node's author to feed item author, update - feed node's items
207 // should now be assigned to feed node author.
208 $this->addMappings('syndication',
211 'source' => 'parent:uid',
216 $this->drupalPost('node/'.
$nid .
'/import', array(), 'Import');
217 $this->drupalGet('node');
218 $this->assertNoPattern('/<span class="username">' .
check_plain($author->name
) .
'<\/span>/');
219 $uid = db_query("SELECT uid FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
220 $count = db_query("SELECT COUNT(*) FROM {node} WHERE uid = :uid", array(':uid' =>$uid))->fetchField();
221 $this->assertEqual($count, 11, 'All feed item nodes are assigned to feed node author.');
223 // Login with new user with only access content permissions.
225 $this->drupalCreateUser()
227 // Navigate to feed node, there should be no Feeds tabs visible.
228 $this->drupalGet('node/'.
$nid);
229 $this->assertNoRaw('node/'.
$nid .
'/import');
230 $this->assertNoRaw('node/'.
$nid .
'/delete-items');
232 // Now create a second feed configuration that is not attached to a content
233 // type and run tests on importing/purging.
235 // Login with sufficient permissions.
237 $this->drupalCreateUser(array('administer feeds', 'administer nodes'))
239 // Remove all items again so that next test can check for them.
240 $this->drupalPost('node/'.
$nid .
'/delete-items', array(), 'Delete');
242 // Create an importer, not attached to content type.
243 $this->createImporterConfiguration('Syndication standalone', 'syndication_standalone');
245 'content_type' => '',
247 $this->drupalPost('admin/structure/feeds/edit/syndication_standalone/settings', $edit, 'Save');
248 $this->addMappings('syndication_standalone',
256 'source' => 'description',
261 'source' => 'timestamp',
262 'target' => 'created',
278 // Import, assert 10 items aggregated after creation of the node.
279 $this->importURL('syndication_standalone');
280 $this->assertText('Created 10 Article nodes.');
282 // Assert accuracy of aggregated information.
283 $this->drupalGet('node');
284 $this->assertDevseedFeedContent();
287 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
288 $this->assertEqual($count, 10, 'Accurate number of items in database.');
291 $this->drupalPost('import/syndication_standalone', array(), 'Import');
292 $this->assertText('There is no new content.');
294 // Assert DB status, there still shouldn't be more than 10 items.
295 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
296 $this->assertEqual($count, 10, 'Accurate number of items in database.');
298 // Enable replace existing and import updated feed file.
299 $this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => 1));
300 $feed_url = $GLOBALS['base_url'] .
'/'.
drupal_get_path('module', 'feeds') .
'/tests/feeds/developmentseed_changes.rss2';
301 $this->importURL('syndication_standalone', $feed_url);
302 $this->assertText('Updated 2 Article nodes.');
304 // Assert accuracy of aggregated information (check 2 updates, one orig).
305 $this->drupalGet('node');
306 $this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
307 $this->assertText('Presenting on Features in Drupal and Managing News');
308 $this->assertText('Scaling the Open Atrium UI');
311 $this->drupalPost('import/syndication_standalone', array(), 'Import');
312 $this->assertText('There is no new content.');
314 // Assert DB status, there still shouldn't be more than 10 items.
315 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
316 $this->assertEqual($count, 10, 'Accurate number of items in database.');
318 // Now delete all items.
319 $this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
320 $this->assertText('Deleted 10 nodes.');
322 // Assert DB status, now there should be no items.
323 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
324 $this->assertEqual($count, 0, 'Accurate number of items in database.');
326 // Import again, we should find new content.
327 $this->drupalPost('import/syndication_standalone', array(), 'Import');
328 $this->assertText('Created 10 Article nodes.');
330 // Assert DB status, there should be 10 again.
331 $count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
332 $this->assertEqual($count, 10, 'Accurate number of items in database.');
334 // Login with new user with only access content permissions.
335 $this->drupalLogin($this->drupalCreateUser());
337 // Navigate to feed import form, access should be denied.
338 $this->drupalGet('import/syndication_standalone');
339 $this->assertResponse(403);
342 $this->drupalLogin($this->drupalCreateUser(array(
345 'create page content',
348 $this->setPlugin('syndication', 'FeedsFileFetcher');
349 // Create a feed node.
351 'files[feeds]' => $this->absolutePath() .
'/tests/feeds/drupalplanet.rss2',
353 $this->drupalPost('node/add/page', $edit, 'Save');
354 $this->assertText('has been created.');
355 $this->assertText('Created 25 Article nodes.');
359 * Check thet contents of the current page for the DS feed.
361 function assertDevseedFeedContent() {
362 $this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
363 $this->assertText('Tue, 10/06/2009');
364 $this->assertText('A new translation process for Open Atrium & integration with Localize Drupal');
365 $this->assertText('Week in DC Tech: October 5th Edition');
366 $this->assertText('Mon, 10/05/2009');
367 $this->assertText('There are some great technology events happening this week');
368 $this->assertText('Mapping Innovation at the World Bank with Open Atrium');
369 $this->assertText('Fri, 10/02/2009');
370 $this->assertText('is being used as a base platform for collaboration at the World Bank');
371 $this->assertText('September GeoDC Meetup Tonight');
372 $this->assertText('Wed, 09/30/2009');
373 $this->assertText('Today is the last Wednesday of the month');
374 $this->assertText('Week in DC Tech: September 28th Edition');
375 $this->assertText('Mon, 09/28/2009');
376 $this->assertText('Looking to geek out this week? There are a bunch of');
377 $this->assertText('Open Data for Microfinance: The New MIXMarket.org');
378 $this->assertText('Thu, 09/24/2009');
379 $this->assertText('There are profiles for every country that the MIX Market is hosting.');
380 $this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet');
381 $this->assertText('Tue, 09/22/2009');
382 $this->assertText('In addition to authentication, the Siteminder system');
383 $this->assertText('Week in DC Tech: September 21 Edition');
384 $this->assertText('Mon, 09/21/2009');
385 $this->assertText('an interesting variety of technology events happening in Washington, DC ');
386 $this->assertText('s Software Freedom Day: Impressions & Photos');
387 $this->assertText('Mon, 09/21/2009');
388 $this->assertText('Presenting on Features in Drupal and Open Atrium');
389 $this->assertText('Scaling the Open Atrium UI');
390 $this->assertText('Fri, 09/18/2009');
391 $this->assertText('The first major change is switching');