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-448
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 / 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', 'Try -1: no rollback' ); |
449 |
|
450 |
undef $mock_ret; # still no rollback expected |
451 |
$set->_resultset->reset; # needed for reiterate |
452 |
is( $set->delete, '0E0', 'Try undef: no rollback' ); |
453 |
|
454 |
$mock_ret = 0; # this should trigger rollback/exception |
455 |
$set->_resultset->reset; |
446 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete', |
456 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete', |
447 |
'Exception raised for deleting patron'; |
457 |
'Exception raised for deleting patron'; |
448 |
}; |
458 |
}; |
449 |
- |
|
|