You are here

public function ProtectedNodePerNodePassword::testHash in Protected Node 7

Same name and namespace in other branches
  1. 1.0.x tests/protected_node.per_node.test \ProtectedNodePerNodePassword::testHash()

Test that the password is well hashed when stored.

File

tests/protected_node.per_node.test, line 42
Test protected node per node functionality.

Class

ProtectedNodePerNodePassword
Configure protected_node to use per node password.

Code

public function testHash() {

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

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

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

  // Check the stored pasword in database.
  $stored_node_password = db_select('protected_nodes')
    ->fields('protected_nodes', array(
    'protected_node_passwd',
  ))
    ->condition('nid', $node->nid)
    ->execute()
    ->fetchField();
  $hashed_node_password = hash('sha256', $password);
  $this
    ->assertEqual($stored_node_password, $hashed_node_password, "The node's password is stored hashed and the value correspond to the password.", $this->group);
}