You are here

public function ProtectedNodeFork::testForkPageAccess in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x tests/protected_node.fork.test \ProtectedNodeFork::testForkPageAccess()

Test function.

Test that the fork feature password form is accessed only when the page has the good parameters.

File

tests/protected_node.fork.test, line 45
Test protected node fork functionality.

Class

ProtectedNodeFork
Configure protected_node to use per node password.

Code

public function testForkPageAccess() {

  // 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();
  $this
    ->drupalLogin($this->normalAccessAllowedUser);

  // Absence of protected_pages parameter.
  $this
    ->drupalGet('protected-nodes');
  $this
    ->assertResponse(403, "The protected-nodes page can't be accessed without the protected_pages parameter.");

  // Presence of protected_pages parameter and the first node does not exist.
  $this
    ->drupalGet('protected-nodes', array(
    'query' => array(
      'protected_pages' => '',
    ),
  ));
  $this
    ->assertResponse(403, "The protected-nodes page can't be accessed without a first valid nid in the protected_pages parameter.");

  // Absence of destination parameter.
  $this
    ->drupalGet('protected-nodes', array(
    'query' => array(
      'protected_pages' => $node->nid,
      'destination' => '',
    ),
  ));
  $this
    ->assertResponse(403, "The protected-nodes page can't be accessed if there is a destination parameter.");

  // Normal access.
  $form = array(
    'password' => $password,
  );
  $this
    ->drupalPost('protected-nodes', $form, t('OK'), array(
    'query' => array(
      'protected_pages' => $node->nid,
    ),
  ));
  $text = $node->body[LANGUAGE_NONE][0]['value'];
  $this
    ->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
}