Lines 22-27
use Modern::Perl;
Link Here
|
22 |
use Test::More tests => 33; |
22 |
use Test::More tests => 33; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
|
|
25 |
use Test::MockModule; |
25 |
use Time::Fake; |
26 |
use Time::Fake; |
26 |
use DateTime; |
27 |
use DateTime; |
27 |
use JSON; |
28 |
use JSON; |
Lines 422-437
subtest "delete" => sub {
Link Here
|
422 |
}; |
423 |
}; |
423 |
|
424 |
|
424 |
subtest 'Koha::Patrons->delete' => sub { |
425 |
subtest 'Koha::Patrons->delete' => sub { |
425 |
plan tests => 3; |
426 |
plan tests => 4; |
|
|
427 |
|
428 |
my $mod_patron = Test::MockModule->new( 'Koha::Patron' ); |
429 |
my $moved_to_deleted = 0; |
430 |
$mod_patron->mock( 'move_to_deleted', sub { $moved_to_deleted++; } ); |
431 |
|
426 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
432 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
427 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
433 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
428 |
my $id1 = $patron1->borrowernumber; |
434 |
my $id1 = $patron1->borrowernumber; |
429 |
my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
435 |
my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
430 |
is( $set->count, 2, 'Two patrons found as expected' ); |
436 |
is( $set->count, 2, 'Two patrons found as expected' ); |
431 |
my $count1 = $schema->resultset('Deletedborrower')->count; |
|
|
432 |
is( $set->delete({ move => 1 }), 1, 'Two patrons deleted' ); |
437 |
is( $set->delete({ move => 1 }), 1, 'Two patrons deleted' ); |
433 |
my $count2 = $schema->resultset('Deletedborrower')->count; |
438 |
is( $moved_to_deleted, 2, 'Patrons moved to deletedborrowers' ); |
434 |
is( $count2, $count1 + 2, 'Patrons moved to deletedborrowers' ); |
439 |
|
|
|
440 |
# Add again, test if we can raise an exception |
441 |
$mod_patron->mock( 'delete', sub { return -1; } ); |
442 |
$patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
443 |
$id1 = $patron1->borrowernumber; |
444 |
$set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
445 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::Delete', |
446 |
'Exception raised for deleting patron'; |
435 |
}; |
447 |
}; |
436 |
|
448 |
|
437 |
subtest 'add_enrolment_fee_if_needed' => sub { |
449 |
subtest 'add_enrolment_fee_if_needed' => sub { |
438 |
- |
|
|