From 14e84e422ee5c454e2bce341a124330b047deb63 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 9 May 2017 15:56:32 -0300 Subject: [PATCH] Bug 17944: QA follow-up - Remove an unused use statement - Fix pod - Use snake_case - Fix test "An itemtype cannot be deleted if and only if there is biblioitem linked with it" Signed-off-by: Jonathan Druart Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart (cherry picked from commit 6d76f61a6b0b6b429246c5a9398ec55f97d98027) Signed-off-by: Fridolin Somers --- Koha/ItemType.pm | 9 +++++---- admin/itemtypes.pl | 8 ++++---- t/db_dependent/Koha/ItemTypes.t | 12 ++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index 0b84e80af6..24be0d2297 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -23,7 +23,6 @@ use C4::Koha; use C4::Languages; use Koha::Database; use Koha::Localizations; -use Koha::Exceptions; use base qw(Koha::Object); @@ -91,8 +90,10 @@ sub translated_descriptions { } + =head3 can_be_deleted -my $overalltotal = Koha::ItemType->can_be_deleted(); + +my $can_be_deleted = Koha::ItemType->can_be_deleted(); Counts up the number of biblioitems and items with itemtype (code) and hands back the combined number of biblioitems and items with the itemtype @@ -100,8 +101,8 @@ Counts up the number of biblioitems and items with itemtype (code) and hands bac sub can_be_deleted { my ($self) = @_; - my $nb_items = Koha::Items->search( { 'itype' => $self->itemtype} )->count; - my $nb_biblioitems = Koha::Biblioitems->search( { 'itemtype' => $self->itemtype} )->count; + my $nb_items = Koha::Items->search( { itype => $self->itemtype } )->count; + my $nb_biblioitems = Koha::Biblioitems->search( { itemtype => $self->itemtype } )->count; return $nb_items + $nb_biblioitems == 0 ? 1 : 0; } diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 756910d470..09e564e40d 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -139,13 +139,13 @@ if ( $op eq 'add_form' ) { $op = 'list'; } elsif ( $op eq 'delete_confirm' ) { - my $ItemType = Koha::ItemTypes->find($itemtype_code); - my $overalltotal = $ItemType->can_be_deleted(); - if ($overalltotal == 0) { + my $itemtype = Koha::ItemTypes->find($itemtype_code); + my $can_be_deleted = $itemtype->can_be_deleted(); + if ($can_be_deleted == 0) { push @messages, { type => 'error', code => 'cannot_be_deleted'}; $op = 'list'; } else { - $template->param( itemtype => $ItemType, ); + $template->param( itemtype => $itemtype, ); } } elsif ( $op eq 'delete_confirmed' ) { diff --git a/t/db_dependent/Koha/ItemTypes.t b/t/db_dependent/Koha/ItemTypes.t index 082d733611..ac239b3fc3 100755 --- a/t/db_dependent/Koha/ItemTypes.t +++ b/t/db_dependent/Koha/ItemTypes.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 26; +use Test::More tests => 24; use Data::Dumper; use Koha::Database; use t::lib::Mocks; @@ -135,16 +135,12 @@ my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' }); is( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted'); my $item = $builder->build_object({ class => 'Koha::Items', value => { itype => $item_type->itemtype }}); - is( $item_type->can_be_deleted, 0, 'An item type that is used by an item cannot be deleted' ); +$item->delete; -my $biblio = $builder->build_object({ class => 'Koha::Biblioitems', value => { itemtype => $item_type->itemtype }}); - +my $biblioitem = $builder->build_object({ class => 'Koha::Biblioitems', value => { itemtype => $item_type->itemtype }}); is ( $item_type->can_be_deleted, 0, 'An item type that is used by an item and a biblioitem cannot be deleted' ); - -is ( $item->delete, 1, 'An item has been deleted' ); - -is ( $biblio->delete, 1, 'A biblioitem has been deleted' ); +$biblioitem->delete; is ( $item_type->can_be_deleted, 1, 'The item type that was being used by the removed item and biblioitem can now be deleted' ); -- 2.39.5