|
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 929-932
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents with Inclu
Link Here
|
| 929 |
is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); |
930 |
is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); |
| 930 |
}; |
931 |
}; |
| 931 |
|
932 |
|
|
|
933 |
subtest 'marc_records_to_documents should set the "available" field' => sub { |
| 934 |
plan tests => 8; |
| 935 |
|
| 936 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
| 937 |
my $dbh = C4::Context->dbh; |
| 938 |
|
| 939 |
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); |
| 940 |
$se->noop('_foreach_mapping'); |
| 941 |
|
| 942 |
my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); |
| 943 |
|
| 944 |
# sort_fields will call this and use the actual db values unless we call it first |
| 945 |
$see->get_elasticsearch_mappings(); |
| 946 |
|
| 947 |
my $marc_record_1 = MARC::Record->new(); |
| 948 |
$marc_record_1->leader(' cam 22 a 4500'); |
| 949 |
$marc_record_1->append_fields( |
| 950 |
MARC::Field->new('245', '', '', a => 'Title'), |
| 951 |
); |
| 952 |
my ($biblionumber) = C4::Biblio::AddBiblio($marc_record_1, '', { defer_marc_save => 1 }); |
| 953 |
|
| 954 |
my $docs = $see->marc_records_to_documents([$marc_record_1]); |
| 955 |
is_deeply($docs->[0]->{available}, \0, 'a biblio without items is not available'); |
| 956 |
|
| 957 |
my $item = Koha::Item->new({ |
| 958 |
biblionumber => $biblionumber, |
| 959 |
})->store(); |
| 960 |
|
| 961 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 962 |
is_deeply($docs->[0]->{available}, \1, 'a biblio with one item that has no particular status is available'); |
| 963 |
|
| 964 |
$item->notforloan(1)->store(); |
| 965 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 966 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is "notforloan" is not available'); |
| 967 |
|
| 968 |
$item->set({ notforloan => 0, onloan => '2022-03-03' })->store(); |
| 969 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 970 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is on loan is not available'); |
| 971 |
|
| 972 |
$item->set({ onloan => undef, withdrawn => 1 })->store(); |
| 973 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 974 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is withdrawn is not available'); |
| 975 |
|
| 976 |
$item->set({ withdrawn => 0, itemlost => 1 })->store(); |
| 977 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 978 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is lost is not available'); |
| 979 |
|
| 980 |
$item->set({ itemlost => 0, damaged => 1 })->store(); |
| 981 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 982 |
is_deeply($docs->[0]->{available}, \0, 'a biblio with one item that is damaged is not available'); |
| 983 |
|
| 984 |
my $item2 = Koha::Item->new({ |
| 985 |
biblionumber => $biblionumber, |
| 986 |
})->store(); |
| 987 |
$docs = $see->marc_records_to_documents([$marc_record_1]); |
| 988 |
is_deeply($docs->[0]->{available}, \1, 'a biblio with at least one item that has no particular status is available'); |
| 989 |
}; |
| 990 |
|
| 932 |
$schema->storage->txn_rollback; |
991 |
$schema->storage->txn_rollback; |
| 933 |
- |
|
|