View | Details | Raw Unified | Return to bug 14536
Collapse All | Expand All

(-)a/t/lib/Page/Members/Memberentry.pm (+151 lines)
Line 0 Link Here
1
package t::lib::Page::Members::Memberentry;
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
20
use Modern::Perl;
21
use Scalar::Util qw(blessed);
22
use Test::More;
23
24
use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar);
25
26
use Koha::Exception::BadParameter;
27
28
29
sub new {
30
    my ($class, $params) = @_;
31
    unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) {
32
        $params = {};
33
    }
34
    $params->{resource} = '/cgi-bin/koha/members/memberentry.pl';
35
    $params->{type}     = 'staff';
36
37
    $params->{getParams} = [];
38
    #Handle MANDATORY parameters
39
    if ($params->{borrowernumber}) {
40
        push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber};
41
    }
42
    else {
43
        Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing.");
44
    }
45
    push @{$params->{getParams}}, "destination=".$params->{destination} if $params->{destination};
46
    push @{$params->{getParams}}, "op=".$params->{op} if $params->{op};
47
    push @{$params->{getParams}}, "categorycode=".$params->{categorycode} if $params->{categorycode};
48
    my $self = $class->SUPER::new($params);
49
50
    return $self;
51
}
52
53
################################################################################
54
=head UI Mapping helper subroutines
55
See. Selenium documentation best practices for UI element mapping to common language descriptions.
56
=cut
57
################################################################################
58
59
60
sub _getInputFieldsForValidation {
61
    my ($self) = @_;
62
    my $d = $self->getDriver();
63
64
    my $emailInput  = $d->find_element('#email');
65
    my $emailProInput  = $d->find_element('#emailpro');
66
    my $email_BInput  = $d->find_element('#B_email');
67
    
68
    my $phoneInput  = $d->find_element('#phone');
69
    my $phoneProInput  = $d->find_element('#phonepro');
70
    my $phone_BInput  = $d->find_element('#B_phone');
71
    
72
    return ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput);
73
}
74
75
76
################################################################################
77
=head PageObject Services
78
79
=cut
80
################################################################################
81
82
sub setEmail {
83
    my ($self, $input) = @_;
84
    my $d = $self->getDriver();
85
    $self->debugTakeSessionSnapshot();
86
    
87
    my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput) = $self->_getInputFieldsForValidation();
88
    
89
    $emailInput->clear();
90
    $emailProInput->clear();
91
    $email_BInput->clear();
92
    $emailInput->send_keys($input);
93
    $emailProInput->send_keys($input);
94
    $email_BInput->send_keys($input);
95
    ok(1, "Intra Memberentry Wrote \"$input\" to email fields.");
96
    
97
    return $self;
98
}
99
100
sub setPhone {
101
    my ($self, $input) = @_;
102
    my $d = $self->getDriver();
103
    $self->debugTakeSessionSnapshot();
104
    
105
    my ($emailInput, $emailProInput, $email_BInput, $phoneInput, $phoneProInput, $phone_BInput) = $self->_getInputFieldsForValidation();
106
    
107
    $phoneInput->clear();
108
    $phoneProInput->clear();
109
    $phone_BInput->clear();
110
    $phoneInput->send_keys($input);
111
    $phoneProInput->send_keys($input);
112
    $phone_BInput->send_keys($input);
113
    ok(1, "Intra Memberentry Wrote \"$input\" to phone fields.");
114
    
115
    return $self;
116
}
117
118
sub submitForm {
119
    my ($self, $valid) = @_;
120
    my $d = $self->getDriver();
121
    $self->debugTakeSessionSnapshot();
122
    
123
    my $submitButton = $d->find_element('form#entryform input[type="submit"]');
124
    $submitButton->click();
125
    
126
    $self->debugTakeSessionSnapshot();
127
    
128
    if ($valid) {
129
        my $submitted = $d->find_element("#editpatron", 'css');
130
        ok(1, "Intra Memberentry Submit changes success");
131
        return t::lib::Page::Members::Moremember->rebrandFromPageObject($self);
132
    } else {
133
        my @notsubmitted = $d->find_elements('form#entryform label[class="error"]', 'css');
134
        my $error_ids = "";
135
        
136
        foreach my $el_id (@notsubmitted){
137
            my $attr_id = $el_id->get_attribute("for");
138
            $error_ids .=  "'".$attr_id . "' ";
139
        }
140
        
141
        ok(1, "Intra Memberentry Submit changes ". $error_ids .", validation error (as expected).");
142
        $d->refresh();
143
        return $self;
144
    }
145
    
146
    
147
    
148
    
149
}
150
151
1;
(-)a/t/lib/Page/Members/Toolbar.pm (+11 lines)
Lines 128-135 sub navigateManageApiKeys { Link Here
128
128
129
    return t::lib::Page::Members::ApiKeys->rebrandFromPageObject($self);
129
    return t::lib::Page::Members::ApiKeys->rebrandFromPageObject($self);
130
}
130
}
131
sub navigateEditPatron {
132
    my ($self) = @_;
133
    my $d = $self->getDriver();
134
    $self->debugTakeSessionSnapshot();
131
135
136
    my $elements = $self->_getToolbarActionElements();
137
    $elements->{edit}->click();
138
    ok($d->get_title() =~ m/Modify patron/, "Intra Navigate to Modify patron");
132
139
140
    $self->debugTakeSessionSnapshot();
141
142
    return t::lib::Page::Members::Memberentry->rebrandFromPageObject($self);
143
}
133
144
134
145
135
1; #Make the compiler happy!
146
1; #Make the compiler happy!
(-)a/t/lib/Page/Opac/LeftNavigation.pm (+18 lines)
Lines 106-109 sub navigateYourAPIKeys { Link Here
106
    return t::lib::Page::Opac::OpacApiKeys->rebrandFromPageObject($self);
106
    return t::lib::Page::Opac::OpacApiKeys->rebrandFromPageObject($self);
107
}
107
}
108
108
109
sub navigateYourPersonalDetails {
110
    my ($self) = @_;
111
    my $d = $self->getDriver();
112
    $self->debugTakeSessionSnapshot();
113
114
    my $elements = $self->_getLeftNavigationActionElements();
115
    $elements->{yourPersonalDetails}->click();
116
    $self->debugTakeSessionSnapshot();
117
118
    my $breadcrumbs = $self->_getBreadcrumbLinks();
119
120
    ok(ref($breadcrumbs) eq 'ARRAY' &&
121
       $breadcrumbs->[scalar(@$breadcrumbs)-1]->get_text() =~ m/Your personal details/i,
122
       "Opac Navigate to Your personal details");
123
124
    return t::lib::Page::Opac::OpacMemberentry->rebrandFromPageObject($self);
125
}
126
109
1; #Make the compiler happy!
127
1; #Make the compiler happy!
(-)a/t/lib/Page/Opac/OpacMemberentry.pm (-1 / +161 lines)
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;

Return to bug 14536