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

(-)a/t/db_dependent/Koha/Auth.t (+68 lines)
Line 0 Link Here
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
20
use Modern::Perl;
21
22
use Test::More; #Please don't set the test count here. It is nothing but trouble when rebasing against master
23
                #and is of dubious help, especially since we are running dynamic tests here which are triggered
24
                #based on the reported test infrastucture capabilities.
25
use Try::Tiny; #Even Selenium::Remote::Driver uses Try::Tiny :)
26
27
use t::lib::Page::Mainpage;
28
29
use C4::Members;
30
use Koha::Database;
31
use Koha::Borrower;
32
33
#my $builder = t::lib::TestBuilder->new();
34
#$builder->build({
35
#    source  => 'UserPermission',
36
#    value   => {},
37
#    only_fk => undef,
38
#});
39
40
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
41
my $password = '1234';
42
##Setting up test context Koha-style!
43
#This should be refactored when a proper automagic setUp-tearDown framework for integration tests is deployed.
44
my $borrower = C4::Members::GetMember(cardnumber => '11A001'); #These tests can crash and leave the context behind,
45
my $borrowernumber = $borrower->{borrowernumber} if $borrower; #so when we rerun them, we get nasty issues with existing DB objects.
46
unless ($borrower) {
47
    $borrowernumber = C4::Members::AddMember(
48
                            firstname    => 'Olli',
49
                            lastname     => 'Kivi',
50
                            categorycode => 'PT',
51
                            userid       => '11Aadmin',
52
                            password     => $password,
53
                            cardnumber   => '11A001',
54
                            dateofbirth  => DateTime->now(time_zone => C4::Context->tz)->subtract(years => 21), #I am always 21 :)
55
                            flags        => '1', #Giving specific permission flags here is REALLY HARD! Just giving superlibrarian-permission.
56
                            branchcode   => 'CPL',
57
                            );
58
    $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber);
59
}
60
61
my $mainpage = t::lib::Page::Mainpage->new();
62
$mainpage->isPasswordLoginAvailable()->doPasswordLogin($borrower->{userid}, $password);
63
#my $ss = $mainpage->getDriver()->get_page_source();
64
65
66
#TearDown test context..
67
Koha::Database->new()->schema()->resultset('Borrower')->search({borrowernumber => $borrower->{borrowernumber}})->delete_all();
68
done_testing;
(-)a/t/lib/Page.pm (+136 lines)
Line 0 Link Here
1
package t::lib::Page;
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 Test::More;
22
23
use t::lib::WebDriverFactory;
24
25
use Koha::Exception::BadParameter;
26
27
=head NAME t::lib::Page
28
29
=head SYNOPSIS
30
31
PageObject-pattern parent class
32
33
=head Class variables
34
35
Selenium::Remote::Driver driver, contains the driver implementation used to run these tests
36
t::Page::Common::Header header, the header page component
37
t::Page::Common::Footer footer, the footer page component
38
=cut
39
40
our $hostProtocol = 'http';
41
our $hostAddress = 'localhost';
42
our $hostPort = '443';
43
44
sub new {
45
    my ($class, $params) = @_;
46
    $params = _mergeDefaultConfig($params);
47
48
    my $self = {};
49
    bless($self, $class);
50
    unless ($params->{driver}) {
51
        my ($driver) = t::lib::WebDriverFactory::getUserAgentDrivers({phantomjs => $params});
52
        $self->{driver} = $driver;
53
    }
54
    $self->{type}     = $params->{type}; #This parameter is mandatory. _mergeDefaultConfig() dies without it.
55
    $self->{resource} = $params->{resource} || '/';
56
    $self->{header}   = $params->{header}   || undef;
57
    $self->{footer}   = $params->{footer}   || undef;
58
59
    $self->{driver}->get( $params->{resource} );
60
    return $self;
61
}
62
63
=head _mergeDefaultConfig
64
65
@THROWS Koha::Exception::BadParameter
66
=cut
67
68
sub _mergeDefaultConfig {
69
    my ($params) = @_;
70
    unless (ref($params) eq 'HASH' && $params->{type}) {
71
        Koha::Exception::BadParameter->throw(error => "t::lib::Page:> When instantiating Page-objects, you must define the 'type'-parameter.");
72
    }
73
74
    my $testServerConfigs = C4::Context->config('testservers');
75
    my $conf = $testServerConfigs->{ $params->{type} };
76
    Koha::Exception::BadParameter->throw(error => "t::lib::Page:> Unknown 'type'-parameter '".$params->{type}."'. Values 'opac', 'staff' and 'rest' are supported.")
77
                unless $conf;
78
    #Merge given $params-config on top of the $KOHA_CONF's testservers-directives
79
    @$conf{keys %$params} = values %$params;
80
    return $conf;
81
}
82
83
=head isPasswordLoginAvailable
84
85
    $page->isPasswordLoginAvailable();
86
87
@RETURN t::lib::Page-object
88
@CROAK if password login is unavailable.
89
=cut
90
91
sub isPasswordLoginAvailable {
92
    my $self = shift;
93
    my $d = $self->getDriver();
94
95
    _getPasswordLoginElements($d);
96
    ok(($d->get_title() =~ /Log in to Koha/), "PasswordLoginAvailable");
97
    return $self;
98
}
99
sub doPasswordLogin {
100
    my ($self, $username, $password) = @_;
101
    my $d = $self->getDriver();
102
103
    my ($submitButton, $useridInput, $passwordInput) = _getPasswordLoginElements($d);
104
    $useridInput->send_keys($username);
105
    $passwordInput->send_keys($password);
106
    $submitButton->click();
107
108
    my $cookies = $d->get_all_cookies();
109
    my @cgisessid = grep {$_->{name} eq 'CGISESSID'} @$cookies;
110
111
    ok(($d->get_title() !~ /Log in to Koha/ && #No longer in the login page
112
        $cgisessid[0]) #Cookie CGISESSID defined!
113
       , "PasswordLoginSucceeded");
114
115
    return $self; #After a succesfull password login, we are directed to the same page we tried to access.
116
}
117
sub _getPasswordLoginElements {
118
    my $d = shift;
119
    my $submitButton  = $d->find_element('#submit');
120
    my $useridInput   = $d->find_element('#userid');
121
    my $passwordInput = $d->find_element('#password');
122
    return ($submitButton, $useridInput, $passwordInput);
123
}
124
125
################################################
126
  ##  INTRODUCING OBJECT ACCESSORS  ##
127
################################################
128
sub setDriver {
129
    my ($self, $driver) = @_;
130
    $self->{driver} = $driver;
131
}
132
sub getDriver {
133
    my ($self) = @_;
134
    return $self->{driver};
135
}
136
1; #Make the compiler happy!
(-)a/t/lib/Page/Mainpage.pm (-1 / +45 lines)
Line 0 Link Here
0
- 
1
package t::lib::Page::Mainpage;
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
22
use base qw(t::lib::Page);
23
24
=head NAME t::lib::Page::Mainpage
25
26
=head SYNOPSIS
27
28
Mainpage PageObject providing page functionality as a service!
29
30
=cut
31
32
sub new {
33
    my ($class, $params) = @_;
34
    unless (ref($params) eq 'HASH') {
35
        $params = {};
36
    }
37
    $params->{resource} = '/cgi-bin/koha/mainpage.pl';
38
    $params->{type}     = 'staff';
39
    my $self = $class->SUPER::new($params);
40
41
    return $self;
42
}
43
44
45
1; #Make the compiler happy!

Return to bug 13691