public function FeedsRSStoNodesTest::testAuthorize in Feeds 7.2
Test that nodes will not be created if the user is unauthorized to create them.
File
- tests/
feeds_processor_node.test, line 459 - Tests for plugins/FeedsNodeProcessor.inc.
Class
- FeedsRSStoNodesTest
- Test aggregating a feed as node items.
Code
public function testAuthorize() {
// Create a user with limited permissions. We can't use
// $this->drupalCreateUser here because we need to to set a specific user
// name.
$edit = array(
'name' => 'Development Seed',
'mail' => 'devseed@example.com',
'pass' => user_password(),
'status' => 1,
);
$account = user_save(drupal_anonymous_user(), $edit);
// Adding a mapping to the user_name will invoke authorization.
$this
->addMappings('syndication', array(
5 => array(
'source' => 'author_name',
'target' => 'user_name',
),
));
$nid = $this
->createFeedNode();
$this
->assertText('Failed importing 10 nodes.');
$this
->assertText('The user ' . $account->name . ' is not authorized to create content of type article.');
$node_count = db_query("SELECT COUNT(*) FROM {node}")
->fetchField();
// We should have 1 node, the feed node.
$this
->assertEqual($node_count, 1, t('Correct number of nodes in the database.'));
// Give the user our admin powers.
$edit = array(
'roles' => $this->admin_user->roles,
);
$account = user_save($account, $edit);
$this
->drupalPost("node/{$nid}/import", array(), 'Import');
$this
->assertText('Created 10 nodes.');
$node_count = db_query("SELECT COUNT(*) FROM {node}")
->fetchField();
$this
->assertEqual($node_count, 11, t('Correct number of nodes in the database.'));
}