From 3c28ec71a7cf3b02c892269554bbb56399bac023 Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Thu, 14 May 2015 14:17:58 +0200
Subject: [PATCH] Debugging testbot.

---
 tests/protected_node.fork.test | 112 +++++++++++++++++++++--------------------
 1 file changed, 58 insertions(+), 54 deletions(-)

diff --git a/tests/protected_node.fork.test b/tests/protected_node.fork.test
index 6aded83..d5a5804 100644
--- a/tests/protected_node.fork.test
+++ b/tests/protected_node.fork.test
@@ -42,42 +42,41 @@ class ProtectedNodeFork extends ProtectedNodeBaseTestCase {
    * Test that the fork feature password form is accessed only when the page has
    * the good parameters.
    */
-  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['und'][0]['value'];
-    $this->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
-  }
+//  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['und'][0]['value'];
+//    $this->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
+//  }
 
   /**
    * Test function.
    *
    * Test that the user is redirected to the node with the matching password.
    */
-  /**
   public function testMatchingPassword() {
     // Log in as Admin.
     $this->drupalLogin($this->adminUser);
@@ -91,7 +90,7 @@ class ProtectedNodeFork extends ProtectedNodeBaseTestCase {
     $this->drupalLogout();
 
     // Prepare protected_pages parameter.
-    $protected_pages = implode(',', array($node1->nid, $node2->nid));
+    $protected_pages = implode(',', array($node2->nid, $node1->nid));
 
     // Access to node1.
     $this->drupalLogin($this->normalAccessAllowedUser);
@@ -109,10 +108,15 @@ class ProtectedNodeFork extends ProtectedNodeBaseTestCase {
     $this->drupalLogin($this->normalAccessAllowedUser);
     $form = array('password' => $password2);
     $this->drupalPost('protected-nodes', $form, t('OK'), array('query' => array('protected_pages' => $protected_pages)));
+    $title = $node2->title;
     $text = $node2->body['und'][0]['value'];
-    $this->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
+    $page_title = $this->xpath("//h1[@class=:class and @id=:id]", array(':class' => 'title', ':id' => 'page-title'));
+    $page_title = $page_title[0]->__toString();
+    $page_title = trim($page_title);
+
+    $this->assertEqual($title, $page_title, "Node title: $title. Xpath found title: $page_title.", $this->group);
+    $this->assertText('Incorrect password!', "the user has entered the wrong password", $this->group);
   }
-   */
 
   /**
    * Test function.
@@ -120,27 +124,27 @@ class ProtectedNodeFork extends ProtectedNodeBaseTestCase {
    * Test that the user it redirected to the node he/she has already entered the
    * password.
    */
-  public function testAlreadyEnteredPassword() {
-    // Log in as Admin.
-    $this->drupalLogin($this->adminUser);
-    // Generate random passwords.
-    $password = $this->randomName(10);
-    // Create a new page nodes.
-    $node = $this->createProtectedNode($password);
-    // Once the nodes created logout the user.
-    $this->drupalLogout();
-
-    $this->drupalLogin($this->normalAccessAllowedUser);
-    // Access to the node the first time.
-    $form = array('password' => $password);
-    $this->drupalPost('protected-nodes', $form, t('OK'), array('query' => array('protected_pages' => $node->nid)));
-    $text = $node->body['und'][0]['value'];
-    $this->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
-
-    // Access to the node the second time.
-    $this->drupalGet('protected-nodes', array('query' => array('protected_pages' => $node->nid)));
-    $this->assertText($text, "User with right permission is redirected to a protected node with right password previously entered", $this->group);
-  }
+//  public function testAlreadyEnteredPassword() {
+//    // Log in as Admin.
+//    $this->drupalLogin($this->adminUser);
+//    // Generate random passwords.
+//    $password = $this->randomName(10);
+//    // Create a new page nodes.
+//    $node = $this->createProtectedNode($password);
+//    // Once the nodes created logout the user.
+//    $this->drupalLogout();
+//
+//    $this->drupalLogin($this->normalAccessAllowedUser);
+//    // Access to the node the first time.
+//    $form = array('password' => $password);
+//    $this->drupalPost('protected-nodes', $form, t('OK'), array('query' => array('protected_pages' => $node->nid)));
+//    $text = $node->body['und'][0]['value'];
+//    $this->assertText($text, "User with right permission is redirected to a protected node with right password", $this->group);
+//
+//    // Access to the node the second time.
+//    $this->drupalGet('protected-nodes', array('query' => array('protected_pages' => $node->nid)));
+//    $this->assertText($text, "User with right permission is redirected to a protected node with right password previously entered", $this->group);
+//  }
 
   /**
    * Helper method to create a protected node.
-- 
2.1.4

