|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 7; |
20 |
use Test::More tests => 8; |
| 21 |
use Test::Exception; |
21 |
use Test::Exception; |
| 22 |
|
22 |
|
| 23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
|
Lines 30-35
use Try::Tiny;
Link Here
|
| 30 |
use List::Util qw( any ); |
30 |
use List::Util qw( any ); |
| 31 |
|
31 |
|
| 32 |
use C4::AuthoritiesMarc qw( AddAuthority ); |
32 |
use C4::AuthoritiesMarc qw( AddAuthority ); |
|
|
33 |
use C4::Biblio; |
| 33 |
|
34 |
|
| 34 |
use Koha::SearchEngine::Elasticsearch; |
35 |
use Koha::SearchEngine::Elasticsearch; |
| 35 |
use Koha::SearchEngine::Elasticsearch::Search; |
36 |
use Koha::SearchEngine::Elasticsearch::Search; |
|
Lines 972-975
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents with Inclu
Link Here
|
| 972 |
is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); |
973 |
is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); |
| 973 |
}; |
974 |
}; |
| 974 |
|
975 |
|
|
|
976 |
subtest 'marc_records_to_documents should set the "available" field' => sub { |
| 977 |
plan tests => 8; |
| 978 |
|
| 979 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
| 980 |
my $dbh = C4::Context->dbh; |
| 981 |
|
| 982 |
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); |
| 983 |
$se->noop('_foreach_mapping'); |
| 984 |
|
| 985 |
my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); |
| 986 |
|
| 987 |
# sort_fields will call this and use the actual db values unless we call it first |
| 988 |
$see->get_elasticsearch_mappings(); |
| 989 |
|
| 990 |
my $marc_record_1 = MARC::Record->new(); |
| 991 |
$marc_record_1->leader(' cam 22 a 4500'); |
| 992 |
$marc_record_1->append_fields( |
| 993 |
MARC::Field->new('245', '', '', a => 'Title'), |
| 994 |
); |
| 995 |
my ($biblionumber) = C4::Biblio::AddBiblio($marc_record_1, '', { defer_marc_save => 1 }); |
| 996 |
|
| 997 |
my $docs = $see->marc_records_to_documents([$marc_record_1]); |
| 998 |
is_deeply($docs->[0]->{available}, \0, 'a biblio without items is not available'); |
| 999 |
|
| 1000 |
my $item = Koha::Item->new({ |
| 1001 |
biblionumber => $biblionumber, |
| 1002 |
})->store(); |
| 1003 |
|
| 1004 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1005 |
is_deeply($docs->[0]->{available}, \1, 'a biblio with one item that has no particular status is available'); |
| 1006 |
|
| 1007 |
$item->notforloan(1)->store(); |
| 1008 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1009 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is "notforloan" is not available'); |
| 1010 |
|
| 1011 |
$item->set({ notforloan => 0, onloan => '2022-03-03' })->store(); |
| 1012 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1013 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is on loan is not available'); |
| 1014 |
|
| 1015 |
$item->set({ onloan => undef, withdrawn => 1 })->store(); |
| 1016 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1017 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is withdrawn is not available'); |
| 1018 |
|
| 1019 |
$item->set({ withdrawn => 0, itemlost => 1 })->store(); |
| 1020 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1021 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is lost is not available'); |
| 1022 |
|
| 1023 |
$item->set({ itemlost => 0, damaged => 1 })->store(); |
| 1024 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1025 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is damaged is not available'); |
| 1026 |
|
| 1027 |
my $item2 = Koha::Item->new({ |
| 1028 |
biblionumber => $biblionumber, |
| 1029 |
})->store(); |
| 1030 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 1031 |
is_deeply($docs->[0]->{available}, \1, 'a biblio with at least one item that has no particular status is available'); |
| 1032 |
}; |
| 1033 |
|
| 975 |
$schema->storage->txn_rollback; |
1034 |
$schema->storage->txn_rollback; |
| 976 |
- |
|
|