Lines 424-430
subtest "delete" => sub {
Link Here
|
424 |
}; |
424 |
}; |
425 |
|
425 |
|
426 |
subtest 'Koha::Patrons->delete' => sub { |
426 |
subtest 'Koha::Patrons->delete' => sub { |
427 |
plan tests => 4; |
427 |
plan tests => 6; |
428 |
|
428 |
|
429 |
my $mod_patron = Test::MockModule->new( 'Koha::Patron' ); |
429 |
my $mod_patron = Test::MockModule->new( 'Koha::Patron' ); |
430 |
my $moved_to_deleted = 0; |
430 |
my $moved_to_deleted = 0; |
Lines 438-450
subtest 'Koha::Patrons->delete' => sub {
Link Here
|
438 |
is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' ); |
438 |
is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' ); |
439 |
is( $moved_to_deleted, 2, 'Patrons moved to deletedborrowers' ); |
439 |
is( $moved_to_deleted, 2, 'Patrons moved to deletedborrowers' ); |
440 |
|
440 |
|
441 |
# Add again, test if we can raise an exception |
441 |
# Check return value / exception, rollback |
442 |
$mod_patron->mock( 'delete', sub { return -1; } ); |
442 |
my $mod_object = Test::MockModule->new( 'Koha::Object' ); |
|
|
443 |
my $mock_ret = -1; # no rollback expected |
444 |
$mod_object->mock( 'delete', sub { return $mock_ret; } ); |
443 |
$patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
445 |
$patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
444 |
$id1 = $patron1->borrowernumber; |
446 |
$id1 = $patron1->borrowernumber; |
445 |
$set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
447 |
$set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
|
|
448 |
is( $set->delete, '0E0', 'No exception for return value -1' ); |
449 |
|
450 |
$mock_ret = 0; # this should trigger rollback/exception |
451 |
$set->_resultset->reset; |
452 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete', |
453 |
'Exception raised for deleting patron on return value 0'; |
454 |
|
455 |
# We now trigger a FK error by deleting patron with issue |
456 |
$mod_object->unmock_all; |
457 |
my $issue = $builder->build_object({ class => 'Koha::Checkouts' }); |
458 |
my $id2 = $issue->borrowernumber; |
459 |
$set->_resultset->reset; |
446 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete', |
460 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete', |
447 |
'Exception raised for deleting patron'; |
461 |
'Exception raised for deleting patron with issue'; |
|
|
462 |
# FIXME And here we should love to check the number of patrons, |
463 |
# BUT unfortunately we cannot. Why? Since Koha::Patrons' txn_do creates |
464 |
# a nested transaction, the rollback does nothing in a test. |
465 |
# So we should *TRUST* txn_do here.. |
448 |
}; |
466 |
}; |
449 |
|
467 |
|
450 |
subtest 'add_enrolment_fee_if_needed' => sub { |
468 |
subtest 'add_enrolment_fee_if_needed' => sub { |
451 |
- |
|
|