From 48f71feeab4908c377678efb2bf6da51e78bc39d Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 14 Aug 2015 15:13:31 +0300 Subject: [PATCH] Bug 14590 - PageObject tests for misconfigured messaging preferences --- t/db_dependent/MessagingPreferencesValidation.t | 176 ++++++++++++++++++++++++ t/lib/Page/Members/Memberentry.pm | 138 +++++++++++++++++-- t/lib/Page/Members/Moremember.pm | 118 +++++++++++++++- t/lib/Page/Members/Toolbar.pm | 16 +++ t/lib/Page/Opac/LeftNavigation.pm | 22 +++ t/lib/Page/Opac/OpacMemberentry.pm | 2 +- t/lib/Page/Opac/OpacMessaging.pm | 101 ++++++++++++++ 7 files changed, 556 insertions(+), 17 deletions(-) create mode 100644 t/db_dependent/MessagingPreferencesValidation.t create mode 100644 t/lib/Page/Opac/OpacMessaging.pm diff --git a/t/db_dependent/MessagingPreferencesValidation.t b/t/db_dependent/MessagingPreferencesValidation.t new file mode 100644 index 0000000..d8ff9aa --- /dev/null +++ b/t/db_dependent/MessagingPreferencesValidation.t @@ -0,0 +1,176 @@ +#!/usr/bin/env perl + +# 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 . +$ENV{KOHA_PAGEOBJECT_DEBUG} = 1; +use Modern::Perl; + +use Test::More; +use Try::Tiny; #Even Selenium::Remote::Driver uses Try::Tiny :) + +use Koha::Auth::PermissionManager; + +use t::lib::Page::Mainpage; +use t::lib::Page::Opac::OpacMain; +use t::lib::Page::Opac::OpacMemberentry; +use t::lib::Page::Members::Memberentry; +use t::lib::Page::Members::Moremember; + +use t::lib::TestObjects::BorrowerFactory; +use t::lib::TestObjects::SystemPreferenceFactory; + +##Setting up the test context +my $testContext = {}; + +my $password = '1234'; +my $borrowerFactory = t::lib::TestObjects::BorrowerFactory->new(); +my $borrowers = $borrowerFactory->createTestGroup([ + {firstname => 'Testone', + surname => 'Testtwo', + cardnumber => '1A01', + branchcode => 'CPL', + userid => 'normal_user', + password => $password, + }, + {firstname => 'Testthree', + surname => 'Testfour', + cardnumber => 'superuberadmin', + branchcode => 'CPL', + userid => 'god', + password => $password, + }, + ], undef, $testContext); + +my $systempreferences = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ + {preference => 'ValidateEmailAddress', + value => 1 + }, + {preference => 'ValidatePhoneNumber', + value => 'ipn', + }, + {preference => 'TalkingTechItivaPhoneNotification', + value => 1 + }, + {preference => 'SMSSendDriver', + value => 'test' + }, + ], undef, $testContext); + +my $permissionManager = Koha::Auth::PermissionManager->new(); +$permissionManager->grantPermissions($borrowers->{'superuberadmin'}, {superlibrarian => 'superlibrarian'}); + +eval { + + # staff client + my $memberentry = t::lib::Page::Members::Memberentry->new({borrowernumber => $borrowers->{'superuberadmin'}->borrowernumber, op => 'modify', destination => 'circ', categorycode => 'PT'}); + # opac + my $main = t::lib::Page::Opac::OpacMain->new({borrowernumber => $borrowers->{'superuberadmin'}->borrowernumber}); + + # set valid contacts and check preferences checkboxes + $memberentry->doPasswordLogin($borrowers->{'superuberadmin'}->userid(), $password) + ->setEmail("valid\@email.com") + ->checkPreferences(1, "email") + ->setPhone("+3585012345678") + ->checkPreferences(1, "phone") + ->setSMSNumber("+3585012345678") + ->checkPreferences(1, "sms") + ->submitForm(1) # expecting success + ->navigateToDetails() + # make sure everything is now checked on moremember.pl details page + ->checkMessagingPreferencesSet(1, "email", "sms", "phone"); + + $main # check that they are also checked in OPAC + ->doPasswordLogin($borrowers->{'superuberadmin'}->userid(), $password) + ->navigateYourMessaging() + ->checkMessagingPreferencesSet(1, "email", "sms", "phone"); + + # go to edit patron and set invalid contacts. + $memberentry + ->navigateEditPatron() + ->setEmail("invalidemail.com") + ->checkPreferences(0, "email") + ->setPhone("+3585012asd345678") + ->checkPreferences(0, "phone") + ->setSMSNumber("+358501asd2345678") + ->checkPreferences(0, "sms") + # check messaging preferences: they should be unchecked + ->checkMessagingPreferencesSet(0, "email", "sms", "phone") + ->submitForm(0) # also confirm that we cant submit the preferences + ->navigateToDetails() + + # go to library use and just simply submit the form without any changes + ->navigateToLibraryUseEdit() + ->submitForm(1) + # all the preferences should be still set + ->checkMessagingPreferencesSet(1, "email", "sms", "phone") + + # go to smsnumber edit and make sure everything is checked + ->navigateToSMSnumberEdit() + ->checkMessagingPreferencesSet(1, "email", "sms", "phone") + ->submitForm(1) + ->checkMessagingPreferencesSet(1, "email", "sms", "phone") + + # go to patron information edit and clear email and phone + ->navigateToPatronInformationEdit() + ->clearMessagingContactFields("email", "phone") + ->submitForm(1) + # this should remove our messaging preferences for phone and email + ->checkMessagingPreferencesSet(0, "email", "phone") + ->checkMessagingPreferencesSet(1, "sms"); # ... but not for sms (it's still set) + + $main # check the preferences also from OPAC + ->navigateYourMessaging() + ->checkMessagingPreferencesSet(0, "email", "phone") + ->checkMessagingPreferencesSet(1, "sms"); + + # go to smsnumber edit and see that email and phone are disabled + $memberentry + ->navigateToSMSnumberEdit() + ->checkMessagingPreferencesSet(0, "email", "phone") + ->clearMessagingContactFields("SMSnumber") # uncheck all sms preferences + ->submitForm(1) + ->checkMessagingPreferencesSet(0, "email", "phone", "sms"); + + $main # check the preferences also from OPAC + ->navigateYourMessaging() + ->checkMessagingPreferencesSet(0, "email", "phone", "sms"); + +}; +if ($@) { #Catch all leaking errors and gracefully terminate. + warn $@; + tearDown(); + exit 1; +} + +##All tests done, tear down test context +tearDown(); +done_testing; + +sub tearDown { + t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); +} + + + + + + + + +###################################################### + ### STARTING TEST IMPLEMENTATIONS ### +###################################################### \ No newline at end of file diff --git a/t/lib/Page/Members/Memberentry.pm b/t/lib/Page/Members/Memberentry.pm index 2599042..2d3db2d 100644 --- a/t/lib/Page/Members/Memberentry.pm +++ b/t/lib/Page/Members/Memberentry.pm @@ -61,15 +61,41 @@ sub _getInputFieldsForValidation { my ($self) = @_; my $d = $self->getDriver(); - my $emailInput = $d->find_element('#email'); - my $emailProInput = $d->find_element('#emailpro'); - my $email_BInput = $d->find_element('#B_email'); + my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput, $SMSnumber); + eval { + $emailInput = $d->find_element('#email'); + }; + eval { + $emailProInput = $d->find_element('#emailpro'); + }; + eval { + $email_BInput = $d->find_element('#B_email'); + }; + eval { + $phoneInput = $d->find_element('#phone'); + }; + eval { + $phoneProInput = $d->find_element('#phonepro'); + }; + eval { + $phone_BInput = $d->find_element('#B_phone'); + }; + eval { + $SMSnumber = $d->find_element('#SMSnumber'); + }; - my $phoneInput = $d->find_element('#phone'); - my $phoneProInput = $d->find_element('#phonepro'); - my $phone_BInput = $d->find_element('#B_phone'); + return ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput, $SMSnumber); +} + +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 ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput); + return { email => \@email_prefs, phone => \@phone_prefs, sms => \@sms_prefs }; } @@ -79,12 +105,85 @@ sub _getInputFieldsForValidation { =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, "Intra Memberentry $type messaging checkbox ".$checkbox->get_attribute('id')." not checked") if !$checkbox->is_selected() and $valid; + ok(0, "Intra Memberentry $type messaging checkbox ".$checkbox->get_attribute('id')." checked (not supposed to be)") if $checkbox->is_selected() and !$valid; + $ok = 1; + } + ok($ok, "Intra Memberentry $type messaging checkboxes ok (all " . (($valid) ? 'checked':'unchecked') . ")"); + } + + return $self; +} + +sub clearMessagingContactFields { + my ($self, @fields) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput, $SMSnumber) = $self->_getInputFieldsForValidation(); + + if (@fields) { + for my $field (@fields){ + $emailInput->clear() if $field eq "email"; + $emailProInput->clear() if $field eq "emailpro"; + $email_BInput->clear() if $field eq "B_email"; + $phoneInput->clear() if $field eq "phone"; + $phoneProInput->clear() if $field eq "phonepro"; + $phone_BInput->clear() if $field eq "B_phone"; + $SMSnumber->clear() if $field eq "SMSnumber"; + } + ok(1, "Intra Memberentry contact fields (@fields) cleared"); + } else { + $emailInput->clear(); + $emailProInput->clear(); + $email_BInput->clear(); + $phoneInput->clear(); + $phoneProInput->clear(); + $phone_BInput->clear(); + $SMSnumber->clear(); + ok(1, "Intra Memberentry contact fields (email, emailpro, email_B, phone, phonepro, phone_B, SMSnumber) cleared"); + } + + return $self; +} + +sub checkPreferences { + my ($self, $valid, $type) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $checkboxes = $self->_getMessagingPreferenceCheckboxes(); + + ok (0, "Intra $type checkboxes not defined") if not defined $checkboxes->{$type}; + return 0 if not defined $checkboxes->{$type}; + + foreach my $checkbox (@{ $checkboxes->{$type} }){ + ok(0, "Intra Memberentry $type messaging checkbox ".$checkbox->get_attribute('id')." not available") if !$checkbox->is_enabled() and $valid; + ok(0, "Intra Memberentry $type messaging checkbox ".$checkbox->get_attribute('id')." available (not supposed to be)") if $checkbox->is_enabled() and !$valid; + + $checkbox->click() if not $checkbox->is_selected(); + } + ok (1, "Intra Memberentry $type messaging checkboxes checked") if $valid; + + return $self; +} sub setEmail { my ($self, $input) = @_; my $d = $self->getDriver(); $self->debugTakeSessionSnapshot(); - my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput) = $self->_getInputFieldsForValidation(); + my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput, $SMSnumber) = $self->_getInputFieldsForValidation(); $emailInput->clear(); $emailProInput->clear(); @@ -102,7 +201,7 @@ sub setPhone { my $d = $self->getDriver(); $self->debugTakeSessionSnapshot(); - my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput) = $self->_getInputFieldsForValidation(); + my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput, $SMSnumber) = $self->_getInputFieldsForValidation(); $phoneInput->clear(); $phoneProInput->clear(); @@ -115,14 +214,27 @@ sub setPhone { return $self; } +sub setSMSNumber { + my ($self, $input) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput, $SMSnumber) = $self->_getInputFieldsForValidation(); + + $SMSnumber->clear(); + $SMSnumber->send_keys($input); + ok(1, "Intra Memberentry Wrote \"$input\" to SMSnumber."); + + return $self; +} + sub submitForm { my ($self, $valid) = @_; my $d = $self->getDriver(); $self->debugTakeSessionSnapshot(); my $submitButton = $d->find_element('form#entryform input[type="submit"]'); - $submitButton->click(); - + $submitButton->submit(); $self->debugTakeSessionSnapshot(); if ($valid) { @@ -142,10 +254,6 @@ sub submitForm { $d->refresh(); return $self; } - - - - } 1; \ No newline at end of file diff --git a/t/lib/Page/Members/Moremember.pm b/t/lib/Page/Members/Moremember.pm index 456fd19..f7095cd 100644 --- a/t/lib/Page/Members/Moremember.pm +++ b/t/lib/Page/Members/Moremember.pm @@ -19,6 +19,7 @@ package t::lib::Page::Members::Moremember; use Modern::Perl; use Scalar::Util qw(blessed); +use Test::More; use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar); @@ -74,9 +75,35 @@ See. Selenium documentation best practices for UI element mapping to common lang =cut ################################################################################ +sub _getEditLinks { + my ($self) = @_; + my $d = $self->getDriver(); + + my $patron_info_edit = $d->find_element("div#patron-information div.action a[href*='memberentry.pl?op=modify'][href*='step=1']", 'css'); + my $sms_number_edit = $d->find_element("div.action a[href*='memberentry.pl?op=modify'][href*='step=5']", 'css'); + my $library_use_edit = $d->find_element("div.action a[href*='memberentry.pl?op=modify'][href*='step=3']", 'css'); + my $alternate_addr_edit = $d->find_element("div.action a[href*='memberentry.pl?op=modify'][href*='step=6']", 'css'); + my $alternative_contact_edit = $d->find_element("div.action a[href*='memberentry.pl?op=modify'][href*='step=2']", 'css'); + + my $e = {}; + $e->{patron_information} = $patron_info_edit if $patron_info_edit; + $e->{smsnumber} = $sms_number_edit if $sms_number_edit; + $e->{library_use} = $library_use_edit if $library_use_edit; + $e->{alternate_address} = $alternate_addr_edit if $alternate_addr_edit; + $e->{alternative_contact} = $alternative_contact_edit if $alternative_contact_edit; + return $e; +} +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 PageObject Services @@ -84,7 +111,96 @@ See. Selenium documentation best practices for UI element mapping to common lang =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, "Intra Moremember $type messaging checkbox ".$checkbox->get_attribute('id')." not checked") if !$checkbox->is_selected() and $valid; + ok(0, "Intra Moremember $type messaging checkbox ".$checkbox->get_attribute('id')." checked (not supposed to be)") if $checkbox->is_selected() and !$valid; + $ok = 1; + } + ok($ok, "Intra Moremember $type messaging checkboxes ok (all " . (($valid) ? 'checked':'unchecked') . ")"); + } + + return $self; +} + +sub navigateToPatronInformationEdit { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getEditLinks(); + $elements->{patron_information}->click(); + ok($d->get_title() =~ m/Modify patron/, "Intra Navigate to Modify patron information"); + + $self->debugTakeSessionSnapshot(); + + return t::lib::Page::Members::Memberentry->rebrandFromPageObject($self); +} + +sub navigateToSMSnumberEdit { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getEditLinks(); + $elements->{smsnumber}->click(); + ok($d->get_title() =~ m/Modify patron/, "Intra Navigate to Modify patron SMS number"); + + $self->debugTakeSessionSnapshot(); + + return t::lib::Page::Members::Memberentry->rebrandFromPageObject($self); +} + +sub navigateToLibraryUseEdit { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getEditLinks(); + $elements->{library_use}->click(); + ok($d->get_title() =~ m/Modify patron/, "Intra Navigate to Modify patron Library use"); + + $self->debugTakeSessionSnapshot(); + + return t::lib::Page::Members::Memberentry->rebrandFromPageObject($self); +} + +sub navigateToAlternateAddressEdit { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getEditLinks(); + $elements->{alternate_address}->click(); + ok($d->get_title() =~ m/Modify patron/, "Intra Navigate to Modify patron Alternate address"); + $self->debugTakeSessionSnapshot(); + + return t::lib::Page::Members::Memberentry->rebrandFromPageObject($self); +} + +sub navigateToAlternativeContactEdit { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getEditLinks(); + $elements->{alternative_contact}->click(); + ok($d->get_title() =~ m/Modify patron/, "Intra Navigate to Modify patron Alternative contact"); + + $self->debugTakeSessionSnapshot(); + + return t::lib::Page::Members::Memberentry->rebrandFromPageObject($self); +} diff --git a/t/lib/Page/Members/Toolbar.pm b/t/lib/Page/Members/Toolbar.pm index 61ecd98..8748834 100644 --- a/t/lib/Page/Members/Toolbar.pm +++ b/t/lib/Page/Members/Toolbar.pm @@ -143,4 +143,20 @@ sub navigateEditPatron { } +# left menu +sub navigateToDetails { + my ($self) = @_; + my $d = $self->getDriver(); + + my $e = {}; + + $e->{details} = $d->find_element("div#menu a[href*='moremember.pl']", 'css'); + + $e->{details}->click(); + ok($d->get_title() =~ m/Patron details for/, "Intra Navigate to Patron Details"); + + $self->debugTakeSessionSnapshot(); + return t::lib::Page::Members::Moremember->rebrandFromPageObject($self); +} + 1; #Make the compiler happy! \ No newline at end of file diff --git a/t/lib/Page/Opac/LeftNavigation.pm b/t/lib/Page/Opac/LeftNavigation.pm index 2f344a8..ae10de5 100644 --- a/t/lib/Page/Opac/LeftNavigation.pm +++ b/t/lib/Page/Opac/LeftNavigation.pm @@ -22,6 +22,7 @@ use Scalar::Util qw(blessed); use Test::More; use t::lib::Page::Opac::OpacApiKeys; +use t::lib::Page::Opac::OpacMessaging; =head NAME t::lib::Page::Opac::LeftNavigation @@ -72,6 +73,9 @@ sub _getLeftNavigationActionElements { $e->{yourPurchaseSuggestions} = $d->find_element("a[href*='opac-suggestions.pl']", 'css'); }; eval { + $e->{yourMessaging} = $d->find_element("a[href*='opac-messaging.pl']", 'css'); + }; + eval { $e->{yourLists} = $d->find_element("a[href*='opac-shelves.pl']", 'css'); }; eval { @@ -106,6 +110,24 @@ sub navigateYourAPIKeys { return t::lib::Page::Opac::OpacApiKeys->rebrandFromPageObject($self); } +sub navigateYourMessaging { + my ($self) = @_; + my $d = $self->getDriver(); + $self->debugTakeSessionSnapshot(); + + my $elements = $self->_getLeftNavigationActionElements(); + $elements->{yourMessaging}->click(); + $self->debugTakeSessionSnapshot(); + + my $breadcrumbs = $self->_getBreadcrumbLinks(); + + ok(ref($breadcrumbs) eq 'ARRAY' && + $breadcrumbs->[scalar(@$breadcrumbs)-1]->get_text() =~ m/Your messaging/i, + "Opac Navigate to Your messaging"); + + return t::lib::Page::Opac::OpacMessaging->rebrandFromPageObject($self); +} + sub navigateYourPersonalDetails { my ($self) = @_; my $d = $self->getDriver(); diff --git a/t/lib/Page/Opac/OpacMemberentry.pm b/t/lib/Page/Opac/OpacMemberentry.pm index 2dc3a21..343e25e 100644 --- a/t/lib/Page/Opac/OpacMemberentry.pm +++ b/t/lib/Page/Opac/OpacMemberentry.pm @@ -23,7 +23,7 @@ use Test::More; use t::lib::Page::Opac::OpacUser; -use base qw(t::lib::Page::Opac); +use base qw(t::lib::Page::Opac t::lib::Page::Opac::LeftNavigation); use Koha::Exception::BadParameter; 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