From 65b1618e9c4197718c59950767692e0502fee689 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 4 Mar 2016 13:21:39 +0000 Subject: [PATCH] Bug 11998: Use C4::Context->preference in Koha/Schema/Result/Item.pm Otherwise some tests won't pass Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jacek Ablewicz Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com (cherry picked from commit a691e88a4ebf57e9ebda8afb5f8e6bac33bc6ad6) Signed-off-by: Julian Maurice --- Koha/Schema/Result/Item.pm | 8 +++++--- t/db_dependent/Items.t | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index 806a2bff5b..0fda92eddd 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -621,15 +621,17 @@ __PACKAGE__->might_have( __PACKAGE__->belongs_to( biblioitem => "Koha::Schema::Result::Biblioitem", "biblioitemnumber" ); + +use C4::Context; sub effective_itemtype { my ( $self ) = @_; - my $pref = $self->result_source->schema->resultset('Systempreference')->find('item-level_itypes'); - if ( $pref->value() && $self->itype() ) { + my $pref = C4::Context->preference('item-level_itypes'); + if ( $pref && $self->itype() ) { return $self->itype(); } else { warn "item-level_itypes set but no itemtype set for item ($self->itemnumber)" - if $pref->value(); + if $pref; return $self->biblioitemnumber()->itemtype(); } } diff --git a/t/db_dependent/Items.t b/t/db_dependent/Items.t index 99d9edafac..c982464517 100755 --- a/t/db_dependent/Items.t +++ b/t/db_dependent/Items.t @@ -245,10 +245,10 @@ subtest q{Test Koha::Database->schema()->resultset('Item')->itemtype()} => sub { my ( $item ) = $bi[0]->items(); t::lib::Mocks::mock_preference( 'item-level_itypes', 0 ); - ok( $item->effective_itemtype() eq 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' ); + is( $item->effective_itemtype(), 'BIB_LEVEL', '$item->itemtype() returns biblioitem.itemtype when item-level_itypes is disabled' ); t::lib::Mocks::mock_preference( 'item-level_itypes', 1 ); - ok( $item->effective_itemtype() eq 'ITEM_LEVEL', '$item->itemtype() returns items.itype when item-level_itypes is enabled' ); + is( $item->effective_itemtype(), '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 -- 2.39.5