You are here

public function ProtectedNodePrivateFile::testBypassView in Protected Node 7

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

Test function.

Test that a file on a node protected with per node protection can be downloaded if the user has the "View protected content (bypass password)" permission.

File

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

  // 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();

  // A bypass password for view authenticated user sees the node.
  $this
    ->drupalLogin($this->bypassViewAccessAllowedUser);
  $this
    ->drupalGet('node/' . $node->nid);
  $text = $node->body[LANGUAGE_NONE][0]['value'];
  $this
    ->assertText($text, "User with the bypass password for view permission can access a protected node without password.", $this->group);

  // Ensure the file can be downloaded.
  $this
    ->drupalGet(file_create_url($node->private_file[LANGUAGE_NONE][0]['uri']));
  $text = 'Protected page -- Enter password';
  $this
    ->assertNoText($text, "User with the bypass password for view permission can access a protected node without password.", $this->group);
}