|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/env perl |
|
|
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 |
$ENV{KOHA_PAGEOBJECT_DEBUG} = 1; |
| 20 |
use Modern::Perl; |
| 21 |
|
| 22 |
use Test::More; |
| 23 |
use Try::Tiny; #Even Selenium::Remote::Driver uses Try::Tiny :) |
| 24 |
|
| 25 |
use Koha::Auth::PermissionManager; |
| 26 |
|
| 27 |
use t::lib::Page::Mainpage; |
| 28 |
use t::lib::Page::Opac::OpacMain; |
| 29 |
use t::lib::Page::Opac::OpacMemberentry; |
| 30 |
use t::lib::Page::Members::Memberentry; |
| 31 |
use t::lib::Page::Members::Moremember; |
| 32 |
|
| 33 |
use t::lib::TestObjects::BorrowerFactory; |
| 34 |
use t::lib::TestObjects::SystemPreferenceFactory; |
| 35 |
|
| 36 |
##Setting up the test context |
| 37 |
my $testContext = {}; |
| 38 |
|
| 39 |
my $password = '1234'; |
| 40 |
my $borrowerFactory = t::lib::TestObjects::BorrowerFactory->new(); |
| 41 |
my $borrowers = $borrowerFactory->createTestGroup([ |
| 42 |
{firstname => 'Testone', |
| 43 |
surname => 'Testtwo', |
| 44 |
cardnumber => '1A01', |
| 45 |
branchcode => 'CPL', |
| 46 |
userid => 'normal_user', |
| 47 |
password => $password, |
| 48 |
}, |
| 49 |
{firstname => 'Testthree', |
| 50 |
surname => 'Testfour', |
| 51 |
cardnumber => 'superuberadmin', |
| 52 |
branchcode => 'CPL', |
| 53 |
userid => 'god', |
| 54 |
password => $password, |
| 55 |
}, |
| 56 |
], undef, $testContext); |
| 57 |
|
| 58 |
my $systempreferences = t::lib::TestObjects::SystemPreferenceFactory->createTestGroup([ |
| 59 |
{preference => 'ValidateEmailAddress', |
| 60 |
value => 1 |
| 61 |
}, |
| 62 |
{preference => 'ValidatePhoneNumber', |
| 63 |
value => 'ipn', |
| 64 |
}, |
| 65 |
{preference => 'TalkingTechItivaPhoneNotification', |
| 66 |
value => 1 |
| 67 |
}, |
| 68 |
{preference => 'SMSSendDriver', |
| 69 |
value => 'test' |
| 70 |
}, |
| 71 |
], undef, $testContext); |
| 72 |
|
| 73 |
my $permissionManager = Koha::Auth::PermissionManager->new(); |
| 74 |
$permissionManager->grantPermissions($borrowers->{'superuberadmin'}, {superlibrarian => 'superlibrarian'}); |
| 75 |
|
| 76 |
eval { |
| 77 |
|
| 78 |
# staff client |
| 79 |
my $memberentry = t::lib::Page::Members::Memberentry->new({borrowernumber => $borrowers->{'superuberadmin'}->borrowernumber, op => 'modify', destination => 'circ', categorycode => 'PT'}); |
| 80 |
# opac |
| 81 |
my $main = t::lib::Page::Opac::OpacMain->new({borrowernumber => $borrowers->{'superuberadmin'}->borrowernumber}); |
| 82 |
|
| 83 |
# set valid contacts and check preferences checkboxes |
| 84 |
$memberentry->doPasswordLogin($borrowers->{'superuberadmin'}->userid(), $password) |
| 85 |
->setEmail("valid\@email.com") |
| 86 |
->checkPreferences(1, "email") |
| 87 |
->setPhone("+3585012345678") |
| 88 |
->checkPreferences(1, "phone") |
| 89 |
->setSMSNumber("+3585012345678") |
| 90 |
->checkPreferences(1, "sms") |
| 91 |
->submitForm(1) # expecting success |
| 92 |
->navigateToDetails() |
| 93 |
# make sure everything is now checked on moremember.pl details page |
| 94 |
->checkMessagingPreferencesSet(1, "email", "sms", "phone"); |
| 95 |
|
| 96 |
$main # check that they are also checked in OPAC |
| 97 |
->doPasswordLogin($borrowers->{'superuberadmin'}->userid(), $password) |
| 98 |
->navigateYourMessaging() |
| 99 |
->checkMessagingPreferencesSet(1, "email", "sms", "phone"); |
| 100 |
|
| 101 |
# go to edit patron and set invalid contacts. |
| 102 |
$memberentry |
| 103 |
->navigateEditPatron() |
| 104 |
->setEmail("invalidemail.com") |
| 105 |
->checkPreferences(0, "email") |
| 106 |
->setPhone("+3585012asd345678") |
| 107 |
->checkPreferences(0, "phone") |
| 108 |
->setSMSNumber("+358501asd2345678") |
| 109 |
->checkPreferences(0, "sms") |
| 110 |
# check messaging preferences: they should be unchecked |
| 111 |
->checkMessagingPreferencesSet(0, "email", "sms", "phone") |
| 112 |
->submitForm(0) # also confirm that we cant submit the preferences |
| 113 |
->navigateToDetails() |
| 114 |
|
| 115 |
# go to library use and just simply submit the form without any changes |
| 116 |
->navigateToLibraryUseEdit() |
| 117 |
->submitForm(1) |
| 118 |
# all the preferences should be still set |
| 119 |
->navigateToDetails() |
| 120 |
->checkMessagingPreferencesSet(1, "email", "sms", "phone") |
| 121 |
|
| 122 |
# go to smsnumber edit and make sure everything is checked |
| 123 |
->navigateToSMSnumberEdit() |
| 124 |
->checkMessagingPreferencesSet(1, "email", "sms", "phone") |
| 125 |
->submitForm(1) |
| 126 |
->navigateToDetails() |
| 127 |
->checkMessagingPreferencesSet(1, "email", "sms", "phone") |
| 128 |
|
| 129 |
# go to patron information edit and clear email and phone |
| 130 |
->navigateToPatronInformationEdit() |
| 131 |
->clearMessagingContactFields("email", "phone") |
| 132 |
->submitForm(1) |
| 133 |
->navigateToDetails() |
| 134 |
# this should remove our messaging preferences for phone and email |
| 135 |
->checkMessagingPreferencesSet(0, "email", "phone") |
| 136 |
->checkMessagingPreferencesSet(1, "sms"); # ... but not for sms (it's still set) |
| 137 |
|
| 138 |
$main # check the preferences also from OPAC |
| 139 |
->navigateYourMessaging() |
| 140 |
->checkMessagingPreferencesSet(0, "email", "phone") |
| 141 |
->checkMessagingPreferencesSet(1, "sms"); |
| 142 |
|
| 143 |
# go to smsnumber edit and see that email and phone are disabled |
| 144 |
$memberentry |
| 145 |
->navigateToSMSnumberEdit() |
| 146 |
->checkMessagingPreferencesSet(0, "email", "phone") |
| 147 |
->clearMessagingContactFields("SMSnumber") # uncheck all sms preferences |
| 148 |
->submitForm(1) |
| 149 |
->navigateToDetails() |
| 150 |
->checkMessagingPreferencesSet(0, "email", "phone", "sms"); |
| 151 |
|
| 152 |
$main # check the preferences also from OPAC |
| 153 |
->navigateYourMessaging() |
| 154 |
->checkMessagingPreferencesSet(0, "email", "phone", "sms"); |
| 155 |
|
| 156 |
}; |
| 157 |
if ($@) { #Catch all leaking errors and gracefully terminate. |
| 158 |
warn $@; |
| 159 |
tearDown(); |
| 160 |
exit 1; |
| 161 |
} |
| 162 |
|
| 163 |
##All tests done, tear down test context |
| 164 |
tearDown(); |
| 165 |
done_testing; |
| 166 |
|
| 167 |
sub tearDown { |
| 168 |
t::lib::TestObjects::ObjectFactory->tearDownTestContext($testContext); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
###################################################### |
| 179 |
### STARTING TEST IMPLEMENTATIONS ### |
| 180 |
###################################################### |