Bug 26157: Hide expected DBI warnings from tests
[koha.git] / t / db_dependent / XSLT.t
blob2d9e9db1b3206e866ee8ddd54954908d2ddc7e0d
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use Test::More tests => 2;
21 use Test::Warn;
22 use t::lib::TestBuilder;
23 use t::lib::Mocks;
25 use Koha::ItemTypes;
27 BEGIN {
28 use_ok('C4::XSLT');
31 my $schema = Koha::Database->new->schema;
32 my $builder = t::lib::TestBuilder->new;
34 $schema->storage->txn_begin;
36 subtest 'buildKohaItemsNamespace status tests' => sub {
37 plan tests => 13;
38 my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
39 my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
40 my $item = $builder->build_sample_item({ itype => $itype->itemtype });
41 $item->biblioitem->itemtype($itemtype->itemtype)->store;
43 my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
44 like($xml,qr{<status>available</status>},"Item is available when no other status applied");
46 # notforloan
49 t::lib::Mocks::mock_preference('item-level_itypes', 0);
50 $item->notforloan(0)->store;
51 Koha::ItemTypes->find($item->itype)->notforloan(0)->store;
52 Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store;
53 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
54 like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value");
56 t::lib::Mocks::mock_preference('item-level_itypes', 1);
57 Koha::ItemTypes->find($item->itype)->notforloan(1)->store;
58 Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store;
59 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
60 like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value");
61 Koha::ItemTypes->find($item->itype)->notforloan(0)->store;
63 my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib;
64 $item->notforloan(-1)->store;
65 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
66 like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value");
67 like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value");
69 $item->notforloan(1)->store;
70 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
71 like($xml,qr{<status>reference</status>},"reference if positive notforloan value");
74 $item->onloan('2001-01-01')->store;
75 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
76 like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan");
78 $item->withdrawn(1)->store;
79 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
80 like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out");
82 $item->itemlost(1)->store;
83 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
84 like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn");
86 $item->damaged(1)->store;
87 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
88 like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost");
90 $builder->build({ source => "Branchtransfer", value => {
91 itemnumber => $item->itemnumber,
92 datearrived => undef,
94 });
95 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
96 like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged");
98 my $hold = $builder->build_object({ class => 'Koha::Holds', value => {
99 biblionumber => $item->biblionumber,
100 itemnumber => $item->itemnumber,
101 found => 'W',
102 priority => 0,
105 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
106 like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit");
108 $builder->build({ source => "TmpHoldsqueue", value => {
109 itemnumber => $item->itemnumber
112 $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
113 like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all");
118 $schema->storage->txn_rollback;