You are here

public function ProtectedNodePrivateFile::testAuthenticatedNonAllowedView in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x tests/protected_node.private_file.test \ProtectedNodePrivateFile::testAuthenticatedNonAllowedView()

Test function.

Test that a file on a node protected with per node protection can't be downloaded by an authenticated but not allowed user.

File

tests/protected_node.private_file.test, line 128
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 testAuthenticatedNonAllowedView() {

  // Log in as Admin.
  $this
    ->drupalLogin($this->adminUser);

  // Generate random password.
  $password = $this
    ->randomName(10);

  // Create a new page node.
  $node = $this
    ->createProtectedNode($password);

  // Once the node created logout the user.
  $this
    ->drupalLogout();

  // Ensure the file cannot be downloaded.
  $this
    ->drupalLogin($this->normalNonAccessAllowedUser);
  $this
    ->drupalGet(file_create_url($node->private_file[LANGUAGE_NONE][0]['uri']));
  $this
    ->assertResponse(403, 'Confirmed that access is denied for the file without access to the node.');
}