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;
25 use t::lib::TestBuilder;
27 eval { require Selenium::Remote::Driver; };
28 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
30 my $s = t::lib::Selenium->new;
32 my $driver = $s->driver;
33 my $opac_base_url = $s->opac_base_url;
34 my $base_url = $s->base_url;
36 # It seems that we do not have enough records indexed with ES
37 my $SearchEngine_value = C4::Context->preference('SearchEngine');
38 C4::Context->set_preference('SearchEngine', 'Zebra');
40 my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
41 C4::Context->set_preference('AudioAlerts', '1');
45 subtest 'OPAC - Remove from cart' => sub {
48 $driver->get( $opac_base_url . "opac-search.pl?q=d" );
50 # A better way to do that would be to modify the way we display the basket count
51 # We should show/hide the count instead or recreate the node
52 my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
53 is( scalar(@basket_count_elts), 0, 'Basket should be empty');
55 # This will fail if nothing is indexed, but at this point we should have everything setup correctly
56 my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="biblionumber"]');
57 my $biblionumber1 = $checkboxes[0]->get_value();
58 my $biblionumber3 = $checkboxes[2]->get_value();
59 my $biblionumber5 = $checkboxes[4]->get_value();
61 $driver->find_element('//a[@class="addtocart cart'.$biblionumber1.'"]')->click;
62 my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
63 is( $basket_count_elt->get_text(),
64 1, 'One element should have been added to the cart' );
66 $driver->find_element('//a[@class="addtocart cart'.$biblionumber3.'"]')->click;
67 $driver->find_element('//a[@class="addtocart cart'.$biblionumber5.'"]')->click;
68 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
69 is( $basket_count_elt->get_text(),
70 3, '3 elements should have been added to the cart' );
72 $driver->find_element('//a[@class="cartRemove cartR'.$biblionumber3.'"]')->click;
73 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
74 is( $basket_count_elt->get_text(),
75 2, '1 element should have been removed from the cart' );
78 subtest 'Play sound on the circulation page' => sub {
81 my $builder = t::lib::TestBuilder->new;
82 my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
84 my $mainpage = $s->base_url . q|mainpage.pl|;
85 $driver->get($mainpage);
86 like( $driver->get_title(), qr(Log in to Koha), );
89 $driver->get( $base_url . "/circ/circulation.pl?borrowernumber=" . $patron->borrowernumber );
91 my $audio_node = $driver->find_element('//span[@id="audio-alert"]/audio[@src="/intranet-tmpl/prog/sound/beep.ogg"]');
93 push @data_to_cleanup, $patron, $patron->category, $patron->library;
97 C4::Context->preference('SearchEngine', $SearchEngine_value);
98 C4::Context->preference('AudioAlerts', $AudioAlerts_value);
99 $_->delete for @data_to_cleanup;