public function FeedsRSStoNodesTest::test in Feeds 7.2
Same name and namespace in other branches
- 6 tests/feeds_processor_node.test \FeedsRSStoNodesTest::test()
- 7 tests/feeds_processor_node.test \FeedsRSStoNodesTest::test()
Test node creation, refreshing/deleting feeds and feed items.
File
- tests/
feeds_processor_node.test, line 72 - Tests for plugins/FeedsNodeProcessor.inc.
Class
- FeedsRSStoNodesTest
- Test aggregating a feed as node items.
Code
public function test() {
$nid = $this
->createFeedNode();
// Assert 10 items aggregated after creation of the node.
$this
->assertText('Created 10 nodes');
$article_nid = db_query_range("SELECT nid FROM {node} WHERE type = 'article'", 0, 1)
->fetchField();
$this
->assertEqual("Created 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());
// 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");
// Assert accuracy of aggregated information.
$this
->drupalGet('node');
$this
->assertRaw('<span class="username">Anonymous (not verified)</span>');
$this
->assertDevseedFeedContent();
// Assert DB status.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id")
->fetchField();
$this
->assertEqual($count, 10, 'Accurate number of items in database.');
// Assert default input format on first imported feed node.
// NEEDS update.
// $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();
// $this->assertEqual($format, filter_fallback_format(), 'Using default Input format.');
// Import again.
$this
->drupalPost("node/{$nid}/import", array(), 'Import');
$this
->assertText('There are no new nodes');
// Assert DB status, there still shouldn't be more than 10 items.
$count = db_query("SELECT COUNT(*) FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id")
->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_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE n.status = 1")
->fetchField();
$this
->assertEqual($count, 10, 'All items are published.');
$edit = array(
'node_options[status]' => FALSE,
);
$this
->drupalPost('admin/structure/types/manage/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_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id WHERE n.status = 0")
->fetchField();
$this
->assertEqual($count, 10, 'No items are published.');
$edit = array(
'node_options[status]' => TRUE,
);
$this
->drupalPost('admin/structure/types/manage/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 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 are no new nodes');
$this
->assertFeedItemCount(10);
// Now delete all items.
$this
->drupalPost("node/{$nid}/delete-items", array(), 'Delete');
$this
->assertText('Deleted 10 nodes');
$this
->assertFeedItemCount(0);
// Change author and turn off authorization.
$this->auth_user = $this
->drupalCreateUser(array(
'access content',
));
$this
->setSettings('syndication', 'FeedsNodeProcessor', array(
'author' => $this->auth_user->name,
'authorize' => FALSE,
));
// Change input format.
$this
->setSettings('syndication', 'FeedsNodeProcessor', array(
'input_format' => 'plain_text',
));
// Import again.
$this
->drupalPost("node/{$nid}/import", array(), 'Import');
$this
->assertText('Created 10 nodes');
// Assert author.
$this
->drupalGet('node');
$this
->assertPattern('/<span class="username">' . check_plain($this->auth_user->name) . '<\\/span>/');
$count = db_query("SELECT COUNT(*) FROM {feeds_item} fi JOIN {node} n ON fi.entity_type = 'node' AND fi.entity_id = n.nid WHERE n.uid = :uid", array(
':uid' => $this->auth_user->uid,
))
->fetchField();
$this
->assertEqual($count, 10, 'Accurate number of items in database.');
// Assert input format.
// NEEDS update.
// $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();
// $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,
));
$nids = db_query("SELECT nid FROM {node} n INNER JOIN {feeds_item} fi ON fi.entity_type = 'node' AND n.nid = fi.entity_id")
->fetchCol();
db_update('node')
->fields(array(
'uid' => 0,
))
->condition('nid', $nids, 'IN')
->execute();
db_update('feeds_item')
->fields(array(
'hash' => '',
))
->condition('entity_type', 'node')
->condition('entity_id', $nids, 'IN')
->execute();
$this
->drupalPost("node/{$nid}/import", array(), 'Import');
$this
->drupalGet('node');
$this
->assertNoPattern('/<span class="username">' . check_plain($this->auth_user->name) . '<\\/span>/');
$count = db_query("SELECT COUNT(*) FROM {feeds_item} fi JOIN {node} n ON fi.entity_type = 'node' AND fi.entity_id = n.nid WHERE n.uid = :uid", array(
':uid' => $this->auth_user->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(
5 => array(
'source' => 'parent:uid',
'target' => 'uid',
),
));
$this
->drupalPost("node/{$nid}/import", array(), 'Import');
$this
->drupalGet('node');
$this
->assertNoPattern('/<span class="username">' . check_plain($this->auth_user->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();
$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->auth_user);
// 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->admin_user);
// 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/syndication_standalone/settings', $edit, 'Save');
$this
->addMappings('syndication_standalone', array(
0 => array(
'source' => 'title',
'target' => 'title',
'unique' => FALSE,
),
1 => array(
'source' => 'description',
'target' => 'body',
),
2 => array(
'source' => 'timestamp',
'target' => 'created',
),
3 => array(
'source' => 'url',
'target' => 'url',
'unique' => TRUE,
),
4 => 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 nodes');
// Assert accuracy of aggregated information.
$this
->drupalGet('node');
$this
->assertDevseedFeedContent();
$this
->assertFeedItemCount(10);
// Import again.
$this
->drupalPost('import/syndication_standalone', array(), 'Import');
$this
->assertText('There are no new nodes');
$this
->assertFeedItemCount(10);
// 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 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 are no new nodes');
$this
->assertFeedItemCount(10);
// Now delete all items.
$this
->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this
->assertText('Deleted 10 nodes');
$this
->assertFeedItemCount(0);
// Import again, we should find new content.
$this
->drupalPost('import/syndication_standalone', array(), 'Import');
$this
->assertText('Created 10 nodes');
$this
->assertFeedItemCount(10);
// Enable unpublish missing nodes and import updated feed file.
$this
->setSettings('syndication_standalone', 'FeedsNodeProcessor', array(
'update_non_existent' => FEEDS_UNPUBLISH_NON_EXISTENT,
'update_existing' => FEEDS_REPLACE_EXISTING,
));
$missing_url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds') . '/tests/feeds/developmentseed_missing.rss2';
$this
->importURL('syndication_standalone', $missing_url);
$this
->assertText('Unpublished 1 node');
$this
->assertFeedItemCount(10);
// Import again to ensure the message that one node is unpublished doesn't
// reappear (since the node was already unpublished during the previous
// import).
$this
->drupalPost('import/syndication_standalone', array(), 'Import');
$this
->assertText('There are no new nodes');
$this
->assertFeedItemCount(10);
// Re-import the original feed to ensure the unpublished node is updated,
// even though the item is the same since the last time it was available in
// the feed. Fact is that the node was not available in the previous import
// and that should be seen as a change.
$this
->importURL('syndication_standalone', $feed_url);
$this
->assertText('Updated 1 node');
$this
->assertFeedItemCount(10);
// Now delete all items.
$this
->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this
->assertText('Deleted 10 nodes');
$this
->assertFeedItemCount(0);
// Import again, to reset node counts.
$this
->importURL('syndication_standalone', $feed_url);
$this
->assertText('Created 10 nodes');
$this
->assertFeedItemCount(10);
// Change settings to delete non-existent nodes from feed.
$this
->setSettings('syndication_standalone', 'FeedsNodeProcessor', array(
'update_non_existent' => 'delete',
));
$this
->importURL('syndication_standalone', $missing_url);
$this
->assertText('Removed 1 node');
$this
->assertFeedItemCount(9);
// Now delete all items.
$this
->drupalPost('import/syndication_standalone/delete-items', array(), 'Delete');
$this
->assertText('Deleted 9 nodes');
$this
->assertFeedItemCount(0);
// Login with new user with only access content permissions.
$this
->drupalLogin($this->auth_user);
// Navigate to feed import form, access should be denied.
$this
->drupalGet('import/syndication_standalone');
$this
->assertResponse(403);
// Use File Fetcher.
$this
->drupalLogin($this->admin_user);
$edit = array(
'plugin_key' => 'FeedsFileFetcher',
);
$this
->drupalPost('admin/structure/feeds/syndication_standalone/fetcher', $edit, 'Save');
$edit = array(
'allowed_extensions' => 'rss2',
);
$this
->drupalPost('admin/structure/feeds/syndication_standalone/settings/FeedsFileFetcher', $edit, 'Save');
// Create a feed node.
$edit = array(
'files[feeds]' => $this
->absolutePath() . '/tests/feeds/drupalplanet.rss2',
);
$this
->drupalPost('import/syndication_standalone', $edit, 'Import');
$this
->assertText('Created 25 nodes');
}