From 15a6529dab555f4b3896fec246cf2db9f52f1444 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Mon, 31 Aug 2015 16:03:11 +0300 Subject: [PATCH] Bug 14536 - PageObject squashable --- t/lib/Page/Members/Statistics.pm | 142 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 t/lib/Page/Members/Statistics.pm diff --git a/t/lib/Page/Members/Statistics.pm b/t/lib/Page/Members/Statistics.pm new file mode 100644 index 0000000..6265cea --- /dev/null +++ b/t/lib/Page/Members/Statistics.pm @@ -0,0 +1,142 @@ +package t::lib::Page::Members::Statistics; + +# Copyright 2015 Open Source Freedom Fighters +# +# This file is part of Koha. +# +# 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 . + +use Modern::Perl; +use Scalar::Util qw(blessed); +use Test::More; + +use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation); + +use t::lib::Page::Members::ApiKeys; + +use Koha::Exception::BadParameter; + +=head NAME t::lib::Page::Members::Statistics + +=head SYNOPSIS + +statistics.pl PageObject providing page functionality as a service! + +=cut + +=head new + + my $statistics = t::lib::Page::Members::Statistics->new({borrowernumber => "1"}); + +Instantiates a WebDriver and loads the members/statistics.pl. +@PARAM1 HASHRef of optional and MANDATORY parameters +MANDATORY extra parameters: + borrowernumber => loads the page to display Borrower matching the given borrowernumber + +@RETURNS t::lib::Page::Members::Statistics, ready for user actions! Remember to login first. +=cut + +sub new { + my ($class, $params) = @_; + unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { + $params = {}; + } + $params->{resource} = '/cgi-bin/koha/members/statistics.pl'; + $params->{type} = 'staff'; + + $params->{getParams} = []; + #Handle MANDATORY parameters + if ($params->{borrowernumber}) { + push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber}; + } + else { + Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing."); + } + + my $self = $class->SUPER::new($params); + + return $self; +} + +################################################################################ +=head UI Mapping helper subroutines +See. Selenium documentation best practices for UI element mapping to common language descriptions. +=cut +################################################################################ + +sub _getStatisticsTableElements { + my ($self) = @_; + my $d = $self->getDriver(); + + my $e = {}; + $e->{messages} = $d->find_elements("div.dialog, div.message, div.warning", 'css'); + eval { + $e->{table} = $d->find_element("#statistics", 'css'); + $e->{tableTitle} = $d->find_element("#statistics thead tr", 'css'); + $e->{tableRows} = $d->find_elements("#statistics tbody tr", 'css'); + }; + if ($@) { + if (ref($e->{messages}) eq 'ARRAY' && scalar(@{$e->{messages}})) { + #We got a message, probably meaning that there was nothing to show for this + #Borrower, hence we don't get no #statistics-table + } + else { + die __PACKAGE__."->_getStatisticsTableElements():> Error:\n$@\n"; + } + } + + return $e; +} + +################################################################################ +=head PageObject Services + +=cut +################################################################################ + +sub isStatisticsRows { + my ($self, $rows) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + unless (ref($rows) eq 'ARRAY') { + Koha::Exception::BadParameter->throw(error => + __PACKAGE__."->isStatisticsRows():> You must give an ARRAYRef as parameter.". + "Empty ARRAYRef means there should be no statistics rows for the Borrower ". + "and we should get the notification 'There are no statistics for this patron.'.". + "Otherwise we search for the given rows from the shown #statistics-table."); + } + + my $e = $self->_getStatisticsTableElements(); + + if (scalar(@$rows) == 0) { + my $noStatisticsFound = 0; + if (ref($e->{messages}) eq 'ARRAY') { + foreach my $msg (@{$e->{messages}}) { + $noStatisticsFound = 1 if $msg->get_text() =~ /There are no statistics for this patron/; + } + } + ok($noStatisticsFound, "Intra Statistics, no statistics found"); + return $self; + } + + ok(ref($e->{tableRows}) eq 'ARRAY' && + scalar(@{$e->{tableRows}}) > 0 && + scalar(@$rows) <= scalar(@{$e->{tableRows}}), + "Intra Statistics, expecting atleast '".scalar(@$rows)."' rows."); + + return $self; +} + +1; #Make the compiler happy! -- 1.9.1