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

(-)a/t/db_dependent/Koha_borrower_modifications.t (-10 / +14 lines)
Lines 4-9 use Modern::Perl; Link Here
4
use Test::More tests => 14;
4
use Test::More tests => 14;
5
5
6
use C4::Context;
6
use C4::Context;
7
use t::lib::TestBuilder;
7
use C4::Members;
8
use C4::Members;
8
9
9
use Koha::Patron::Modifications;
10
use Koha::Patron::Modifications;
Lines 48-54 ok( Link Here
48
);
49
);
49
50
50
## Create new pending modification, but for an existing borrower
51
## Create new pending modification, but for an existing borrower
51
Koha::Patron::Modifications->new( borrowernumber => '2' )
52
## But not a hardcoded borrowernumber of course (Bug 16407)
53
my $builder = t::lib::TestBuilder->new;
54
my $borr1 = $builder->build({ source => 'Borrower' })->{borrowernumber};
55
Koha::Patron::Modifications->new( borrowernumber => $borr1 )
52
  ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
56
  ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
53
57
54
## Test the counter
58
## Test the counter
Lines 56-62 ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1, Link Here
56
    'Test GetPendingModificationsCount()' );
60
    'Test GetPendingModificationsCount()' );
57
61
58
## Create new pending modification for another existing borrower
62
## Create new pending modification for another existing borrower
59
Koha::Patron::Modifications->new( borrowernumber => '3' )
63
my $borr2 = $builder->build({ source => 'Borrower' })->{borrowernumber};
64
Koha::Patron::Modifications->new( borrowernumber => $borr2 )
60
  ->AddModifications( { surname => 'Smith', firstname => 'Sandy' } );
65
  ->AddModifications( { surname => 'Smith', firstname => 'Sandy' } );
61
66
62
## Test the counter
67
## Test the counter
Lines 72-88 ok( $firstnames_mod[0] eq 'Kyle', 'Test GetPendingModifications()' ); Link Here
72
ok( $firstnames_mod[1] eq 'Sandy', 'Test GetPendingModifications() again' );
77
ok( $firstnames_mod[1] eq 'Sandy', 'Test GetPendingModifications() again' );
73
78
74
## This should delete the row from the table
79
## This should delete the row from the table
75
Koha::Patron::Modifications->DenyModifications('3');
80
Koha::Patron::Modifications->DenyModifications( $borr2 );
76
81
77
## Test the counter
82
## Test the counter
78
ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1,
83
ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1,
79
    'Test DenyModifications()' );
84
    'Test DenyModifications()' );
80
85
81
## Save a copy of the borrowers original data
86
## Save a copy of the borrowers original data
82
my $old_borrower = GetMember( borrowernumber => '2' );
87
my $old_borrower = GetMember( borrowernumber => $borr1 );
83
88
84
## Apply the modifications
89
## Apply the modifications
85
Koha::Patron::Modifications->ApproveModifications('2');
90
Koha::Patron::Modifications->ApproveModifications( $borr1 );
86
91
87
## Test the counter
92
## Test the counter
88
ok(
93
ok(
Lines 91-104 ok( Link Here
91
);
96
);
92
97
93
## Get a copy of the borrowers current data
98
## Get a copy of the borrowers current data
94
my $new_borrower = GetMember( borrowernumber => '2' );
99
my $new_borrower = GetMember( borrowernumber => $borr1 );
95
100
96
## Check to see that the approved modifications were saved
101
## Check to see that the approved modifications were saved
97
ok( $new_borrower->{'surname'} eq 'Hall',
102
ok( $new_borrower->{'surname'} eq 'Hall',
98
    'Test ApproveModifications() applys modification to borrower' );
103
    'Test ApproveModifications() applys modification to borrower' );
99
104
100
## Now let's put it back the way it was
105
## Now let's put it back the way it was
101
Koha::Patron::Modifications->new( borrowernumber => '2' )->AddModifications(
106
Koha::Patron::Modifications->new( borrowernumber => $borr1 )->AddModifications(
102
    {
107
    {
103
        surname   => $old_borrower->{'surname'},
108
        surname   => $old_borrower->{'surname'},
104
        firstname => $old_borrower->{'firstname'}
109
        firstname => $old_borrower->{'firstname'}
Lines 110-116 ok( Koha::Patron::Modifications->GetPendingModificationsCount() == 1, Link Here
110
    'Test GetPendingModificationsCount()' );
115
    'Test GetPendingModificationsCount()' );
111
116
112
## Apply the modifications
117
## Apply the modifications
113
Koha::Patron::Modifications->ApproveModifications('2');
118
Koha::Patron::Modifications->ApproveModifications( $borr1 );
114
119
115
## Test the counter
120
## Test the counter
116
ok(
121
ok(
Lines 118-124 ok( Link Here
118
    'Test ApproveModifications() removes pending modification from db, again'
123
    'Test ApproveModifications() removes pending modification from db, again'
119
);
124
);
120
125
121
$new_borrower = GetMember( borrowernumber => '2' );
126
$new_borrower = GetMember( borrowernumber => $borr1 );
122
127
123
## Test to verify the borrower has been updated with the original values
128
## Test to verify the borrower has been updated with the original values
124
ok(
129
ok(
125
- 

Return to bug 16407