From 511720ad093a14c5ff8234f3e86147e5513798eb Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Mon, 6 Jul 2015 19:00:53 +0200
Subject: [PATCH] Issue #2277045 by Grimreaper: Add test for the "use global
 password" action.

---
 tests/protected_node.bulk.test | 68 +++++++++++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 17 deletions(-)

diff --git a/tests/protected_node.bulk.test b/tests/protected_node.bulk.test
index 9b30e34..7aeabf8 100644
--- a/tests/protected_node.bulk.test
+++ b/tests/protected_node.bulk.test
@@ -77,36 +77,35 @@ class ProtectedNodeBulkPassword extends ProtectedNodeBaseTestCase {
   /**
    * Test function.
    *
-   * Test that the password has to be entered after restoring protection.
+   * Test that the node password is erased after using global password.
    */
-  public function testRestoreProtection() {
+  public function testUseGlobalPassword() {
     // Log in as Admin.
     $this->drupalLogin($this->adminUser);
     // Generate random password.
     $password = $this->randomName(10);
     // Create a new page node.
     $node = $this->createByNodeProtectedNode($password);
-    // Remove protection.
-    $this->drupalPost('admin/config/content/protected_node', array(), t('Remove password protection from all nodes'));
+    // Use global password.
+    $this->drupalPost('admin/config/content/protected_node', array(), t('Use global password on ALL nodes'));
     // Once the node created logout the user.
     $this->drupalLogout();
 
-    // An authenticated user sees the node.
+    // An authenticated user can't see the node with the node password.
     $this->drupalLogin($this->normalAccessAllowedUser);
-    $this->drupalGet('node/' . $node->nid);
-    $text = $node->body[LANGUAGE_NONE][0]['value'];
-    $this->assertText($text, "User with right permission can access an unprotected node", $this->group);
+    $form = array('password' => $password);
+    $this->drupalPost('node/' . $node->nid, $form, t('OK'));
 
-    // Log in as Admin to clear sessions.
-    $this->drupalLogin($this->adminUser);
-    $this->drupalPost('admin/config/content/protected_node', array(), t('Protect nodes that already have a password'));
-    $this->drupalLogout();
+    $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 has to enter the password to see the node.
+    // An authenticated user can see the node with global password.
     $this->drupalLogin($this->normalAccessAllowedUser);
-    $this->drupalGet('node/' . $node->nid);
-    $text = 'Protected page -- Enter password';
-    $this->assertText($text, "User with right permission has to enter the password", $this->group);
+    $form = array('password' => $this->global_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 global password", $this->group);
   }
 
   /**
@@ -119,7 +118,7 @@ class ProtectedNodeBulkPassword extends ProtectedNodeBaseTestCase {
     // Log in as Admin.
     $this->drupalLogin($this->adminUser);
     // Create a new page node.
-    $node = $this->createProtectedNode();
+    $node = $this->createGlobalProtectedNode();
     // Once the node created logout the user.
     $this->drupalLogout();
 
@@ -143,6 +142,41 @@ class ProtectedNodeBulkPassword extends ProtectedNodeBaseTestCase {
   }
 
   /**
+   * Test function.
+   *
+   * Test that the password has to be entered after restoring protection.
+   */
+  public function testRestoreProtection() {
+    // Log in as Admin.
+    $this->drupalLogin($this->adminUser);
+    // Generate random password.
+    $password = $this->randomName(10);
+    // Create a new page node.
+    $node = $this->createByNodeProtectedNode($password);
+    // Remove protection.
+    $this->drupalPost('admin/config/content/protected_node', array(), t('Remove password protection from all nodes'));
+    // Once the node created logout the user.
+    $this->drupalLogout();
+
+    // An authenticated user sees the node.
+    $this->drupalLogin($this->normalAccessAllowedUser);
+    $this->drupalGet('node/' . $node->nid);
+    $text = $node->body[LANGUAGE_NONE][0]['value'];
+    $this->assertText($text, "User with right permission can access an unprotected node", $this->group);
+
+    // Log in as Admin to clear sessions.
+    $this->drupalLogin($this->adminUser);
+    $this->drupalPost('admin/config/content/protected_node', array(), t('Protect nodes that already have a password'));
+    $this->drupalLogout();
+
+    // An authenticated user has to enter the password to see the node.
+    $this->drupalLogin($this->normalAccessAllowedUser);
+    $this->drupalGet('node/' . $node->nid);
+    $text = 'Protected page -- Enter password';
+    $this->assertText($text, "User with right permission has to enter the password", $this->group);
+  }
+
+  /**
    * Helper method to create a protected node.
    *
    * Please make sure the user has the permission to create the node before
-- 
2.1.4

