public function ProcessorWebTest::testAuthorize in Feeds Comment Processor 7
Tests authorization.
File
- src/
Tests/ ProcessorWebTest.php, line 100 - Contains \Drupal\feeds_comment_processor\Tests\ProcessorWebTest.
Class
- ProcessorWebTest
- Basic behavior tests for feeds_comment_processor.
Namespace
Drupal\feeds_comment_processor\TestsCode
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' => 'Poor user',
'mail' => 'poor@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('comment', array(
5 => array(
'source' => 'mail',
'target' => 'user_mail',
),
));
$url = $GLOBALS['base_url'] . '/' . drupal_get_path('module', 'feeds_comment_processor') . '/tests/test.csv';
$nid = $this
->createFeedNode('comment', $url, 'Comment test');
$this
->assertText('Failed importing 1 comment');
$this
->assertText('User ' . $account->name . ' is not permitted to post comments.');
$this
->assertEqual(0, db_query("SELECT COUNT(*) FROM {comment}")
->fetchField());
user_role_change_permissions(2, array(
'post comments' => TRUE,
));
$this
->drupalPost("node/{$nid}/import", array(), 'Import');
$this
->assertText('Created 1 comment.');
$this
->assertEqual(1, db_query("SELECT COUNT(*) FROM {comment}")
->fetchField());
$comment = comment_load(1);
$this
->assertEqual(0, $comment->status);
}