Bug 14651: (regression test) fallback to bib-level if itype is undef

Koha::Item->effective_itemtype should fallback to biblio-level itemtype
even if item-level item types are set, in the case the item has no itemtype
set (bad migration, bad old code).

To test:
- Run
  $ prove t/db_dependent/Items.t
=> FAIL: Koha::Item->effective_itemtype doesn't work properly

Edit: Added a test for a warning when falling back as per QA request
and because it made a lot of sense :-D

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2015-08-18 16:34:25 -03:00 committed by Tomas Cohen Arazi
parent db891d33f0
commit efe3d17acc

View file

@ -24,6 +24,7 @@ use C4::Branch;
use Koha::Database;
use Test::More tests => 8;
use Test::Warn;
BEGIN {
use_ok('C4::Items');
@ -195,7 +196,7 @@ subtest 'GetItemsInfo tests' => sub {
subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
plan tests => 2;
plan tests => 4;
# Start transaction
$dbh->{AutoCommit} = 0;
@ -225,6 +226,19 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub {
C4::Context->set_preference( 'item-level_itypes', 1 );
ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is enabled' );
# If itemtype is not defined and item-level_level item types are set
# fallback to biblio-level itemtype (Bug 14651) and warn
$item->itype( undef );
$item->update();
my $effective_itemtype;
warning_is { $effective_itemtype = $item->effective_itemtype() }
"item-level_itypes set but no itemtype set for item ($item->itemnumber)",
'->effective_itemtype() raises a warning when falling back to bib-level';
ok( defined $effective_itemtype &&
$effective_itemtype eq 'BIB_LEVEL',
'$item->effective_itemtype() falls back to biblioitems.itemtype when item-level_itypes is enabled but undef' );
$dbh->rollback;
};