View | Details | Raw Unified | Return to bug 34069
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Old/Patron.t (-1 / +64 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2025 Koha
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <https://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 2;
23
use Test::Exception;
24
use Test::MockModule;
25
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
use Test::NoWarnings;
29
30
use Koha::Database;
31
use Koha::Patrons;
32
use Koha::Old::Patrons;
33
34
my $schema  = Koha::Database->new->schema;
35
my $builder = t::lib::TestBuilder->new;
36
37
subtest 'restore_deleted_borrower' => sub {
38
    plan tests => 4;
39
40
    $schema->storage->txn_begin;
41
42
    #create a test patron
43
    my $patron         = $builder->build_object( { class => 'Koha::Patrons' } );
44
    my $borrowernumber = $patron->borrowernumber;
45
    my $cardnumber     = $patron->cardnumber;
46
47
    #delete the created patron, using move = 1 to ensure they go to deleteborrowers
48
    my $to_delete = Koha::Patrons->search( { borrowernumber => $borrowernumber } );
49
    $to_delete->delete( { move => 1 } );
50
51
    #verify patron is in deletedborrowers
52
    my $deleted_patron = Koha::Old::Patrons->search( { borrowernumber => $borrowernumber } )->next;
53
    ok( $deleted_patron, 'Patron moved to deletedborrowers' );
54
55
    #restore the deleted patron
56
    my $restored = $deleted_patron->restore_deleted_borrower;
57
58
    #verify the patron is restored
59
    ok( $restored, 'Restored patron exists' );
60
    is( $restored->borrowernumber, $borrowernumber, 'Borrowernumber matches' );
61
    is( $restored->cardnumber,     $cardnumber,     'Cardnumber matches' );
62
63
    $schema->storage->txn_rollback;
64
};

Return to bug 34069