Bug 26057: (QA follow-up) Fix Biblios, Reserves, Z3950Responder and XSLT tests
[koha.git] / t / db_dependent / Koha / Z3950Responder / Session2.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use Test::More tests => 3;
5 use t::lib::TestBuilder;
6 use C4::Items;
7
8 use Koha::Caches;
9
10 BEGIN {
11     use_ok('Koha::Z3950Responder');
12     use_ok('Koha::Z3950Responder::Session');
13 }
14
15 my $builder = t::lib::TestBuilder->new;
16 my $schema  = Koha::Database->new->schema;
17
18 $schema->storage->txn_begin;
19
20 # Clear the cache, before and after
21 Koha::Caches->get_instance->flush_all;
22
23 subtest 'add_item_status' => sub {
24
25     plan tests => 2;
26
27     # This time we are sustituting some values
28     $builder->schema->resultset( 'AuthorisedValue' )->delete_all();
29     $builder->build({
30         source => 'AuthorisedValue',
31         value => {
32             category => 'Z3950_STATUS',
33             authorised_value => 'AVAILABLE',
34             lib => "Free as a bird"
35         }
36     });
37     $builder->build({
38         source => 'AuthorisedValue',
39         value => {
40             category => 'Z3950_STATUS',
41             authorised_value => 'DAMAGED',
42             lib => "Borked completely"
43         }
44     });
45
46     ## FIRST ITEM HAS ALL THE STATUSES ##
47     my $item_1 = $builder->build_sample_item(
48         {
49             onloan     => '2017-07-07',
50             itemlost   => 1,
51             notforloan => 1,
52             damaged    => 1,
53             withdrawn  => 1,
54         }
55     );
56     my $item_marc_1 = C4::Items::GetMarcItem( $item_1->biblionumber, $item_1->itemnumber );
57     my $item_field_1 = scalar $item_marc_1->field('952');
58     $builder->build({ source => 'Reserve', value=> { itemnumber => $item_1->itemnumber } });
59     $builder->build(
60         {
61             source => 'Branchtransfer',
62             value  => {
63                 itemnumber    => $item_1->itemnumber,
64                 datearrived   => undef,
65                 datecancelled => undef
66             }
67         }
68     );
69     ## END FIRST ITEM ##
70
71     ## SECOND ITEM HAS NO STATUSES ##
72     my $item_2 = $builder->build_sample_item;
73     my $item_marc_2 = C4::Items::GetMarcItem( $item_2->biblionumber, $item_2->itemnumber );
74     my $item_field_2 = scalar $item_marc_2->field('952');
75     ## END SECOND ITEM ##
76
77     # Create the responder
78     my $args={ PEER_NAME => 'PEER'};
79     my $zR = Koha::Z3950Responder->new({add_item_status_subfield => 'k'});
80     $zR->init_handler($args);
81
82     $args->{HANDLE}->add_item_status($item_field_1);
83     is($item_field_1->subfield('k'),"Checked Out, Lost, Not for Loan, Borked completely, Withdrawn, In Transit, On Hold","All statuses added in one field as expected");
84
85     $args->{HANDLE}->add_item_status($item_field_2);
86     is($item_field_2->subfield('k'),'Free as a bird',"Available status is 'Free as a bird' added as expected");
87
88 };
89
90 # Clear the cache, before and after
91 Koha::Caches->get_instance->flush_all;
92
93 $schema->storage->txn_rollback;