From 43b63520311020904e8e5e6616d30e35ee89eef6 Mon Sep 17 00:00:00 2001
From: Mark Tompsett <mtompset@hotmail.com>
Date: Thu, 23 Jun 2016 21:08:00 -0400
Subject: [PATCH] Bug 3311: Testing Cases

There was no form of testing for the page. In order to test
the perl-side of the changes, I just went to a variety of
URLs to see if it will blow up.

TEST PLAN
---------
1) Apply this patch
2) At the bash prompt, export KOHA_INTRANET_URL=http://localhost:8080/
   -- Or whatever yours is. With or without the trailing /
3) prove -v t/db_dependent/www/catalogue_stats.t
   -- before applying the other patch, there should be failures.
4) Apply both patches
5) prove -v t/db_dependent/www/catalogue_stats.t
   -- there should be no failures now.
6) run koha qa test tools
---
 t/db_dependent/www/catalogue_stats.t | 109 +++++++++++++++++++++++++++++++++++
 1 file changed, 109 insertions(+)
 create mode 100644 t/db_dependent/www/catalogue_stats.t

diff --git a/t/db_dependent/www/catalogue_stats.t b/t/db_dependent/www/catalogue_stats.t
new file mode 100644
index 0000000..0540c88
--- /dev/null
+++ b/t/db_dependent/www/catalogue_stats.t
@@ -0,0 +1,109 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Copyright (C) 2016  Mark Tompsett
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More;
+use Test::WWW::Mechanize;
+use XML::Simple;
+
+my $koha_conf = $ENV{KOHA_CONF};
+my $xml       = XMLin($koha_conf);
+
+my $user     = $ENV{KOHA_USER} || $xml->{config}->{user};
+my $password = $ENV{KOHA_PASS} || $xml->{config}->{pass};
+my $intranet = $ENV{KOHA_INTRANET_URL};
+
+# test KOHA_INTRANET_URL is set
+if ( not defined $intranet ) {
+    plan skip_all =>
+      "Tests skip. You must set env. variable KOHA_INTRANET_URL to do tests\n";
+}
+
+$intranet =~ s/\/$//xsm;
+
+test_row_column_selection();
+
+done_testing();
+
+sub test_row_column_selection {
+
+    my $agent = Test::WWW::Mechanize->new( autocheck => 1 );
+
+    $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl",
+        'connect to intranet' );
+    $agent->form_name('loginform');
+    $agent->field( 'password', $password );
+    $agent->field( 'userid',   $user );
+    $agent->field( 'branch',   q{} );
+    $agent->click_ok( q{}, 'login to staff client' );
+
+    $agent->get_ok( "$intranet/cgi-bin/koha/mainpage.pl", 'load main page' );
+
+    $agent->follow_link_ok( { url_regex => qr/reports-home/xsmi },
+        'open reports module' );
+    $agent->follow_link_ok( { url_regex => qr/catalogue_stats/xsmi },
+        'go to Catalog statistics' );
+
+    my $base_url = $agent->uri();
+    note "Base URL: $base_url\n";
+    my @test_urls = (
+        '?Column=&Line=',
+        '?Column=test&Line=',
+        '?Column=items.itype&Line=',
+        '?Column=&Line=&do_it=1',
+        '?Column=test&Line=&do_it=1',
+        '?Column=items.itype&Line=&do_it=1',
+        '?Column=&Line=test',
+        '?Column=test&Line=test',
+        '?Column=items.itype&Line=test',
+        '?Column=&Line=test&do_it=1',
+        '?Column=test&Line=test&do_it=1',
+        '?Column=items.itype&Line=test&do_it=1',
+        '?Column=&Line=publishercode',
+        '?Column=test&Line=publishercode',
+        '?Column=items.itype&Line=publishercode',
+        '?Column=&Line=publishercode&do_it=1',
+        '?Column=test&Line=publishercode&do_it=1',
+        '?Column=items.itype&Line=publishercode&do_it=1',
+        '?Line=',
+        '?Line=&do_it=1',
+        '?Line=test',
+        '?Line=test&do_it=1',
+        '?Line=publishercode',
+        '?Line=publishercode&do_it=1',
+        '?Column=',
+        '?Column=&do_it=1',
+        '?Column=test',
+        '?Column=test&do_it=1',
+        '?Column=publishercode',
+        '?Column=publishercode&do_it=1',
+        q{?},
+        '?do_it=1',
+    );
+
+    foreach my $test_url (@test_urls) {
+        my $current_url = $base_url . q{/} . $test_url;
+        $agent->get_ok( $current_url, 'Checking ' . $test_url );
+    }
+
+    return;
+}
+
+1;
-- 
1.9.1