Line 0
Link Here
|
0 |
- |
1 |
package t::lib::Page::Opac::OpacMemberentry; |
|
|
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 Lice strongnse |
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 t::lib::Page::Opac::OpacUser; |
25 |
|
26 |
use base qw(t::lib::Page::Opac); |
27 |
|
28 |
use Koha::Exception::BadParameter; |
29 |
|
30 |
=head NAME t::lib::Page::Opac::OpacMemberentry |
31 |
|
32 |
=head SYNOPSIS |
33 |
|
34 |
PageObject providing page functionality as a service! |
35 |
|
36 |
=cut |
37 |
|
38 |
=head new |
39 |
|
40 |
my $opacmemberentry = t::lib::Page::Opac::OpacMemberentry->new(); |
41 |
|
42 |
Instantiates a WebDriver and loads the opac/opac-memberentry.pl. |
43 |
@PARAM1 HASHRef of optional and MANDATORY parameters |
44 |
MANDATORY extra parameters: |
45 |
none atm. |
46 |
|
47 |
@RETURNS t::lib::Page::Opac::OpacMemberentry, ready for user actions! |
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/opac-memberentry.pl'; |
56 |
$params->{type} = 'opac'; |
57 |
|
58 |
my $self = $class->SUPER::new($params); |
59 |
|
60 |
return $self; |
61 |
} |
62 |
|
63 |
################################################################################ |
64 |
=head UI Mapping helper subroutines |
65 |
See. Selenium documentation best practices for UI element mapping to common language descriptions. |
66 |
=cut |
67 |
################################################################################ |
68 |
|
69 |
sub _getInputFieldsForValidation { |
70 |
my ($self) = @_; |
71 |
my $d = $self->getDriver(); |
72 |
|
73 |
my $emailInput = $d->find_element('#borrower_email'); |
74 |
my $emailProInput = $d->find_element('#borrower_emailpro'); |
75 |
my $email_BInput = $d->find_element('#borrower_B_email'); |
76 |
|
77 |
my $phoneInput = $d->find_element('#borrower_phone'); |
78 |
my $phoneProInput = $d->find_element('#borrower_phonepro'); |
79 |
my $phone_BInput = $d->find_element('#borrower_B_phone'); |
80 |
|
81 |
return ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput); |
82 |
} |
83 |
|
84 |
|
85 |
################################################################################ |
86 |
=head PageObject Services |
87 |
|
88 |
=cut |
89 |
################################################################################ |
90 |
|
91 |
=head isFieldsAvailable |
92 |
|
93 |
$page->isFieldsAvailable(); |
94 |
|
95 |
@RETURN t::lib::Page-object |
96 |
@CROAK if unable to find required fields. |
97 |
=cut |
98 |
|
99 |
sub setEmail { |
100 |
my ($self, $input) = @_; |
101 |
my $d = $self->getDriver(); |
102 |
$self->debugTakeSessionSnapshot(); |
103 |
|
104 |
my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput) = $self->_getInputFieldsForValidation(); |
105 |
|
106 |
$emailInput->send_keys($input); |
107 |
$emailProInput->send_keys($input); |
108 |
$email_BInput->send_keys($input); |
109 |
ok(1, "OpacMemberentry Wrote \"$input\" to email fields."); |
110 |
|
111 |
return $self; |
112 |
} |
113 |
|
114 |
sub setPhone { |
115 |
my ($self, $input) = @_; |
116 |
my $d = $self->getDriver(); |
117 |
$self->debugTakeSessionSnapshot(); |
118 |
|
119 |
my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput) = $self->_getInputFieldsForValidation(); |
120 |
|
121 |
$phoneInput->send_keys($input); |
122 |
$phoneProInput->send_keys($input); |
123 |
$phone_BInput->send_keys($input); |
124 |
ok(1, "OpacMemberentry Wrote \"$input\" to phone fields."); |
125 |
|
126 |
return $self; |
127 |
} |
128 |
|
129 |
sub submitForm { |
130 |
my ($self, $valid) = @_; |
131 |
my $d = $self->getDriver(); |
132 |
$self->debugTakeSessionSnapshot(); |
133 |
|
134 |
my $submitButton = $d->find_element('form#memberentry-form input[type="submit"]'); |
135 |
$submitButton->click(); |
136 |
|
137 |
$self->debugTakeSessionSnapshot(); |
138 |
|
139 |
if ($valid) { |
140 |
my $submitted = $d->find_element('#update-submitted'); |
141 |
ok(1, "OpacMemberentry Submit changes success"); |
142 |
} else { |
143 |
my @notsubmitted = $d->find_elements('form#memberentry-form label[id^="borrower_"][id$="-error"]', 'css'); |
144 |
my $error_ids = ""; |
145 |
|
146 |
foreach my $el_id (@notsubmitted){ |
147 |
my $attr_id = $el_id->get_attribute("id"); |
148 |
$attr_id =~ s/borrower_//g; |
149 |
$attr_id =~ s/-error//g; |
150 |
$error_ids .= "'".$attr_id . "' "; |
151 |
} |
152 |
|
153 |
ok(1, "OpacMemberentry Submit changes ". $error_ids .", validation error (as expected)."); |
154 |
} |
155 |
|
156 |
|
157 |
|
158 |
return t::lib::Page::Opac::OpacUser->rebrandFromPageObject($self); |
159 |
} |
160 |
|
161 |
1; |