|
Line 0
Link Here
|
| 0 |
- |
1 |
package t::lib::Page::Members::Statistics; |
|
|
2 |
|
| 3 |
# Copyright 2015 Open Source Freedom Fighters |
| 4 |
# |
| 5 |
# This file is part of Koha. |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Scalar::Util qw(blessed); |
| 22 |
use Test::More; |
| 23 |
|
| 24 |
use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation); |
| 25 |
|
| 26 |
use t::lib::Page::Members::ApiKeys; |
| 27 |
|
| 28 |
use Koha::Exception::BadParameter; |
| 29 |
|
| 30 |
=head NAME t::lib::Page::Members::Statistics |
| 31 |
|
| 32 |
=head SYNOPSIS |
| 33 |
|
| 34 |
statistics.pl PageObject providing page functionality as a service! |
| 35 |
|
| 36 |
=cut |
| 37 |
|
| 38 |
=head new |
| 39 |
|
| 40 |
my $statistics = t::lib::Page::Members::Statistics->new({borrowernumber => "1"}); |
| 41 |
|
| 42 |
Instantiates a WebDriver and loads the members/statistics.pl. |
| 43 |
@PARAM1 HASHRef of optional and MANDATORY parameters |
| 44 |
MANDATORY extra parameters: |
| 45 |
borrowernumber => loads the page to display Borrower matching the given borrowernumber |
| 46 |
|
| 47 |
@RETURNS t::lib::Page::Members::Statistics, ready for user actions! Remember to login first. |
| 48 |
=cut |
| 49 |
|
| 50 |
sub new { |
| 51 |
my ($class, $params) = @_; |
| 52 |
unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { |
| 53 |
$params = {}; |
| 54 |
} |
| 55 |
$params->{resource} = '/cgi-bin/koha/members/statistics.pl'; |
| 56 |
$params->{type} = 'staff'; |
| 57 |
|
| 58 |
$params->{getParams} = []; |
| 59 |
#Handle MANDATORY parameters |
| 60 |
if ($params->{borrowernumber}) { |
| 61 |
push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber}; |
| 62 |
} |
| 63 |
else { |
| 64 |
Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing."); |
| 65 |
} |
| 66 |
|
| 67 |
my $self = $class->SUPER::new($params); |
| 68 |
|
| 69 |
return $self; |
| 70 |
} |
| 71 |
|
| 72 |
################################################################################ |
| 73 |
=head UI Mapping helper subroutines |
| 74 |
See. Selenium documentation best practices for UI element mapping to common language descriptions. |
| 75 |
=cut |
| 76 |
################################################################################ |
| 77 |
|
| 78 |
sub _getStatisticsTableElements { |
| 79 |
my ($self) = @_; |
| 80 |
my $d = $self->getDriver(); |
| 81 |
|
| 82 |
my $e = {}; |
| 83 |
$e->{messages} = $d->find_elements("div.dialog, div.message, div.warning", 'css'); |
| 84 |
eval { |
| 85 |
$e->{table} = $d->find_element("#statistics", 'css'); |
| 86 |
$e->{tableTitle} = $d->find_element("#statistics thead tr", 'css'); |
| 87 |
$e->{tableRows} = $d->find_elements("#statistics tbody tr", 'css'); |
| 88 |
}; |
| 89 |
if ($@) { |
| 90 |
if (ref($e->{messages}) eq 'ARRAY' && scalar(@{$e->{messages}})) { |
| 91 |
#We got a message, probably meaning that there was nothing to show for this |
| 92 |
#Borrower, hence we don't get no #statistics-table |
| 93 |
} |
| 94 |
else { |
| 95 |
die __PACKAGE__."->_getStatisticsTableElements():> Error:\n$@\n"; |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
return $e; |
| 100 |
} |
| 101 |
|
| 102 |
################################################################################ |
| 103 |
=head PageObject Services |
| 104 |
|
| 105 |
=cut |
| 106 |
################################################################################ |
| 107 |
|
| 108 |
sub isStatisticsRows { |
| 109 |
my ($self, $rows) = @_; |
| 110 |
my $d = $self->getDriver(); |
| 111 |
$self->debugTakeSessionSnapshot(); |
| 112 |
|
| 113 |
unless (ref($rows) eq 'ARRAY') { |
| 114 |
Koha::Exception::BadParameter->throw(error => |
| 115 |
__PACKAGE__."->isStatisticsRows():> You must give an ARRAYRef as parameter.". |
| 116 |
"Empty ARRAYRef means there should be no statistics rows for the Borrower ". |
| 117 |
"and we should get the notification 'There are no statistics for this patron.'.". |
| 118 |
"Otherwise we search for the given rows from the shown #statistics-table."); |
| 119 |
} |
| 120 |
|
| 121 |
my $e = $self->_getStatisticsTableElements(); |
| 122 |
|
| 123 |
if (scalar(@$rows) == 0) { |
| 124 |
my $noStatisticsFound = 0; |
| 125 |
if (ref($e->{messages}) eq 'ARRAY') { |
| 126 |
foreach my $msg (@{$e->{messages}}) { |
| 127 |
$noStatisticsFound = 1 if $msg->get_text() =~ /There are no statistics for this patron/; |
| 128 |
} |
| 129 |
} |
| 130 |
ok($noStatisticsFound, "Intra Statistics, no statistics found"); |
| 131 |
return $self; |
| 132 |
} |
| 133 |
|
| 134 |
ok(ref($e->{tableRows}) eq 'ARRAY' && |
| 135 |
scalar(@{$e->{tableRows}}) > 0 && |
| 136 |
scalar(@$rows) <= scalar(@{$e->{tableRows}}), |
| 137 |
"Intra Statistics, expecting atleast '".scalar(@$rows)."' rows."); |
| 138 |
|
| 139 |
return $self; |
| 140 |
} |
| 141 |
|
| 142 |
1; #Make the compiler happy! |