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;
26 use C4::Biblio qw( AddBiblio );
30 use t::lib::TestBuilder;
32 eval { require Selenium::Remote::Driver; };
33 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
35 my $s = t::lib::Selenium->new;
37 my $driver = $s->driver;
38 my $opac_base_url = $s->opac_base_url;
39 my $base_url = $s->base_url;
41 # It seems that we do not have enough records indexed with ES
42 my $SearchEngine_value = C4::Context->preference('SearchEngine');
43 C4::Context->set_preference('SearchEngine', 'Zebra');
45 my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
46 C4::Context->set_preference('AudioAlerts', '1');
50 subtest 'OPAC - Remove from cart' => sub {
53 $driver->get( $opac_base_url . "opac-search.pl?q=d" );
55 # A better way to do that would be to modify the way we display the basket count
56 # We should show/hide the count instead or recreate the node
57 my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
58 is( scalar(@basket_count_elts), 0, 'Basket should be empty');
60 # This will fail if nothing is indexed, but at this point we should have everything setup correctly
61 my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="biblionumber"]');
62 my $biblionumber1 = $checkboxes[0]->get_value();
63 my $biblionumber3 = $checkboxes[2]->get_value();
64 my $biblionumber5 = $checkboxes[4]->get_value();
66 $driver->find_element('//a[@class="addtocart cart'.$biblionumber1.'"]')->click;
67 my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
68 is( $basket_count_elt->get_text(),
69 1, 'One element should have been added to the cart' );
71 $driver->find_element('//a[@class="addtocart cart'.$biblionumber3.'"]')->click;
72 $driver->find_element('//a[@class="addtocart cart'.$biblionumber5.'"]')->click;
73 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
74 is( $basket_count_elt->get_text(),
75 3, '3 elements should have been added to the cart' );
77 $driver->find_element('//a[@class="cartRemove cartR'.$biblionumber3.'"]')->click;
78 $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
79 is( $basket_count_elt->get_text(),
80 2, '1 element should have been removed from the cart' );
83 subtest 'Play sound on the circulation page' => sub {
86 my $builder = t::lib::TestBuilder->new;
87 my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
89 my $mainpage = $s->base_url . q|mainpage.pl|;
90 $driver->get($mainpage . q|?logout.x=1|);
91 like( $driver->get_title(), qr(Log in to Koha), );
94 $driver->get( $base_url . "/circ/circulation.pl?borrowernumber=" . $patron->borrowernumber );
96 my $audio_node = $driver->find_element('//span[@id="audio-alert"]/audio[@src="/intranet-tmpl/prog/sound/beep.ogg"]');
98 push @data_to_cleanup, $patron, $patron->category, $patron->library;
101 subtest 'Display circulation table correctly' => sub {
104 my $builder = t::lib::TestBuilder->new;
105 my $library = $builder->build_object( { class => 'Koha::Libraries' } );
106 my $patron = $builder->build_object(
108 class => 'Koha::Patrons',
109 value => { branchcode => $library->branchcode, flags => 0 }
113 my ( $biblionumber, $biblioitemnumber ) = add_biblio();
114 my $item = $builder->build_object(
116 class => 'Koha::Items',
118 biblionumber => $biblionumber,
119 homebranch => $library->branchcode,
120 holdingbranch => $library->branchcode,
127 my $context = Test::MockModule->new('C4::Context');
131 return { branch => $library->branchcode };
135 C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
137 my $mainpage = $s->base_url . q|mainpage.pl|;
138 $driver->get($mainpage . q|?logout.x=1|);
141 $driver->get( $base_url
142 . "/circ/circulation.pl?borrowernumber="
143 . $patron->borrowernumber );
145 # Display the table clicking on the "Show checkouts" button
146 $driver->find_element('//a[@id="issues-table-load-now-button"]')->click;
148 my @thead_th = $driver->find_elements('//table[@id="issues-table"]/thead/tr/th');
149 my $thead_length = 0;
150 $thead_length += $_->get_attribute('colspan') || 0 for @thead_th;
152 my @tfoot_td = $driver->find_elements('//table[@id="issues-table"]/tfoot/tr/td');
153 my $tfoot_length = 0;
154 $tfoot_length += $_->get_attribute('colspan') || 0 for @tfoot_td;
156 my @tbody_td = $driver->find_elements('//table[@id="issues-table"]/tbody/tr/td');
157 my $tbody_length = 0;
158 $tbody_length += $_->get_attribute('colspan') || 0 for @tbody_td;
160 is( $thead_length == $tfoot_length && $tfoot_length == $tbody_length,
161 1, "Checkouts table must be correctly aligned" )
163 "thead: $thead_length ; tfoot: $tfoot_length ; tbody: $tbody_length");
165 push @cleanup, $patron->checkouts, $item->biblio, $item, $patron,
166 $patron->category, $library;
170 C4::Context->preference('SearchEngine', $SearchEngine_value);
171 C4::Context->preference('AudioAlerts', $AudioAlerts_value);
172 $_->delete for @data_to_cleanup;
176 my ($title, $author) = @_;
178 my $marcflavour = C4::Context->preference('marcflavour');
180 my $biblio = MARC::Record->new();
182 $tag = $marcflavour eq 'UNIMARC' ? '200' : '245';
183 $biblio->append_fields(
184 MARC::Field->new($tag, ' ', ' ', a => $title || 'a title'),
187 ($tag, $code) = $marcflavour eq 'UNIMARC' ? (200, 'f') : (100, 'a');
188 $biblio->append_fields(
189 MARC::Field->new($tag, ' ', ' ', $code => $author || 'an author'),
192 return C4::Biblio::AddBiblio($biblio, '');