]> git.koha-community.org Git - koha.git/blob - t/db_dependent/selenium/regressions.t
Bug 21479: Add regression tests
[koha.git] / t / db_dependent / selenium / regressions.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use C4::Context;
21
22 use Test::More tests => 2;
23
24 use Koha::AuthUtils;
25 use t::lib::Selenium;
26 use t::lib::TestBuilder;
27
28 eval { require Selenium::Remote::Driver; };
29 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
30
31 my $s = t::lib::Selenium->new;
32
33 my $driver = $s->driver;
34 my $opac_base_url = $s->opac_base_url;
35 my $builder = t::lib::TestBuilder->new;
36
37 our @cleanup;
38 subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub {
39     plan tests => 2;
40
41     my $patron = $builder->build_object(
42         { class => 'Koha::Patrons', value => { flags => 1 } } );
43     my $password = Koha::AuthUtils::generate_password();
44     $patron->update_password( $patron->userid, $password );
45     $s->opac_auth( $patron->userid, $password );
46     my $elt = $driver->find_element('//span[@class="loggedinusername"]');
47     is( $elt->get_attribute('data-branchcode'), $patron->library->branchcode,
48         "Since bug 20921 span.loggedinusername should contain data-branchcode"
49     );
50     is( $elt->get_attribute('data-borrowernumber'), $patron->borrowernumber,
51 "Since bug 20921 span.loggedinusername should contain data-borrowernumber"
52     );
53     push @cleanup, $patron;
54     push @cleanup, $patron->category;
55     push @cleanup, $patron->library;
56 };
57
58 subtest 'OPAC - Remove from cart' => sub {
59     plan tests => 4;
60
61     $driver->get( $opac_base_url . "opac-search.pl?q=d" );
62
63     my $basket_count_elt;
64     eval {
65         # FIXME This will produce a STRACE
66         # A better way to do that would be to modify the way we display the basket count
67         # We should show/hide the count instead or recreate the node
68         $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span')
69     };
70     like($@, qr{An element could not be located on the page}, 'Basket should be empty');
71
72     $driver->find_element('//a[@class="addtocart cart1"]')->click;
73     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
74     is( $basket_count_elt->get_text(),
75         1, 'One element should have been added to the cart' );
76
77     $driver->find_element('//a[@class="addtocart cart3"]')->click;
78     $driver->find_element('//a[@class="addtocart cart5"]')->click;
79     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
80     is( $basket_count_elt->get_text(),
81         3, '3 elements should have been added to the cart' );
82
83     $driver->find_element('//a[@class="cartRemove cartR3"]')->click;
84     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
85     is( $basket_count_elt->get_text(),
86         2, '1 element should have been removed from the cart' );
87 };
88
89 END {
90     $_->delete for @cleanup;
91 };