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" );
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')
70 like($@, qr{An element could not be located on the page}, 'Basket should be empty');
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' );
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' );
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' );
90 $_->delete for @cleanup;