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 => 3;
27 use t::lib::TestBuilder;
29 eval { require Selenium::Remote::Driver; };
30 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
32 my $s = t::lib::Selenium->new;
34 my $driver = $s->driver;
35 my $opac_base_url = $s->opac_base_url;
36 my $base_url = $s->base_url;
37 my $builder = t::lib::TestBuilder->new;
39 # It seems that we do not have enough records indexed with ES
40 my $SearchEngine_value = C4::Context->preference('SearchEngine');
41 C4::Context->set_preference('SearchEngine', 'Zebra');
43 my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
44 C4::Context->set_preference('AudioAlerts', '1');
47 subtest 'OPAC - borrowernumber and branchcode as html attributes' => sub {
50 my $patron = $builder->build_object(
51 { class => 'Koha::Patrons', value => { flags => 1 } } );
52 my $password = Koha::AuthUtils::generate_password();
53 $patron->update_password( $patron->userid, $password );
54 $s->opac_auth( $patron->userid, $password );
55 my $elt = $driver->find_element('//span[@class="loggedinusername"]');
56 is( $elt->get_attribute('data-branchcode'), $patron->library->branchcode,
57 "Since bug 20921 span.loggedinusername should contain data-branchcode"
59 is( $elt->get_attribute('data-borrowernumber'), $patron->borrowernumber,
60 "Since bug 20921 span.loggedinusername should contain data-borrowernumber"
62 push @cleanup, $patron, $patron->category, $patron->library;
65 subtest 'OPAC - Remove from cart' => sub {
68 $driver->get( $opac_base_url . "opac-search.pl?q=d" );
70 # A better way to do that would be to modify the way we display the basket count
71 # We should show/hide the count instead or recreate the node
72 my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
73 is( scalar(@basket_count_elts), 0, 'Basket should be empty');
75 # This will fail if nothing is indexed, but at this point we should have everything setup correctly
76 my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="biblionumber"]');
77 my $biblionumber1 = $checkboxes[0]->get_value();
78 my $biblionumber3 = $checkboxes[2]->get_value();
79 my $biblionumber5 = $checkboxes[4]->get_value();
81 $driver->find_element('//a[@class="addtocart cart'.$biblionumber1.'"]')->click;
82 my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
83 is( $basket_count_elt->get_text(),
84 1, 'One element should have been added to the cart' );
86 $driver->find_element('//a[@class="addtocart cart'.$biblionumber3.'"]')->click;
87 $driver->find_element('//a[@class="addtocart cart'.$biblionumber5.'"]')->click;
88 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
89 is( $basket_count_elt->get_text(),
90 3, '3 elements should have been added to the cart' );
92 $driver->find_element('//a[@class="cartRemove cartR'.$biblionumber3.'"]')->click;
93 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
94 is( $basket_count_elt->get_text(),
95 2, '1 element should have been removed from the cart' );
98 subtest 'Play sound on the circulation page' => sub {
101 my $builder = t::lib::TestBuilder->new;
102 my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
104 my $mainpage = $s->base_url . q|mainpage.pl|;
105 $driver->get($mainpage . q|?logout.x=1|);
106 like( $driver->get_title(), qr(Log in to Koha), );
109 $driver->get( $base_url . "/circ/circulation.pl?borrowernumber=" . $patron->borrowernumber );
111 my $audio_node = $driver->find_element('//span[@id="audio-alert"]/audio[@src="/intranet-tmpl/prog/sound/beep.ogg"]');
113 push @cleanup, $patron, $patron->category, $patron->library;
117 C4::Context->preference('SearchEngine', $SearchEngine_value);
118 C4::Context->preference('AudioAlerts', $AudioAlerts_value);
119 $_->delete for @cleanup;