public function ProtectedNodeFork::testMatchingPassword in Protected Node 7
Same name and namespace in other branches
- 1.0.x tests/protected_node.fork.test \ProtectedNodeFork::testMatchingPassword()
Test function.
Test that the user is redirected to the node with the matching password.
File
- tests/
protected_node.fork.test, line 80 - Test protected node fork functionality.
Class
- ProtectedNodeFork
- Configure protected_node to use per node password.
Code
public function testMatchingPassword() {
// Log in as Admin.
$this
->drupalLogin($this->adminUser);
// Generate random passwords.
$password1 = $this
->randomName(10);
$password2 = $this
->randomName(15);
// Create two page nodes.
$node1 = $this
->createProtectedNode($password1);
$node2 = $this
->createProtectedNode($password2);
// Once the nodes created logout the user.
$this
->drupalLogout();
// Prepare protected_pages parameter.
$protected_pages = implode(',', array(
$node1->nid,
$node2->nid,
));
// Access to node1.
$this
->drupalLogin($this->normalAccessAllowedUser);
$form = array(
'password' => $password1,
);
$this
->drupalPost('protected-nodes', $form, t('OK'), array(
'query' => array(
'protected_pages' => $protected_pages,
),
));
$text = $node1->body[LANGUAGE_NONE][0]['value'];
$this
->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
// Log in as Admin to clear sessions.
$this
->drupalLogin($this->adminUser);
$this
->drupalPost('admin/config/content/protected_node', array(), t('Clear sessions'));
$this
->drupalLogout();
// Access to node2.
$this
->drupalLogin($this->normalAccessAllowedUser);
$form = array(
'password' => $password2,
);
$this
->drupalPost('protected-nodes', $form, t('OK'), array(
'query' => array(
'protected_pages' => $protected_pages,
),
));
$text = $node2->body[LANGUAGE_NONE][0]['value'];
$this
->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
}