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 <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>
(cherry picked from commit 6d76f61a6b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
parent
c31db771b3
commit
14e84e422e
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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' ) {
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue