Koha/t/db_dependent/XSLT.t
Marcel de Rooy 07741c30b6 Bug 21260: Introduce local pref to affect status grouping
Introducing a local preference Available_NFL to control which not for
loan statuses are considered to be 'available for reference'.
Standard value is '1|2' which comes down to the former >0 when using
the initial Koha defaults.

Test plan:
[1] Pick a biblio with an available item A, an item B with notforloan 1,
    an item C with notforloan 2 and two damaged items. (Former patch.)
    Include it in a OPAC search. You should see:
        Available: A. Reference: B, C. Not-available: Damaged(2).
[2] Add local pref Available_NFL with value '1'. Repeat the search.
    You should see now:
        Available: A. Reference: B. Not-available: S.C.(1), Damaged(2).
    [where S.C. stands for Staff Collection]
[3] Run test t/db_dependent/XSLT.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: ava li <rubyli208@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-04-01 17:58:49 +02:00

127 lines
5.2 KiB
Perl
Executable file

#!/usr/bin/perl
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 2;
use Test::Warn;
use t::lib::TestBuilder;
use t::lib::Mocks;
use Koha::ItemTypes;
BEGIN {
use_ok('C4::XSLT');
}
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
$schema->storage->txn_begin;
subtest 'buildKohaItemsNamespace status tests' => sub {
plan tests => 14;
t::lib::Mocks::mock_preference('Available_NFL', '1|2');
my $itype = $builder->build_object({ class => 'Koha::ItemTypes' });
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
my $item = $builder->build_sample_item({ itype => $itype->itemtype });
$item->biblioitem->itemtype($itemtype->itemtype)->store;
my $xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>available</status>},"Item is available when no other status applied");
# notforloan
{
t::lib::Mocks::mock_preference('item-level_itypes', 0);
$item->notforloan(0)->store;
Koha::ItemTypes->find($item->itype)->notforloan(0)->store;
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(1)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>reference</status>},"reference if positive itype notforloan value");
t::lib::Mocks::mock_preference('item-level_itypes', 1);
Koha::ItemTypes->find($item->itype)->notforloan(1)->store;
Koha::ItemTypes->find($item->biblioitem->itemtype)->notforloan(0)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>reference</status>},"reference if positive itemtype notforloan value");
Koha::ItemTypes->find($item->itype)->notforloan(0)->store;
my $substatus = Koha::AuthorisedValues->search({ category => 'NOT_LOAN', authorised_value => -1 })->next->lib;
$item->notforloan(-1)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan if negative notforloan value");
like($xml,qr{<substatus>$substatus</substatus>},"substatus set if negative notforloan value");
$item->notforloan(1)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>reference</status>},"reference if positive notforloan value");
# But now make status notforloan==1 count under Not available
t::lib::Mocks::mock_preference('Available_NFL', '2');
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>reallynotforloan</status>},"reallynotforloan when we change Avaiable_NFL");
t::lib::Mocks::mock_preference('Available_NFL', '1|2');
}
$item->onloan('2001-01-01')->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>Checked out</status>},"Checked out status takes precedence over Not for loan");
$item->withdrawn(1)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>Withdrawn</status>},"Withdrawn status takes precedence over Checked out");
$item->itemlost(1)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>Lost</status>},"Lost status takes precedence over Withdrawn");
$item->damaged(1)->store;
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>Damaged</status>},"Damaged status takes precedence over Lost");
$builder->build({ source => "Branchtransfer", value => {
itemnumber => $item->itemnumber,
datearrived => undef,
datecancelled => undef,
}
});
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>In transit</status>},"In-transit status takes precedence over Damaged");
my $hold = $builder->build_object({ class => 'Koha::Holds', value => {
biblionumber => $item->biblionumber,
itemnumber => $item->itemnumber,
found => 'W',
priority => 0,
}
});
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>Waiting</status>},"Waiting status takes precedence over In transit");
$builder->build({ source => "TmpHoldsqueue", value => {
itemnumber => $item->itemnumber
}
});
$xml = C4::XSLT::buildKohaItemsNamespace( $item->biblionumber,[]);
like($xml,qr{<status>Pending hold</status>},"Pending status takes precedence over all");
};
$schema->storage->txn_rollback;