Bug 17944: QA follow-up
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 9 May 2017 18:56:32 +0000 (15:56 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 5 Jun 2017 14:59:11 +0000 (11:59 -0300)
- 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 <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/ItemType.pm
admin/itemtypes.pl
t/db_dependent/Koha/ItemTypes.t

index 0b84e80..24be0d2 100644 (file)
@@ -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;
 }
 
index 756910d..09e564e 100755 (executable)
@@ -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' ) {
index 082d733..ac239b3 100755 (executable)
@@ -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' );