You are here

public function ProtectedNodeFieldCollection::testAllowedView in Protected Node 1.0.x

Same name and namespace in other branches
  1. 7 tests/protected_node.field_collection.test \ProtectedNodeFieldCollection::testAllowedView()

Test function.

Test that a file on a node protected with per node protection can be downloaded with the right password.

File

tests/protected_node.field_collection.test, line 88
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 testAllowedView() {

  // 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);
  $form = array(
    'password' => $password,
  );
  $this
    ->drupalPost('node/' . $creation_info['node']->nid, $form, t('OK'));

  // Ensure the file can be downloaded.
  $this
    ->drupalGet(file_create_url($creation_info['field_collection_item']->{$this->private_file_field_name}[LANGUAGE_NONE][0]['uri']));
  $this
    ->assertResponse(200, 'Confirmed that the generated URL is correct by downloading the shipped file.');
}