From a691e88a4ebf57e9ebda8afb5f8e6bac33bc6ad6 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 --- Koha/Schema/Result/Item.pm | 7 ++++--- t/db_dependent/Items.t | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Koha/Schema/Result/Item.pm b/Koha/Schema/Result/Item.pm index c3c4b33601..36e1e910ab 100644 --- a/Koha/Schema/Result/Item.pm +++ b/Koha/Schema/Result/Item.pm @@ -652,15 +652,16 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); +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 5f8dac36c8..5df6eb5b33 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