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>.
19 use File::Basename qw(dirname );
21 use Test::WWW::Mechanize;
28 use t::lib::TestBuilder;
30 use t::lib::Mocks::Zebra;
32 eval { require Selenium::Remote::Driver; };
34 plan skip_all => "Selenium::Remote::Driver is needed for selenium tests.";
39 my $s = t::lib::Selenium->new;
41 my $driver = $s->driver;
42 my $opac_base_url = $s->opac_base_url;
43 my $base_url = $s->base_url;
44 my $builder = t::lib::TestBuilder->new;
46 my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
48 my $SearchEngine_value = C4::Context->preference('SearchEngine');
49 C4::Context->set_preference('SearchEngine', 'Zebra');
51 my $mock_zebra = t::lib::Mocks::Zebra->new(
53 koha_conf => $ENV{KOHA_CONF},
54 marcflavour => $marcflavour,
58 subtest 'OPAC - Remove from cart' => sub {
61 my $sourcedir = dirname(__FILE__) . "/../data";
62 $mock_zebra->load_records(
63 sprintf( "%s/%s/zebraexport/biblio", $sourcedir, lc($marcflavour) ),
64 'iso2709', 'biblios', 1 );
65 $mock_zebra->launch_zebra;
67 # We need to prevent scrolling to prevent the floating toolbar from overlapping buttons we are testing
68 my $window_size = $driver->get_window_size();
69 $driver->set_window_size(1920,10800);
71 $driver->get( $opac_base_url . "opac-search.pl?q=d" );
73 # A better way to do that would be to modify the way we display the basket count
74 # We should show/hide the count instead or recreate the node
75 my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
76 is( scalar(@basket_count_elts), 0, 'Basket should be empty');
78 # This will fail if nothing is indexed, but at this point we should have everything setup correctly
79 my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="biblionumber"]');
80 my $biblionumber1 = $checkboxes[0]->get_value();
81 my $biblionumber3 = $checkboxes[2]->get_value();
82 my $biblionumber5 = $checkboxes[4]->get_value();
84 $driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber1.'"]')->click;
85 my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
86 is( $basket_count_elt->get_text(),
87 1, 'One element should have been added to the cart' );
89 $driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber3.'"]')->click;
90 $driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber5.'"]')->click;
91 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
92 is( $basket_count_elt->get_text(),
93 3, '3 elements should have been added to the cart' );
95 $driver->find_element('//a[@class="btn btn-link btn-sm remove cartRemove cartR'.$biblionumber3.'"]')->click;
96 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
97 is( $basket_count_elt->get_text(),
98 2, '1 element should have been removed from the cart' );
101 $driver->set_window_size($window_size->{'height'}, $window_size->{'width'});
103 $mock_zebra->cleanup;
107 C4::Context->set_preference('SearchEngine', $SearchEngine_value);
108 $mock_zebra->cleanup if $mock_zebra;