public function ProtectedNodePrivateFile::testAuthenticatedMultipleNodesAllowedView in Protected Node 1.0.x
Same name and namespace in other branches
- 7 tests/protected_node.private_file.test \ProtectedNodePrivateFile::testAuthenticatedMultipleNodesAllowedView()
Test function.
Test that a file used on two protected nodes with per node protection can be downloaded if the user has access to one node.
See function testPrivateFile() from file.test.
File
- tests/
protected_node.private_file.test, line 152 - Test protected node behavior with private files.
Class
- ProtectedNodePrivateFile
- Configure protected_node to use per node password and use private file field.
Code
public function testAuthenticatedMultipleNodesAllowedView() {
// Log in as Admin.
$this
->drupalLogin($this->adminUser);
// Generate two random passwords.
$password1 = $this
->randomName(10);
$password2 = $this
->randomName(15);
// Create two new page nodes.
$node1 = $this
->createProtectedNode($password1);
$node2 = $this
->createProtectedNode($password2);
// Once the node created logout the user.
$this
->drupalLogout();
// Ensure the file cannot be downloaded.
$this
->drupalLogin($this->normalNonAccessAllowedUser);
$this
->drupalGet(file_create_url($node1->private_file[LANGUAGE_NONE][0]['uri']));
$this
->assertResponse(403, 'Confirmed that access is denied for the file without access to the node.');
// An authenticated user sees the first node.
$this
->drupalLogin($this->normalAccessAllowedUser);
$form = array(
'password' => $password1,
);
$this
->drupalPost('node/' . $node1->nid, $form, t('OK'));
$text = $node1->body[LANGUAGE_NONE][0]['value'];
$this
->assertText($text, "User with right permission can access a protected node with the right password", $this->group);
// An authenticated user can't see the second node.
$this
->drupalGet('node/' . $node2->nid);
$text = 'Protected page -- Enter password';
$this
->assertText($text, "User with right permission can't access a protected node without entering the password", $this->group);
// Ensure the file can be downloaded even if the user can't access the
// second node.
$this
->drupalGet(file_create_url($node2->private_file[LANGUAGE_NONE][0]['uri']));
$this
->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file on the second node.');
}