Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 12; |
22 |
use Test::More tests => 13; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Time::Fake; |
24 |
use Time::Fake; |
25 |
|
25 |
|
Lines 947-949
$retrieved_item_1->delete;
Link Here
|
947 |
is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); |
947 |
is( Koha::Items->search->count, $nb_of_items - 1, 'Delete should have deleted the item' ); |
948 |
|
948 |
|
949 |
$schema->storage->txn_rollback; |
949 |
$schema->storage->txn_rollback; |
950 |
- |
950 |
|
|
|
951 |
subtest 'safe_delete() tests' => sub { |
952 |
|
953 |
plan tests => 7; |
954 |
|
955 |
$schema->storage->txn_begin; |
956 |
|
957 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
958 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
959 |
my $item_1 = $builder->build_sample_item({ library => $library->branchcode }); |
960 |
my $item_2 = $builder->build_sample_item({ library => $library->branchcode }); |
961 |
|
962 |
my $item_1_id = $item_1->id; |
963 |
my $item_2_id = $item_2->id; |
964 |
|
965 |
t::lib::Mocks::mock_userenv( |
966 |
{ patron => $patron, branchcode => $patron->branchcode } ); |
967 |
|
968 |
# book_on_loan |
969 |
C4::Circulation::AddIssue( $patron->unblessed, $item_1->barcode ); |
970 |
|
971 |
is( |
972 |
$item_1->safe_delete, |
973 |
'book_on_loan', |
974 |
'item that is on loan cannot be deleted', |
975 |
); |
976 |
|
977 |
my $items_rs = Koha::Items->search({ itemnumber => { -in => [ $item_1_id, $item_2_id ] } }); |
978 |
is( $items_rs->count, 2, 'We get the right items count' ); |
979 |
|
980 |
throws_ok |
981 |
{ $items_rs->safe_delete } |
982 |
'Koha::Exceptions::Object::CannotBeDeleted', |
983 |
'Exception thrown'; |
984 |
|
985 |
is( $@->reason, 'book_on_loan', 'Exception reason is correct' ); |
986 |
|
987 |
$items_rs = Koha::Items->search({ itemnumber => { -in => [ $item_1_id, $item_2_id ] } }); |
988 |
is( $items_rs->count, 2, 'We get the right items count, rollback happened' ); |
989 |
|
990 |
C4::Circulation::AddReturn( $item_1->barcode ); |
991 |
|
992 |
my $result = $items_rs->safe_delete; |
993 |
is( $result, undef, 'Successful call returns undef' ); |
994 |
$items_rs = Koha::Items->search({ itemnumber => { -in => [ $item_1_id, $item_2_id ] } }); |
995 |
is( $items_rs->count, 0, 'Successful safe delete, items are not ' ); |
996 |
|
997 |
$schema->storage->txn_rollback; |
998 |
}; |