4 use Test::More tests => 3;
5 use t::lib::TestBuilder;
6 use C4::Items qw( GetMarcItem );
8 use Koha::AuthorisedValues;
12 use_ok('Koha::Z3950Responder');
13 use_ok('Koha::Z3950Responder::Session');
16 my $builder = t::lib::TestBuilder->new;
17 my $schema = Koha::Database->new->schema;
19 $schema->storage->txn_begin;
21 # Clear the cache, before and after
22 Koha::Caches->get_instance->flush_all;
24 subtest 'add_item_status' => sub {
28 # This time we are sustituting some values
30 my $available = Koha::AuthorisedValues->find({ category => 'Z3950_STATUS', authorised_value => 'AVAILABLE' });
32 $available = $builder->build_object({
33 class => 'Koha::AuthorisedValues',
35 category => 'Z3950_STATUS',
36 authorised_value => 'AVAILABLE',
37 lib => "Free as a bird"
41 my $available_status = $available->lib;
43 my $damaged = Koha::AuthorisedValues->find({ category => 'Z3950_STATUS', authorised_value => 'DAMAGED' });
45 $damaged = $builder->build_object({
46 class => 'Koha::AuthorisedValues',
48 category => 'Z3950_STATUS',
49 authorised_value => 'DAMAGED',
50 lib => "Borked completely"
54 my $damaged_status = $damaged->lib;
56 ## FIRST ITEM HAS ALL THE STATUSES ##
57 my $item_1 = $builder->build_sample_item(
59 onloan => '2017-07-07',
66 my $item_marc_1 = C4::Items::GetMarcItem( $item_1->biblionumber, $item_1->itemnumber );
67 my $item_field_1 = scalar $item_marc_1->field('952');
68 $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->itemnumber } });
71 source => 'Branchtransfer',
73 itemnumber => $item_1->itemnumber,
75 datecancelled => undef,
82 ## SECOND ITEM HAS NO STATUSES ##
83 my $item_2 = $builder->build_sample_item;
84 my $item_marc_2 = C4::Items::GetMarcItem( $item_2->biblionumber, $item_2->itemnumber );
85 my $item_field_2 = scalar $item_marc_2->field('952');
88 # Create the responder
89 my $args={ PEER_NAME => 'PEER'};
90 my $zR = Koha::Z3950Responder->new({add_item_status_subfield => 'k'});
91 $zR->init_handler($args);
93 $args->{HANDLE}->add_item_status($item_field_1);
94 is($item_field_1->subfield('k'),"Checked Out, Lost, Not for Loan, $damaged_status, Withdrawn, In Transit, On Hold","All statuses added in one field as expected");
96 $args->{HANDLE}->add_item_status($item_field_2);
97 is($item_field_2->subfield('k'),"$available_status","Available status is '$available_status' added as expected");
101 # Clear the cache, before and after
102 Koha::Caches->get_instance->flush_all;
104 $schema->storage->txn_rollback;