From f7ac05a60734260a3f084895424032b142c2ef6f Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Mon, 6 Jul 2015 19:45:14 +0200
Subject: [PATCH] Issue #2277045 by Grimreaper: Add test for "reset passwords"
 action.

---
 tests/protected_node.bulk.test | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/tests/protected_node.bulk.test b/tests/protected_node.bulk.test
index 7aeabf8..5b8c07a 100644
--- a/tests/protected_node.bulk.test
+++ b/tests/protected_node.bulk.test
@@ -77,6 +77,45 @@ class ProtectedNodeBulkPassword extends ProtectedNodeBaseTestCase {
   /**
    * Test function.
    *
+   * Test that the node password is changed after using reset passwords.
+   */
+  public function testResetPasswords() {
+    // Log in as Admin.
+    $this->drupalLogin($this->adminUser);
+    // Generate random password.
+    $password = $this->randomName(10);
+    // Create a new page node.
+    $node = $this->createByNodeProtectedNode($password);
+    // Reset passwords.
+    $new_password = $this->randomName(15);
+    $form = array(
+      'protected_node_reset_passwords_password[pass1]' => $new_password,
+      'protected_node_reset_passwords_password[pass2]' => $new_password,
+    );
+    $this->drupalPost('admin/config/content/protected_node', $form, t('Reset all existing passwords'));
+    // Once the node created logout the user.
+    $this->drupalLogout();
+
+    // An authenticated user can't see the node with the original node password.
+    $this->drupalLogin($this->normalAccessAllowedUser);
+    $form = array('password' => $password);
+    $this->drupalPost('node/' . $node->nid, $form, t('OK'));
+
+    $text = $node->body[LANGUAGE_NONE][0]['value'];
+    $this->assertNoText($text, "User with right permission can't access a protected node with the node's password", $this->group);
+
+    // An authenticated user can see the node with the new password.
+    $this->drupalLogin($this->normalAccessAllowedUser);
+    $form = array('password' => $new_password);
+    $this->drupalPost('node/' . $node->nid, $form, t('OK'));
+
+    $text = $node->body[LANGUAGE_NONE][0]['value'];
+    $this->assertText($text, "User with right permission has to enter the new password", $this->group);
+  }
+
+  /**
+   * Test function.
+   *
    * Test that the node password is erased after using global password.
    */
   public function testUseGlobalPassword() {
-- 
2.1.4

