public function ProtectedNodeFieldCollection::testAllowedViewWrongPassword in Protected Node 1.0.x
Same name and namespace in other branches
- 7 tests/protected_node.field_collection.test \ProtectedNodeFieldCollection::testAllowedViewWrongPassword()
Test function.
Test that a file on a node protected with per node protection can't be downloaded with the wrong password.
File
- tests/
protected_node.field_collection.test, line 114 - Test protected node behavior with field collection private files.
Class
- ProtectedNodeFieldCollection
- Configure protected_node to use per node password and use private file field.
Code
public function testAllowedViewWrongPassword() {
// Log in as Admin.
$this
->drupalLogin($this->adminUser);
// Generate random password.
$password = $this
->randomName(10);
// Create a new page node.
$creation_info = $this
->createProtectedNodeWithFieldCollection($password);
// Once the node created logout the user.
$this
->drupalLogout();
// An authenticated user sees the node.
$this
->drupalLogin($this->normalAccessAllowedUser);
$another_password = $this
->randomName(12);
$form = array(
'password' => $another_password,
);
$this
->drupalPost('node/' . $creation_info['node']->nid, $form, t('OK'));
// Ensure the file cannot be downloaded.
$file_uri = $creation_info['field_collection_item']->{$this->private_file_field_name}[LANGUAGE_NONE][0]['uri'];
$file_url = file_create_url($file_uri);
$file_text = file_get_contents(drupal_realpath($file_uri));
$this
->drupalGet($file_url);
$this
->assertNoText($file_text, 'Confirmed that access is denied for the file without access to the node.', $this->group);
}