3 # This file is part of Koha.
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.
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.
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>.
22 use Test::More tests => 2;
26 use t::lib::TestBuilder;
28 eval { require Selenium::Remote::Driver; };
29 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
31 my $s = t::lib::Selenium->new;
33 my $driver = $s->driver;
34 my $opac_base_url = $s->opac_base_url;
35 my $builder = t::lib::TestBuilder->new;
38 subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub {
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"
50 is( $elt->get_attribute('data-borrowernumber'), $patron->borrowernumber,
51 "Since bug 20921 span.loggedinusername should contain data-borrowernumber"
53 push @cleanup, $patron;
54 push @cleanup, $patron->category;
55 push @cleanup, $patron->library;
58 subtest 'OPAC - Remove from cart' => sub {
61 $driver->get( $opac_base_url . "opac-search.pl?q=d" );
63 # A better way to do that would be to modify the way we display the basket count
64 # We should show/hide the count instead or recreate the node
65 my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
66 is( scalar(@basket_count_elts), 0, 'Basket should be empty');
68 $driver->find_element('//a[@class="addtocart cart1"]')->click;
69 my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
70 is( $basket_count_elt->get_text(),
71 1, 'One element should have been added to the cart' );
73 $driver->find_element('//a[@class="addtocart cart3"]')->click;
74 $driver->find_element('//a[@class="addtocart cart5"]')->click;
75 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
76 is( $basket_count_elt->get_text(),
77 3, '3 elements should have been added to the cart' );
79 $driver->find_element('//a[@class="cartRemove cartR3"]')->click;
80 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
81 is( $basket_count_elt->get_text(),
82 2, '1 element should have been removed from the cart' );
86 $_->delete for @cleanup;