Lines 11-94
use Koha::Borrower::Modifications;
Link Here
|
11 |
C4::Context->dbh->do("TRUNCATE TABLE borrower_modifications"); |
11 |
C4::Context->dbh->do("TRUNCATE TABLE borrower_modifications"); |
12 |
|
12 |
|
13 |
## Create new pending modification |
13 |
## Create new pending modification |
14 |
Koha::Borrower::Modifications->new( verification_token => '1234567890' )->AddModifications({ surname => 'Hall', firstname => 'Kyle' }); |
14 |
Koha::Borrower::Modifications->new( verification_token => '1234567890' ) |
|
|
15 |
->AddModifications( { surname => 'Hall', firstname => 'Kyle' } ); |
15 |
|
16 |
|
16 |
## Get the new pending modification |
17 |
## Get the new pending modification |
17 |
my $borrower = Koha::Borrower::Modifications->GetModifications({ |
18 |
my $borrower = Koha::Borrower::Modifications->GetModifications( |
18 |
verification_token => '1234567890' |
19 |
{ verification_token => '1234567890' } ); |
19 |
}); |
|
|
20 |
|
20 |
|
21 |
## Verify we get the same data |
21 |
## Verify we get the same data |
22 |
ok( $borrower->{'surname'} = 'Hall' ); |
22 |
ok( $borrower->{'surname'} = 'Hall', |
|
|
23 |
'Test AddModifications() and GetModifications()' ); |
23 |
|
24 |
|
24 |
## Check the Verify method |
25 |
## Check the Verify method |
25 |
ok( Koha::Borrower::Modifications->Verify( '1234567890' ) ); |
26 |
ok( |
|
|
27 |
Koha::Borrower::Modifications->Verify('1234567890'), |
28 |
'Test that Verify() succeeds with a valid token' |
29 |
); |
26 |
|
30 |
|
27 |
## Delete the pending modification |
31 |
## Delete the pending modification |
28 |
$borrower = Koha::Borrower::Modifications->DelModifications({ |
32 |
$borrower = Koha::Borrower::Modifications->DelModifications( |
29 |
verification_token => '1234567890' |
33 |
{ verification_token => '1234567890' } ); |
30 |
}); |
|
|
31 |
|
34 |
|
32 |
## Verify it's no longer in the database |
35 |
## Verify it's no longer in the database |
33 |
$borrower = Koha::Borrower::Modifications->GetModifications({ |
36 |
$borrower = Koha::Borrower::Modifications->GetModifications( |
34 |
verification_token => '1234567890' |
37 |
{ verification_token => '1234567890' } ); |
35 |
}); |
38 |
ok( !defined( $borrower->{'surname'} ), 'Test DelModifications()' ); |
36 |
ok( !defined( $borrower->{'surname'} ) ); |
|
|
37 |
|
39 |
|
38 |
## Check the Verify method |
40 |
## Check the Verify method |
39 |
ok( !Koha::Borrower::Modifications->Verify( '1234567890' ) ); |
41 |
ok( |
|
|
42 |
!Koha::Borrower::Modifications->Verify('1234567890'), |
43 |
'Test that Verify() method fails for a bad token' |
44 |
); |
40 |
|
45 |
|
41 |
## Create new pending modification, but for an existing borrower |
46 |
## Create new pending modification, but for an existing borrower |
42 |
Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications({ surname => 'Hall', firstname => 'Kyle' }); |
47 |
Koha::Borrower::Modifications->new( borrowernumber => '2' ) |
|
|
48 |
->AddModifications( { surname => 'Hall', firstname => 'Kyle' } ); |
43 |
|
49 |
|
44 |
## Test the counter |
50 |
## Test the counter |
45 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1 ); |
51 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1, |
|
|
52 |
'Test GetPendingModificationsCount()' ); |
46 |
|
53 |
|
47 |
## Create new pending modification for another existing borrower |
54 |
## Create new pending modification for another existing borrower |
48 |
Koha::Borrower::Modifications->new( borrowernumber => '3' )->AddModifications({ surname => 'Smith', firstname => 'Sandy' }); |
55 |
Koha::Borrower::Modifications->new( borrowernumber => '3' ) |
|
|
56 |
->AddModifications( { surname => 'Smith', firstname => 'Sandy' } ); |
49 |
|
57 |
|
50 |
## Test the counter |
58 |
## Test the counter |
51 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 2 ); |
59 |
ok( |
|
|
60 |
Koha::Borrower::Modifications->GetPendingModificationsCount() == 2, |
61 |
'Add a new pending modification and test GetPendingModificationsCount() again' |
62 |
); |
52 |
|
63 |
|
53 |
## Check GetPendingModifications |
64 |
## Check GetPendingModifications |
54 |
my $pending = Koha::Borrower::Modifications->GetPendingModifications(); |
65 |
my $pending = Koha::Borrower::Modifications->GetPendingModifications(); |
55 |
ok( $pending->[0]->{'firstname'} eq 'Kyle' ); |
66 |
ok( $pending->[0]->{'firstname'} eq 'Kyle', 'Test GetPendingModifications()' ); |
56 |
ok( $pending->[1]->{'firstname'} eq 'Sandy' ); |
67 |
ok( |
|
|
68 |
$pending->[1]->{'firstname'} eq 'Sandy', |
69 |
'Test GetPendingModifications() again' |
70 |
); |
57 |
|
71 |
|
58 |
## This should delete the row from the table |
72 |
## This should delete the row from the table |
59 |
Koha::Borrower::Modifications->DenyModifications( '3' ); |
73 |
Koha::Borrower::Modifications->DenyModifications('3'); |
60 |
|
74 |
|
61 |
## Test the counter |
75 |
## Test the counter |
62 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1 ); |
76 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1, |
|
|
77 |
'Test DenyModifications()' ); |
63 |
|
78 |
|
64 |
## Save a copy of the borrowers original data |
79 |
## Save a copy of the borrowers original data |
65 |
my $old_borrower = GetMember(borrowernumber => '2' ); |
80 |
my $old_borrower = GetMember( borrowernumber => '2' ); |
66 |
|
81 |
|
67 |
## Apply the modifications |
82 |
## Apply the modifications |
68 |
Koha::Borrower::Modifications->ApproveModifications( '2' ); |
83 |
Koha::Borrower::Modifications->ApproveModifications('2'); |
69 |
|
84 |
|
70 |
## Test the counter |
85 |
## Test the counter |
71 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 0 ); |
86 |
ok( |
|
|
87 |
Koha::Borrower::Modifications->GetPendingModificationsCount() == 0, |
88 |
'Test ApproveModifications() removes pending modification from db' |
89 |
); |
72 |
|
90 |
|
73 |
## Get a copy of the borrowers current data |
91 |
## Get a copy of the borrowers current data |
74 |
my $new_borrower = GetMember(borrowernumber => '2' ); |
92 |
my $new_borrower = GetMember( borrowernumber => '2' ); |
75 |
|
93 |
|
76 |
## Check to see that the approved modifications were saved |
94 |
## Check to see that the approved modifications were saved |
77 |
ok( $new_borrower->{'surname'} eq 'Hall' ); |
95 |
ok( $new_borrower->{'surname'} eq 'Hall', |
|
|
96 |
'Test ApproveModifications() applys modification to borrower' ); |
78 |
|
97 |
|
79 |
## Now let's put it back the way it was |
98 |
## Now let's put it back the way it was |
80 |
Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications({ surname => $old_borrower->{'surname'}, firstname => $old_borrower->{'firstname'} }); |
99 |
Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications( |
|
|
100 |
{ |
101 |
surname => $old_borrower->{'surname'}, |
102 |
firstname => $old_borrower->{'firstname'} |
103 |
} |
104 |
); |
81 |
|
105 |
|
82 |
## Test the counter |
106 |
## Test the counter |
83 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1 ); |
107 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1, |
|
|
108 |
'Test GetPendingModificationsCount()' ); |
84 |
|
109 |
|
85 |
## Apply the modifications |
110 |
## Apply the modifications |
86 |
Koha::Borrower::Modifications->ApproveModifications( '2' ); |
111 |
Koha::Borrower::Modifications->ApproveModifications('2'); |
87 |
|
112 |
|
88 |
## Test the counter |
113 |
## Test the counter |
89 |
ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 0 ); |
114 |
ok( |
|
|
115 |
Koha::Borrower::Modifications->GetPendingModificationsCount() == 0, |
116 |
'Test ApproveModifications() removes pending modification from db, again' |
117 |
); |
90 |
|
118 |
|
91 |
$new_borrower = GetMember(borrowernumber => '2' ); |
119 |
$new_borrower = GetMember( borrowernumber => '2' ); |
92 |
|
120 |
|
93 |
## Test to verify the borrower has been updated with the original values |
121 |
## Test to verify the borrower has been updated with the original values |
94 |
ok( $new_borrower->{'surname'} eq $old_borrower->{'surname'} ); |
122 |
ok( |
|
|
123 |
$new_borrower->{'surname'} eq $old_borrower->{'surname'}, |
124 |
'Test ApproveModifications() applys modification to borrower, again' |
125 |
); |
95 |
- |
|
|