From 4af94d14d425ea7a8024cd8a30f6247c3c98a865 Mon Sep 17 00:00:00 2001
From: Florent Torregrosa <florent.torregrosa@gmail.com>
Date: Sun, 8 Feb 2015 18:56:42 +0100
Subject: [PATCH] Issue #2277045: Add tests on protected node statistics.

---
 protected_node.info                  |    1 +
 tests/protected_node.statistics.test |  148 ++++++++++++++++++++++++++++++++++
 2 files changed, 149 insertions(+)
 create mode 100644 tests/protected_node.statistics.test

diff --git a/protected_node.info b/protected_node.info
index 6e8f171..6b0fb79 100644
--- a/protected_node.info
+++ b/protected_node.info
@@ -15,3 +15,4 @@ files[] = tests/protected_node.global.test
 files[] = tests/protected_node.mail_test.test
 files[] = tests/protected_node.private_file.test
 files[] = tests/protected_node.view_mode.test
+files[] = tests/protected_node.statistics.test
diff --git a/tests/protected_node.statistics.test b/tests/protected_node.statistics.test
new file mode 100644
index 0000000..f15c305
--- /dev/null
+++ b/tests/protected_node.statistics.test
@@ -0,0 +1,148 @@
+<?php
+
+/**
+ * @file
+ * Test protected node statistics overview.
+ */
+
+/**
+ * Test protected node statistics overview.
+ */
+class ProtectedNodeStatistics extends ProtectedNodeBaseTestCase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name'        => 'Protected node statistic overview',
+      'description' => "This tests statistics overview",
+      'group'       => 'Protected Node',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+    // Generate random password.
+    $this->global_password = $this->randomName(10);
+
+    // Log in an Admin.
+    $this->drupalLogin($this->adminUser);
+    // Submit the configuration form.
+    $protected_node_settings = array(
+      'protected_node_use_global_password'          => PROTECTED_NODE_PER_NODE_AND_GLOBAL_PASSWORD,
+      'protected_node_global_password_field[pass1]' => $this->global_password,
+      'protected_node_global_password_field[pass2]' => $this->global_password,
+    );
+    $this->drupalPost('admin/config/content/protected_node', $protected_node_settings, t('Save configuration'));
+  }
+
+  /**
+   * Test the total number of nodes.
+   */
+  public function testTotal() {
+    // Add a new page node.
+    $node_data = array(
+      'title'               => $this->randomName(8),
+      'body[und][0][value]' => $this->randomName(32),
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Go to the configuration page.
+    $this->drupalGet('admin/config/content/protected_node');
+    $this->assertRaw('<td>Total nodes</td><td style="text-align:right">1</td>', 'The total number of nodes is right.');
+  }
+
+  /**
+   * Test the total number of unprotected/protected nodes.
+   */
+  public function testUnprotectedProtected() {
+    // Add a new page node that is not protected.
+    $node_data = array(
+      'title'               => $this->randomName(8),
+      'body[und][0][value]' => $this->randomName(32),
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Add a new page node that is protected.
+    $node_data = array(
+      'title'                       => $this->randomName(8),
+      'body[und][0][value]'         => $this->randomName(32),
+      'protected_node_is_protected' => TRUE,
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Go to the configuration page.
+    $this->drupalGet('admin/config/content/protected_node');
+    $this->assertRaw('<td>Total nodes</td><td style="text-align:right">2</td>', 'The total number of nodes is right.');
+    $this->assertRaw('<td>Unprotected nodes</td><td style="text-align:right">1</td>', 'The total number of unprotected nodes is right.');
+    $this->assertRaw('<td>Protected nodes</td><td style="text-align:right">1</td>', 'The total number of protected nodes is right.');
+  }
+
+  /**
+   * Test the total number of showing/hiding title nodes.
+   */
+  public function testShowingHidingTitle() {
+    // Add a new page node that is protected showing title.
+    $node_data = array(
+      'title'                       => $this->randomName(8),
+      'body[und][0][value]'         => $this->randomName(32),
+      'protected_node_is_protected' => TRUE,
+      'protected_node_show_title'   => TRUE,
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Add a new page node that is protected not showing title.
+    $node_data = array(
+      'title'                       => $this->randomName(8),
+      'body[und][0][value]'         => $this->randomName(32),
+      'protected_node_is_protected' => TRUE,
+      'protected_node_show_title'   => FALSE,
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Go to the configuration page.
+    $this->drupalGet('admin/config/content/protected_node');
+    $this->assertRaw('<td>Total nodes</td><td style="text-align:right">2</td>', 'The total number of nodes is right.');
+    $this->assertRaw('<td>Unprotected nodes</td><td style="text-align:right">0</td>', 'The total number of unprotected nodes is right.');
+    $this->assertRaw('<td>Protected nodes</td><td style="text-align:right">2</td>', 'The total number of protected nodes is right.');
+    $this->assertRaw('<td>Showing title</td><td style="text-align:right">1</td>', 'The total number of protected nodes showing title is right.');
+    $this->assertRaw('<td>Hiding title</td><td style="text-align:right">1</td>', 'The total number of protected nodes hiding title is right.');
+  }
+
+  /**
+   * Test the total number of nodes protected by global/node passwords.
+   */
+  public function testGlobalNodePassword() {
+    // Add a new page node that is protected by the global password.
+    $node_data = array(
+      'title'                       => $this->randomName(8),
+      'body[und][0][value]'         => $this->randomName(32),
+      'protected_node_is_protected' => TRUE,
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Add a new page node that is protected by a node password.
+    $password = $this->randomName(8);
+    $node_data = array(
+      'title'                        => $this->randomName(8),
+      'body[und][0][value]'          => $this->randomName(32),
+      'protected_node_is_protected'  => TRUE,
+      'protected_node_passwd[pass1]' => $password,
+      'protected_node_passwd[pass2]' => $password,
+    );
+    $this->drupalPost('node/add/page', $node_data, t('Save'));
+
+    // Go to the configuration page.
+    $this->drupalGet('admin/config/content/protected_node');
+    $this->assertRaw('<td>Total nodes</td><td style="text-align:right">2</td>', 'The total number of nodes is right.');
+    $this->assertRaw('<td>Unprotected nodes</td><td style="text-align:right">0</td>', 'The total number of unprotected nodes is right.');
+    $this->assertRaw('<td>Protected nodes</td><td style="text-align:right">2</td>', 'The total number of protected nodes is right.');
+    $this->assertRaw('<td>Global passwords</td><td style="text-align:right">1</td>', 'The total number of nodes protected by a global password is right.');
+    $this->assertRaw('<td>Node passwords</td><td style="text-align:right">1</td>', 'The total number of nodes protected by a node password is right.');
+  }
+
+}
-- 
1.7.10.4

