Koha/t/db_dependent/Items/GetHostItemsInfo.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

41 lines
1.5 KiB
Perl

use Modern::Perl;
use Test::More tests => 1;
use t::lib::Mocks;
use t::lib::TestBuilder;
use C4::Items;
use Koha::Database;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
subtest 'GetHostItemsInfo' => sub {
plan tests => 3;
my $builder = t::lib::TestBuilder->new;
my $bib1 = $builder->build_sample_biblio;
my $itm1 = $builder->build_sample_item({ biblionumber => $bib1->biblionumber });
my $itm2 = $builder->build_sample_item({ biblionumber => $bib1->biblionumber });
my $marc = MARC::Record->new;
$marc->append_fields(
MARC::Field->new( '461', '', '', 0 => $bib1->biblionumber, 9 => $itm1->itemnumber ),
MARC::Field->new( '773', '', '', 0 => $bib1->biblionumber, 9 => $itm1->itemnumber ),
MARC::Field->new( '773', '', '', 0 => $bib1->biblionumber, 9 => $itm2->itemnumber ),
);
t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
t::lib::Mocks::mock_preference('EasyAnalyticalRecords', 0);
my @a = C4::Items::GetHostItemsInfo( $marc );
is( @a, 0, 'GetHostItemsInfo returns empty list when pref is disabled' );
t::lib::Mocks::mock_preference('EasyAnalyticalRecords', 1);
@a = C4::Items::GetHostItemsInfo( $marc );
is( @a, 2, 'GetHostItemsInfo returns two items for MARC21' );
t::lib::Mocks::mock_preference('marcflavour', 'UNIMARC');
@a = C4::Items::GetHostItemsInfo( $marc );
is( @a, 1, 'GetHostItemsInfo returns one item for UNIMARC' );
};
$schema->storage->txn_rollback;