From 8bf350ebf1121e3192ccad1ce811ef11fb13a961 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Mon, 17 Aug 2015 10:30:20 +0300 Subject: [PATCH] Bug 14536 - (follow-up) Add OpacMessaging, Circulation and LeftNavigation for Members/Circulation pages in Staff Client --- t/lib/Page/Circulation/Circulation.pm | 76 ++++++++++++++++++++++ t/lib/Page/Members/LeftNavigation.pm | 116 ++++++++++++++++++++++++++++++++++ t/lib/Page/Opac/OpacMessaging.pm | 101 +++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+) create mode 100644 t/lib/Page/Circulation/Circulation.pm create mode 100644 t/lib/Page/Members/LeftNavigation.pm create mode 100644 t/lib/Page/Opac/OpacMessaging.pm diff --git a/t/lib/Page/Circulation/Circulation.pm b/t/lib/Page/Circulation/Circulation.pm new file mode 100644 index 0000000..a651a66 --- /dev/null +++ b/t/lib/Page/Circulation/Circulation.pm @@ -0,0 +1,76 @@ +package t::lib::Page::Circulation::Circulation; + +# 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 Koha::Exception::BadParameter; + +=head NAME t::lib::Page::Circulation::Circulation + +=head SYNOPSIS + +circulation.pl PageObject providing page functionality as a service! + +=cut + +=head new + + my $circulation = t::lib::Page::Circulation::Circulation->new({borrowernumber => "1"}); + +Instantiates a WebDriver and loads the circ/circulation.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::Circulation::Circulation, ready for user actions! +=cut + +sub new { + my ($class, $params) = @_; + unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { + $params = {}; + } + $params->{resource} = '/cgi-bin/koha/circ/circulation.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 +################################################################################ + +1; \ No newline at end of file diff --git a/t/lib/Page/Members/LeftNavigation.pm b/t/lib/Page/Members/LeftNavigation.pm new file mode 100644 index 0000000..d9f2405 --- /dev/null +++ b/t/lib/Page/Members/LeftNavigation.pm @@ -0,0 +1,116 @@ +package t::lib::Page::Members::LeftNavigation; + +# 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; + +=head NAME t::lib::Page::Members::LeftNavigation + +=head SYNOPSIS + +Provides the services of the members/circulation left navigation column/frame for the implementing PageObject + +=cut + +################################################################################ +=head UI Mapping helper subroutines +See. Selenium documentation best practices for UI element mapping to common language descriptions. +=cut +################################################################################ + +=head _getLeftNavigationActionElements +@RETURNS HASHRef of Selenium::Driver::Webelements matching all the clickable elements + in the left navigation frame/column at members and circulation pages. +=cut + +sub _getLeftNavigationActionElements { + my ($self) = @_; + my $d = $self->getDriver(); + + my $e = {}; + eval { + $e->{checkOut} = $d->find_element("div#menu a[href*='circ/circulation.pl']", 'css'); + }; + eval { + $e->{details} = $d->find_element("div#menu a[href*='members/moremember.pl']", 'css'); + }; + eval { + $e->{fines} = $d->find_element("div#menu a[href*='members/pay.pl']", 'css'); + }; + eval { + $e->{routingLists} = $d->find_element("div#menu a[href*='members/routing-lists.pl']", 'css'); + }; + eval { + $e->{circulationHistory} = $d->find_element("div#menu a[href*='members/readingrec.pl']", 'css'); + }; + eval { + $e->{modificationLog} = $d->find_element("div#menu a[href*='tools/viewlog.pl']", 'css'); + }; + eval { + $e->{notices} = $d->find_element("div#menu a[href*='members/notices.pl']", 'css'); + }; + eval { + $e->{statistics} = $d->find_element("div#menu a[href*='members/statistics.pl']", 'css'); + }; + eval { + $e->{purchaseSuggestions} = $d->find_element("div#menu a[href*='members/purchase-suggestions.pl']", 'css'); + }; + return $e; +} + + + +################################################################################ +=head PageObject Services + +=cut +################################################################################ + +sub navigateCheckout { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getLeftNavigationActionElements(); + $elements->{checkOut}->click(); + $self->debugTakeSessionSnapshot(); + + ok($d->get_title() =~ m/Checking out to/i, + "Intra Navigate to Check out"); + + return t::lib::Page::Circulation::Circulation->rebrandFromPageObject($self); +} + +sub navigateToDetails { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getLeftNavigationActionElements(); + $elements->{details}->click(); + $self->debugTakeSessionSnapshot(); + + ok($d->get_title() =~ m/Patron details for/i, + "Intra Navigate to Details"); + + return t::lib::Page::Members::Moremember->rebrandFromPageObject($self); +} + +1; #Make the compiler happy! diff --git a/t/lib/Page/Opac/OpacMessaging.pm b/t/lib/Page/Opac/OpacMessaging.pm new file mode 100644 index 0000000..cd0ea1b --- /dev/null +++ b/t/lib/Page/Opac/OpacMessaging.pm @@ -0,0 +1,101 @@ +package t::lib::Page::Opac::OpacMessaging; + +# 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 Lice strongnse +# along with Koha; if not, see . + +use Modern::Perl; +use Scalar::Util qw(blessed); +use Test::More; + +use t::lib::Page::Opac::OpacUser; + +use base qw(t::lib::Page::Opac t::lib::Page::Opac::LeftNavigation); + +use Koha::Exception::BadParameter; + +=head NAME t::lib::Page::Opac::OpacMessaging + +=head SYNOPSIS + +PageObject providing page functionality as a service! + +=cut + +=head new + + my $opacmemberentry = t::lib::Page::Opac::OpacMessaging->new(); + +Instantiates a WebDriver and loads the opac/opac-messaging.pl. +@PARAM1 HASHRef of optional and MANDATORY parameters +MANDATORY extra parameters: + none atm. + +@RETURNS t::lib::Page::Opac::OpacMessaging, ready for user actions! +=cut + +sub new { + my ($class, $params) = @_; + unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { + $params = {}; + } + $params->{resource} = '/cgi-bin/koha/opac-messaging.pl'; + $params->{type} = 'opac'; + + my $self = $class->SUPER::new($params); + + return $self; +} + +sub _getMessagingPreferenceCheckboxes { + my ($self) = @_; + my $d = $self->getDriver(); + + my @email_prefs = $d->find_elements('input[type="checkbox"][id^="email"]'); + my @phone_prefs = $d->find_elements('input[type="checkbox"][id^="phone"]'); + my @sms_prefs = $d->find_elements('input[type="checkbox"][id^="sms"]'); + + return { email => \@email_prefs, phone => \@phone_prefs, sms => \@sms_prefs }; +} + +################################################################################ +=head UI Mapping helper subroutines +See. Selenium documentation best practices for UI element mapping to common language descriptions. +=cut +################################################################################ + +sub checkMessagingPreferencesSet { + my ($self, $valid, @prefs) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + foreach my $type (@prefs){ + my @this_pref = $d->find_elements('input[type="checkbox"][id^="'.$type.'"]'); + + my $ok = 0; + + foreach my $checkbox (@this_pref){ + ok(0, "Opac Messaging $type checkbox ".$checkbox->get_attribute('id')." not checked") if !$checkbox->is_selected() and $valid; + ok(0, "Opac Messaging $type checkbox ".$checkbox->get_attribute('id')." checked (not supposed to be)") if $checkbox->is_selected() and !$valid; + $ok = 1; + } + ok($ok, "Opac Messaging $type checkboxes ok (all " . (($valid) ? 'checked':'unchecked') . ")"); + } + + return $self; +} + +1; -- 1.9.1