From 74df3502d8eaedc4236ee765c0372d9cc9b09355 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 --- 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 c3c4b33..36e1e91 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 5f8dac3..5df6eb5 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.7.0