[Koha-bugs] [Bug 17944] Remove the sql code from itemtypes.pl administrative perl script
bugzilla-daemon at bugs.koha-community.org
bugzilla-daemon at bugs.koha-community.org
Mon May 8 23:59:36 CEST 2017
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=17944
Alex Buckley <alexbuckley at catalyst.net.nz> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|Failed QA |Needs Signoff
--- Comment #51 from Alex Buckley <alexbuckley at catalyst.net.nz> ---
Hi Jonathan
In the patch I just attached I have addressed all of your points:
1)
> You are not retrieving any item type here, ->can_be_deleted will only return 0.
> You need to call Koha::ItemType->find($id); to retrieve the item type object
> you want from the DB.
I have changed the itemtypes.pl admin script (see below) so it now performs the
can_be_deleted() function on the result of the find() function, therefore it is
actually retrieving a item type here:
> 142 my $ItemType = Koha::ItemTypes->find($itemtype_code);
> 143 my $overalltotal = $ItemType->can_be_deleted();
> 144 if ($overalltotal == 0) {
> 145 push @messages, { type => 'error', code => 'cannot_be_delet ed'};
2)
> my $itemtype = Koha::ItemTypes->find($itemtype_code);
> + my $deleted = eval{ $itemtype->delete };;
> Unnecessary change.
I have changed the above code removing the changes to the second line and
removing the second semi colon in the second line (see below):
> 153 my $itemtype = Koha::ItemTypes->find($itemtype_code);
> 154 my $deleted = eval { $itemtype->delete };
3)
> This second try does not test what you want, see my previous comment:
> """
> The last test says 'An item type that is used by a biblioitem cannot be
> deleted'. But actually you are testing that "an item that is used by AN item
> AND A biblioitem cannot be deleted'.
> You should delete the item to make it test what you want to test.
> """
I have changed the test output from 'an item that is used by AN item
AND A biblioitem cannot be deleted' to 'An item type that is used by an item
and a biblioitem cannot be deleted'
because we are actually running the can_be_deleted() function on itemtype not
an item.
Additionally I have implemented a test for deleting the item and biblioitem
that use the itemtype in question.
Then I have implemented another further test to show that now the item and
biblioitem have been removed the can_be_deleted() function correctly shows that
the itemtype can be deleted:
> 145 is ( $item->delete, 1, 'An item has been deleted' );
> 146
> 147 is ( $biblio->delete, 1, 'A biblioitem has been deleted' );
> 148
> 149 is ( $item_type->can_be_deleted, 1, 'The item type that was being u sed > by the removed item and biblioitem can now be deleted' );
I have run the ItemTypes.t unit test and all tests are successful:
> kohadev-koha at kohadevbox:/home/vagrant/kohaclone/t/db_dependent/Koha$ prove -v > ItemTypes.t
> ItemTypes.t ..
> 1..26
> ok 1 - use Koha::ItemType;
> ok 2 - use Koha::ItemTypes;
> ok 3 - first result
> ok 4 - itemtype/code
> ok 5 - description
> ok 6 - rentalcharge
> ok 7 - imageurl
> ok 8 - summary
> ok 9 - checkinmsg
> ok 10 - checkinmsgtype
> ok 11 - second result
> ok 12 - itemtype/code
> ok 13 - description
> ok 14 - rentalcharge
> ok 15 - imageurl
> ok 16 - summary
> ok 17 - checkinmsg
> ok 18 - checkinmsgtype
> ok 19 - There are 3 item types
> ok 20 - item types should be sorted by translated description
> ok 21 - An item type that is not used can be deleted
> ok 22 - An item type that is used by an item cannot be deleted
> ok 23 - An item that is used by an item and a biblioitem cannot be deleted
> ok 24 - An item has been deleted
> ok 25 - A biblioitem has been deleted
> ok 26 - The item type that was being used by the removed item and biblioitem > can be deleted
> ok
> All tests successful.
Cheers
Alex
--
You are receiving this mail because:
You are watching all bug changes.
More information about the Koha-bugs
mailing list