Newer
Older
<?php
// $Id$
/**
* @file
* Tests for plugins/FeedsNodeProcessor.inc.
*/
// Require FeedsWebTestCase class definition.
require_once(dirname(__FILE__) .'/feeds.test.inc');
/**
* Test aggregating a feed as node items.
*/
class FeedsRSStoNodesTest extends FeedsWebTestCase {
/**
* Describe this test.
*/
public function getInfo() {
return array(
'name' => t('RSS import to nodes'),
'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.'),
'group' => t('Feeds'),
);
}
/**
* Set up test.
*/
public function setUp() {
Alex Barth
committed
parent::setUp('feeds', 'feeds_ui', 'ctools', 'job_scheduler');
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
$this->drupalLogin(
$this->drupalCreateUser(
array(
'administer feeds', 'administer nodes', 'administer content types',
)
)
);
}
/**
* Test node creation, refreshing/deleting feeds and feed items.
*/
public function test() {
// Set the teaser length to unlimited otherwise tests looking for text on
// nodes will fail.
$edit = array(
'teaser_length' => 0,
);
$this->drupalPost('admin/content/node-settings', $edit, 'Save configuration');
// Create an importer configuration.
$this->createImporterConfiguration('Syndication', 'syndication');
$this->addMappings('syndication',
array(
array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
array(
'source' => 'description',
'target' => 'body',
'unique' => FALSE,
),
array(
'source' => 'timestamp',
'target' => 'created',
'unique' => FALSE,
),
array(
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
)
);
$nid = $this->createFeedNode();
// Assert 10 items aggregated after creation of the node.
$this->assertText('Created 10 Article nodes.');
// Navigate to feed node, there should be Feeds tabs visible.
$this->drupalGet('node/'. $nid);
$this->assertRaw('node/'. $nid .'/import');
$this->assertRaw('node/'. $nid .'/delete-items');
// Navigate to a non-feed node, there should be no Feeds tabs visible.
$article_nid = db_query_range("SELECT nid FROM {node} WHERE type = 'article'", 0, 1)->fetchField();
$this->drupalGet('node/'. $article_nid);
$this->assertNoRaw('node/'. $article_nid .'/import');
$this->assertNoRaw('node/'. $article_nid .'/delete-items');
$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' => $article_nid))->fetchField());
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Assert accuracy of aggregated information.
$this->drupalGet('node');
$this->assertPattern('/<span class="submitted">(.*?)Anonymous<\/span>/');
$this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
$this->assertText('Tue, 10/06/2009');
$this->assertText('A new translation process for Open Atrium & integration with Localize Drupal');
$this->assertText('Week in DC Tech: October 5th Edition');
$this->assertText('Mon, 10/05/2009');
$this->assertText('There are some great technology events happening this week');
$this->assertText('Mapping Innovation at the World Bank with Open Atrium');
$this->assertText('Fri, 10/02/2009');
$this->assertText('Open Atrium is being used as a base platform for collaboration');
$this->assertText('September GeoDC Meetup Tonight');
$this->assertText('Wed, 09/30/2009');
$this->assertText('Today is the last Wednesday of the month');
$this->assertText('Week in DC Tech: September 28th Edition');
$this->assertText('Mon, 09/28/2009');
$this->assertText('Looking to geek out this week? There are a bunch of');
$this->assertText('Open Data for Microfinance: The New MIXMarket.org');
$this->assertText('Thu, 09/24/2009');
$this->assertText('There are profiles for every country that the MIX Market is hosting.');
$this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet');
$this->assertText('Tue, 09/22/2009');
$this->assertText('In addition to authentication, the Siteminder system');
$this->assertText('Week in DC Tech: September 21 Edition');
$this->assertText('Mon, 09/21/2009');
$this->assertText('an interesting variety of technology events happening in Washington, DC ');
$this->assertText('s Software Freedom Day: Impressions & Photos');
$this->assertText('Mon, 09/21/2009');
$this->assertText('Presenting on Features in Drupal and Open Atrium');
$this->assertText('Scaling the Open Atrium UI');
$this->assertText('Fri, 09/18/2009');
$this->assertText('The first major change is switching');
// Assert DB status.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Assert default input format on first imported feed node.
$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();
$this->assertEqual($format, filter_fallback_format(), 'Using default Input format.');
// Import again.
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->assertText('There is no new content.');
// Assert DB status, there still shouldn't be more than 10 items.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// All of the above tests should have produced published nodes, set default
// to unpublished, import again.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 1")->fetchField();
$this->assertEqual($count, 10, 'All items are published.');
$edit = array(
'node_options[status]' => FALSE,
);
$this->drupalPost('admin/content/node-type/article', $edit, t('Save content type'));
$this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE n.status = 0")->fetchField();
$this->assertEqual($count, 10, 'No items are published.');
$edit = array(
'node_options[status]' => TRUE,
);
$this->drupalPost('admin/content/node-type/article', $edit, t('Save content type'));
$this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
// Enable replace existing and import updated feed file.
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 1));
$feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') .'/tests/feeds/developmentseed_changes.rss2';
$this->editFeedNode($nid, $feed_url);
$this->drupalPost('node/' . $nid . '/import', array(), 'Import');
$this->assertText('Updated 2 Article nodes.');
// Assert accuracy of aggregated content (check 2 updates, one original).
$this->drupalGet('node');
$this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
$this->assertText('Presenting on Features in Drupal and Managing News');
$this->assertText('Scaling the Open Atrium UI');
// Import again.
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->assertText('There is no new content.');
// Assert DB status, there still shouldn't be more than 10 items.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Now delete all items.
$this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
$this->assertText('Deleted 10 nodes.');
// Assert DB status, now there should be no items.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 0, 'Accurate number of items in database.');
// Change author.
$author = $this->drupalCreateUser();
$this->setSettings('syndication', 'FeedsNodeProcessor', array('author' => $author->name));
// Change input format.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('input_format' => filter_fallback_format() + 1));
// Import again.
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->assertText('Created 10 Article nodes.');
// Assert author.
$this->drupalGet('node');
$this->assertPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/');
$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();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Assert input format.
$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();
$this->assertEqual($format, filter_fallback_format() + 1, 'Set non-default Input format.');
// Set to update existing, remove authorship of above nodes and import again.
$this->setSettings('syndication', 'FeedsNodeProcessor', array('update_existing' => 2));
db_query("UPDATE {node} n JOIN {feeds_node_item} fi ON n.nid = fi.nid SET n.uid = 0, fi.hash=''");
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->drupalGet('node');
$this->assertNoPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/');
$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();
$this->assertEqual($count, 0, 'Accurate number of items in database.');
// Map feed node's author to feed item author, update - feed node's items
// should now be assigned to feed node author.
$this->addMappings('syndication',
array(
array(
'source' => 'parent:uid',
'target' => 'uid',
),
)
);
$this->drupalPost('node/'. $nid .'/import', array(), 'Import');
$this->drupalGet('node');
$this->assertNoPattern('/<span class="submitted">(.*?)'. check_plain($author->name) .'<\/span>/');
$uid = db_query("SELECT uid FROM {node} WHERE nid = :nid", array(':nid' => $nid))->fetchField();
$count = db_query("SELECT COUNT(*) FROM {node} WHERE uid = :uid", array(':uid' =>$uid))->fetchField();
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
$this->assertEqual($count, 11, 'All feed item nodes are assigned to feed node author.');
// Login with new user with only access content permissions.
$this->drupalLogin(
$this->drupalCreateUser()
);
// Navigate to feed node, there should be no Feeds tabs visible.
$this->drupalGet('node/'. $nid);
$this->assertNoRaw('node/'. $nid .'/import');
$this->assertNoRaw('node/'. $nid .'/delete-items');
// Now create a second feed configuration that is not attached to a content
// type and run tests on importing/purging.
// Login with sufficient permissions.
$this->drupalLogin(
$this->drupalCreateUser(array('administer feeds', 'administer nodes'))
);
// Remove all items again so that next test can check for them.
$this->drupalPost('node/'. $nid .'/delete-items', array(), 'Delete');
// Create an importer, not attached to content type.
$this->createImporterConfiguration('Syndication standalone', 'syndication_standalone');
$edit = array(
'content_type' => '',
);
$this->drupalPost('admin/structure/feeds/edit/syndication_standalone/settings', $edit, 'Save');
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
$this->addMappings('syndication_standalone',
array(
array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
array(
'source' => 'description',
'target' => 'body',
'unique' => FALSE,
),
array(
'source' => 'timestamp',
'target' => 'created',
'unique' => FALSE,
),
array(
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
array(
'source' => 'guid',
'target' => 'guid',
'unique' => TRUE,
),
)
);
// Import, assert 10 items aggregated after creation of the node.
$this->importURL('syndication_standalone');
$this->assertText('Created 10 Article nodes.');
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
// Assert accuracy of aggregated information.
$this->drupalGet('node');
$this->assertText('Open Atrium Translation Workflow: Two Way Translation Updates');
$this->assertText('Tue, 10/06/2009');
$this->assertText('A new translation process for Open Atrium & integration with Localize Drupal');
$this->assertText('Week in DC Tech: October 5th Edition');
$this->assertText('Mon, 10/05/2009');
$this->assertText('There are some great technology events happening this week');
$this->assertText('Mapping Innovation at the World Bank with Open Atrium');
$this->assertText('Fri, 10/02/2009');
$this->assertText('Open Atrium is being used as a base platform for collaboration');
$this->assertText('September GeoDC Meetup Tonight');
$this->assertText('Wed, 09/30/2009');
$this->assertText('Today is the last Wednesday of the month');
$this->assertText('Week in DC Tech: September 28th Edition');
$this->assertText('Mon, 09/28/2009');
$this->assertText('Looking to geek out this week? There are a bunch of');
$this->assertText('Open Data for Microfinance: The New MIXMarket.org');
$this->assertText('Thu, 09/24/2009');
$this->assertText('There are profiles for every country that the MIX Market is hosting.');
$this->assertText('Integrating the Siteminder Access System in an Open Atrium-based Intranet');
$this->assertText('Tue, 09/22/2009');
$this->assertText('In addition to authentication, the Siteminder system');
$this->assertText('Week in DC Tech: September 21 Edition');
$this->assertText('Mon, 09/21/2009');
$this->assertText('an interesting variety of technology events happening in Washington, DC ');
$this->assertText('s Software Freedom Day: Impressions & Photos');
$this->assertText('Mon, 09/21/2009');
$this->assertText('Presenting on Features in Drupal and Open Atrium');
$this->assertText('Scaling the Open Atrium UI');
$this->assertText('Fri, 09/18/2009');
$this->assertText('The first major change is switching');
// Assert DB status.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Import again.
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('There is no new content.');
// Assert DB status, there still shouldn't be more than 10 items.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Enable replace existing and import updated feed file.
$this->setSettings('syndication_standalone', 'FeedsNodeProcessor', array('update_existing' => 1));
$feed_url = $GLOBALS['base_url'] .'/'. drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_changes.rss2';
$this->importURL('syndication_standalone', $feed_url);
$this->assertText('Updated 2 Article nodes.');
// Assert accuracy of aggregated information (check 2 updates, one orig).
$this->drupalGet('node');
$this->assertText('Managing News Translation Workflow: Two Way Translation Updates');
$this->assertText('Presenting on Features in Drupal and Managing News');
$this->assertText('Scaling the Open Atrium UI');
// Import again.
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('There is no new content.');
// Assert DB status, there still shouldn't be more than 10 items.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Now delete all items.
$this->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this->assertText('Deleted 10 nodes.');
// Assert DB status, now there should be no items.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 0, 'Accurate number of items in database.');
// Import again, we should find new content.
$this->drupalPost('import/syndication_standalone', array(), 'Import');
$this->assertText('Created 10 Article nodes.');
// Assert DB status, there should be 10 again.
$count = db_query("SELECT COUNT(*) FROM {feeds_node_item}")->fetchField();
$this->assertEqual($count, 10, 'Accurate number of items in database.');
// Login with new user with only access content permissions.
$this->drupalLogin(
$this->drupalCreateUser()
);
// Navigate to feed import form, access should be denied.
$this->drupalGet('import/syndication_standalone');
$this->assertResponse(403);
// Use File Fetcher.
$this->drupalLogin(
$this->drupalCreateUser(array('administer feeds', 'administer nodes'))
);
$this->setPlugin('syndication', 'FeedsFileFetcher');
// Create a feed node.
$edit = array(
'files[feeds]' => $this->absolutePath() .'/tests/feeds/drupalplanet.rss2',
);
$this->drupalPost('node/add/page', $edit, 'Save');
$this->assertText('has been created.');
$this->assertText('Created 25 Article nodes.');