Koha/t/db_dependent/Reserves/ReserveSlip.t
Jonathan Druart 9c9dddeaa4 Bug 26250: Fix tests when SearchEngine=Elastic
Most of the time the tests are failing because the item is not created
correctly (missing biblio and/or biblioitem).
The usual error is:
 t/db_dependent/selenium/regressions.t ..... 5/5 Can't call method "leader" on an undefined value at /kohadevbox/koha/Koha/SearchEngine/Elasticsearch.pm line 534.

In this patch we are making sure $builder->build({ source => 'Item' })
is replace with $builder->build_sample_item

Test plan:
Turn on Elastic and confirm that all the tests pass!

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-08-31 16:10:26 +02:00

116 lines
3.3 KiB
Perl

#!/usr/bin/perl
# Copyright 2016 Oslo Public Library
#
# 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 Test::More tests => 3;
use t::lib::TestBuilder;
use C4::Reserves qw( ReserveSlip );
use C4::Context;
use Koha::Database;
use Koha::Holds;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $dbh = C4::Context->dbh;
$dbh->do(q|DELETE FROM letter|);
$dbh->do(q|DELETE FROM reserves|);
my $builder = t::lib::TestBuilder->new();
my $library = $builder->build(
{
source => 'Branch',
}
);
my $patron = $builder->build(
{
source => 'Borrower',
value => {
branchcode => $library->{branchcode},
},
}
);
my $biblio = $builder->build_sample_biblio;
my $item1 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $library->{branchcode},
}
);
my $item2 = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $library->{branchcode},
}
);
my $hold1 = Koha::Hold->new(
{
biblionumber => $biblio->biblionumber,
itemnumber => $item1->itemnumber,
waitingdate => '2000-01-01',
borrowernumber => $patron->{borrowernumber},
branchcode => $library->{branchcode},
}
)->store;
my $hold2 = Koha::Hold->new(
{
biblionumber => $biblio->biblionumber,
itemnumber => $item2->itemnumber,
waitingdate => '2000-01-01',
borrowernumber => $patron->{borrowernumber},
branchcode => $library->{branchcode},
}
)->store;
my $letter = $builder->build(
{
source => 'Letter',
value => {
module => 'circulation',
code => 'HOLD_SLIP',
lang => 'default',
branchcode => $library->{branchcode},
content => 'Hold found for <<borrowers.firstname>>: Please pick up <<biblio.title>> with barcode <<items.barcode>> at <<branches.branchcode>>.',
message_transport_type => 'email',
},
}
);
is ( ReserveSlip(), undef, "No hold slip returned if invalid or undef borrowernumber and/or biblionumber" );
is ( ReserveSlip({
branchcode => $library->{branchcode},
reserve_id => $hold1->reserve_id,
})->{code},
'HOLD_SLIP', "Get a hold slip from library, patron and biblio" );
is (ReserveSlip({
branchcode => $library->{branchcode},
reserve_id => $hold1->reserve_id,
})->{content},
sprintf( "Hold found for %s: Please pick up %s with barcode %s at %s.", $patron->{firstname}, $biblio->title, $item1->barcode, $library->{branchcode}),"Hold slip contains correctly parsed content");
$schema->storage->txn_rollback;
1;