Jonathan Druart
54a1c5433b
The following test is failing: | # Failed test 'OPAC - Remove from cart' | # at t/db_dependent/selenium/regressions.t line 132. | Can't call method "get_value" on an undefined value at t/db_dependent/selenium/regressions.t line 110. | # Looks like your test exited with 2 just after 3. | [12:14:08] t/db_dependent/selenium/regressions.t We are dependind on the search engine and the records in the DB but the installer is not inserting any records. This patch is suggesting to reuse the code from search_utf8 (and so make it reusable first) for remove_from_cart test. This code is mocking the Zebra index with some MARC data and so the search will return results. We will finally be able to click on the add to/remove from cart links. Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
117 lines
4.3 KiB
Perl
Executable file
117 lines
4.3 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
use File::Basename qw(dirname );
|
|
|
|
use Test::WWW::Mechanize;
|
|
use Test::More tests => 1;
|
|
use Test::MockModule;
|
|
|
|
use C4::Context;
|
|
use t::lib::Mocks;
|
|
use t::lib::Selenium;
|
|
use t::lib::TestBuilder;
|
|
use t::lib::Mocks;
|
|
use t::lib::Mocks::Zebra;
|
|
|
|
eval { require Selenium::Remote::Driver; };
|
|
skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
|
|
|
|
my $s = t::lib::Selenium->new;
|
|
|
|
my $driver = $s->driver;
|
|
my $opac_base_url = $s->opac_base_url;
|
|
my $base_url = $s->base_url;
|
|
my $builder = t::lib::TestBuilder->new;
|
|
|
|
my $SearchEngine_value = C4::Context->preference('SearchEngine');
|
|
C4::Context->set_preference('SearchEngine', 'Zebra');
|
|
|
|
my $mock_zebra = t::lib::Mocks::Zebra->new(
|
|
{
|
|
koha_conf => $ENV{KOHA_CONF},
|
|
user => $ENV{KOHA_USER},
|
|
password => $ENV{KOHA_PASS},
|
|
intranet => $ENV{KOHA_INTRANET_URL},
|
|
opac => $ENV{KOHA_OPAC_URL},
|
|
}
|
|
);
|
|
|
|
subtest 'OPAC - Remove from cart' => sub {
|
|
plan tests => 22;
|
|
|
|
#-------------------------------- Test with greek and corean chars;
|
|
# launch the zebra saerch process
|
|
$mock_zebra->launch_zebra;
|
|
# launch the zebra index process
|
|
$mock_zebra->launch_indexer;
|
|
|
|
my $marcflavour = C4::Context->preference('marcflavour') || 'MARC21';
|
|
|
|
my $testdir = File::Spec->rel2abs( dirname(__FILE__) . '/../www/');
|
|
my $file =
|
|
$marcflavour eq 'UNIMARC'
|
|
? "$testdir/data/unimarcutf8record.mrc"
|
|
: "$testdir/data/marc21utf8record.mrc";
|
|
|
|
my $batch_id = $mock_zebra->load_records($file);
|
|
|
|
# We need to prevent scrolling to prevent the floating toolbar from overlapping buttons we are testing
|
|
my $window_size = $driver->get_window_size();
|
|
$driver->set_window_size(1920,10800);
|
|
|
|
$driver->get( $opac_base_url . "opac-search.pl?q=d" );
|
|
|
|
# A better way to do that would be to modify the way we display the basket count
|
|
# We should show/hide the count instead or recreate the node
|
|
my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
|
|
is( scalar(@basket_count_elts), 0, 'Basket should be empty');
|
|
|
|
# This will fail if nothing is indexed, but at this point we should have everything setup correctly
|
|
my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="biblionumber"]');
|
|
my $biblionumber1 = $checkboxes[0]->get_value();
|
|
my $biblionumber3 = $checkboxes[2]->get_value();
|
|
my $biblionumber5 = $checkboxes[4]->get_value();
|
|
|
|
$driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber1.'"]')->click;
|
|
my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
|
|
is( $basket_count_elt->get_text(),
|
|
1, 'One element should have been added to the cart' );
|
|
|
|
$driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber3.'"]')->click;
|
|
$driver->find_element('//a[@class="btn btn-link btn-sm addtocart cart cart'.$biblionumber5.'"]')->click;
|
|
$basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
|
|
is( $basket_count_elt->get_text(),
|
|
3, '3 elements should have been added to the cart' );
|
|
|
|
$driver->find_element('//a[@class="btn btn-link btn-sm remove cartRemove cartR'.$biblionumber3.'"]')->click;
|
|
$basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
|
|
is( $basket_count_elt->get_text(),
|
|
2, '1 element should have been removed from the cart' );
|
|
|
|
# Reset window size
|
|
$driver->set_window_size($window_size->{'height'}, $window_size->{'width'});
|
|
|
|
$mock_zebra->clean_records($batch_id);
|
|
$mock_zebra->cleanup;
|
|
};
|
|
|
|
END {
|
|
C4::Context->set_preference('SearchEngine', $SearchEngine_value);
|
|
$mock_zebra->cleanup;
|
|
};
|