public function ProtectedNodeRules::testPasswordProtect in Protected Node 7
Same name and namespace in other branches
- 1.0.x protected_node_rules/tests/protected_node_rules.test \ProtectedNodeRules::testPasswordProtect()
Test function.
Test that a rule can password protect a node.
File
- protected_node_rules/
tests/ protected_node_rules.test, line 65 - Test protected node rules functionality.
Class
- ProtectedNodeRules
- Test protected node rules functionality.
Code
public function testPasswordProtect() {
$password = $this
->randomName(10);
// Create a rule to password protect new node.
$rule = rules_reaction_rule();
$rule->label = t('Password protect page on presave.');
$rule
->event('node_presave')
->action('protected_node_rules_action_password_protect', array(
'node:select' => 'node',
'passwd' => $password,
'show_title' => 1,
));
$rule
->save();
// Create an unprotected basic page that will be protected by the rule.
$node = $this
->drupalCreateNode();
// User that can see published content shouldn't be able to get to the node.
$this
->drupalLogin($this->normalNonAccessAllowedUser);
$this
->drupalGet('node/' . $node->nid);
$this
->assertResponse(403, "User with no access permission is not allowed to access a protected node");
// User that can access protected node page tries to do so.
$this
->drupalLogin($this->normalAccessAllowedUser);
$form = array(
'password' => $password,
);
$this
->drupalPost('node/' . $node->nid, $form, t('OK'));
$text = $node->body[LANGUAGE_NONE][0]['value'];
$this
->assertText($text, "User with right permission can access a protected node with right password", $this->group);
}