|
Lines 36-41
use Koha::ActionLogs;
Link Here
|
| 36 |
use Koha::Holds; |
36 |
use Koha::Holds; |
| 37 |
use Koha::Old::Holds; |
37 |
use Koha::Old::Holds; |
| 38 |
use Koha::Patrons; |
38 |
use Koha::Patrons; |
|
|
39 |
use Koha::Old::Patrons; |
| 39 |
use Koha::Patron::Categories; |
40 |
use Koha::Patron::Categories; |
| 40 |
use Koha::Patron::Relationship; |
41 |
use Koha::Patron::Relationship; |
| 41 |
use Koha::Database; |
42 |
use Koha::Database; |
|
Lines 479-485
subtest "delete" => sub {
Link Here
|
| 479 |
); |
480 |
); |
| 480 |
|
481 |
|
| 481 |
my $deleted = $retrieved_patron->delete; |
482 |
my $deleted = $retrieved_patron->delete; |
| 482 |
is( $deleted, 1, 'Koha::Patron->delete should return 1 if the patron has been correctly deleted' ); |
483 |
is( ref($deleted), 'Koha::Patron', 'Koha::Patron->delete should return the deleted patron object if the patron has been correctly deleted' ); |
| 483 |
|
484 |
|
| 484 |
is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' ); |
485 |
is( Koha::Patrons->find( $patron->{borrowernumber} ), undef, 'Koha::Patron->delete should have deleted the patron' ); |
| 485 |
|
486 |
|
|
Lines 494-520
subtest "delete" => sub {
Link Here
|
| 494 |
}; |
495 |
}; |
| 495 |
|
496 |
|
| 496 |
subtest 'Koha::Patrons->delete' => sub { |
497 |
subtest 'Koha::Patrons->delete' => sub { |
| 497 |
plan tests => 4; |
498 |
plan tests => 3; |
| 498 |
|
|
|
| 499 |
my $mod_patron = Test::MockModule->new( 'Koha::Patron' ); |
| 500 |
my $moved_to_deleted = 0; |
| 501 |
$mod_patron->mock( 'move_to_deleted', sub { $moved_to_deleted++; } ); |
| 502 |
|
499 |
|
| 503 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
500 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 504 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
501 |
my $patron2 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 505 |
my $id1 = $patron1->borrowernumber; |
502 |
my $id1 = $patron1->borrowernumber; |
| 506 |
my $set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
503 |
my $set = Koha::Patrons->search({ borrowernumber => { -in => [$patron1->borrowernumber, $patron2->borrowernumber]}}); |
| 507 |
is( $set->count, 2, 'Two patrons found as expected' ); |
504 |
is( $set->count, 2, 'Two patrons found as expected' ); |
| 508 |
is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' ); |
505 |
is( $set->delete({ move => 1 }), 2, 'Two patrons deleted' ); |
| 509 |
is( $moved_to_deleted, 2, 'Patrons moved to deletedborrowers' ); |
506 |
my $deleted_patrons = Koha::Old::Patrons->search({ borrowernumber => { -in => [$patron1->borrowernumber, $patron2->borrowernumber]}}); |
| 510 |
|
507 |
is( $deleted_patrons->count, 2, 'Patrons moved to deletedborrowers' ); |
| 511 |
# Add again, test if we can raise an exception |
508 |
|
| 512 |
$mod_patron->mock( 'delete', sub { return -1; } ); |
509 |
# See other tests in t/db_dependent/Koha/Objects.t |
| 513 |
$patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
|
|
| 514 |
$id1 = $patron1->borrowernumber; |
| 515 |
$set = Koha::Patrons->search({ borrowernumber => { '>=' => $id1 }}); |
| 516 |
throws_ok { $set->delete } 'Koha::Exceptions::Patron::FailedDelete', |
| 517 |
'Exception raised for deleting patron'; |
| 518 |
}; |
510 |
}; |
| 519 |
|
511 |
|
| 520 |
subtest 'add_enrolment_fee_if_needed' => sub { |
512 |
subtest 'add_enrolment_fee_if_needed' => sub { |