https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17944
--- Comment #42 from Jonathan Druart <[email protected]> --- Alex, Some additional remarks (we are aiming the perfect patch, right? :)) 1. The POD of the new method is incorrect, please adapt it. Note that a line should not be longer than 80 chars 2. The method can_be_deleted should be something like: 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; return $nb_items + $nb_biblioitems == 0; } $self is the current object, from this object you know the itemtype (code), so you so not need to pass it as an argument. 3. The tests are wrong: I have a biblio with biblionumber=1, so they fail (Duplicate entry '1' for key 'PRIMARY'). You need to use our TestBuilder module to generate random data. What you want is: a) Generate the $builder object: my $builder = t::lib::TestBuilder->new; b) create an item type: my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' }); c) you want to test if an item type, not used, can be removed. It's time! is( $item_type->can_be_deleted, 1, 'An item type that is not used can be deleted' ); d) create an item using this item type: my $item = $builder->build_object({ class => 'Koha::Items', value => { itype => $item_type->itemtype }); e) Then you want to know if the item type can be removed is( $item_type->can_be_deleted, 0, 'An item type that is used by an item cannot be deleted ); Then you can continue with a biblioitem object. Please resubmit a patch without the delete method, just can_be_deleted step-by-step :) -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list [email protected] http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
