4 use Test::More tests => 14;
9 use Koha::Borrower::Modifications;
11 C4::Context->dbh->do("TRUNCATE TABLE borrower_modifications");
13 ## Create new pending modification
14 Koha::Borrower::Modifications->new( verification_token => '1234567890' )
15 ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
17 ## Get the new pending modification
18 my $borrower = Koha::Borrower::Modifications->GetModifications(
19 { verification_token => '1234567890' } );
21 ## Verify we get the same data
22 ok( $borrower->{'surname'} = 'Hall',
23 'Test AddModifications() and GetModifications()' );
25 ## Check the Verify method
27 Koha::Borrower::Modifications->Verify('1234567890'),
28 'Test that Verify() succeeds with a valid token'
31 ## Delete the pending modification
32 $borrower = Koha::Borrower::Modifications->DelModifications(
33 { verification_token => '1234567890' } );
35 ## Verify it's no longer in the database
36 $borrower = Koha::Borrower::Modifications->GetModifications(
37 { verification_token => '1234567890' } );
38 ok( !defined( $borrower->{'surname'} ), 'Test DelModifications()' );
40 ## Check the Verify method
42 !Koha::Borrower::Modifications->Verify('1234567890'),
43 'Test that Verify() method fails for a bad token'
46 ## Create new pending modification, but for an existing borrower
47 Koha::Borrower::Modifications->new( borrowernumber => '2' )
48 ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
51 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
52 'Test GetPendingModificationsCount()' );
54 ## Create new pending modification for another existing borrower
55 Koha::Borrower::Modifications->new( borrowernumber => '3' )
56 ->AddModifications( { surname => 'Smith', firstname => 'Sandy' } );
60 Koha::Borrower::Modifications->GetPendingModificationsCount() == 2,
61 'Add a new pending modification and test GetPendingModificationsCount() again'
64 ## Check GetPendingModifications
65 my $pending = Koha::Borrower::Modifications->GetPendingModifications();
67 $pending->[0]->{'firstname'} eq 'Sandy',
68 'Test GetPendingModifications() again'
70 ok( $pending->[1]->{'firstname'} eq 'Kyle', 'Test GetPendingModifications()' );
72 ## This should delete the row from the table
73 Koha::Borrower::Modifications->DenyModifications('3');
76 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
77 'Test DenyModifications()' );
79 ## Save a copy of the borrowers original data
80 my $old_borrower = GetMember( borrowernumber => '2' );
82 ## Apply the modifications
83 Koha::Borrower::Modifications->ApproveModifications('2');
87 Koha::Borrower::Modifications->GetPendingModificationsCount() == 0,
88 'Test ApproveModifications() removes pending modification from db'
91 ## Get a copy of the borrowers current data
92 my $new_borrower = GetMember( borrowernumber => '2' );
94 ## Check to see that the approved modifications were saved
95 ok( $new_borrower->{'surname'} eq 'Hall',
96 'Test ApproveModifications() applys modification to borrower' );
98 ## Now let's put it back the way it was
99 Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications(
101 surname => $old_borrower->{'surname'},
102 firstname => $old_borrower->{'firstname'}
107 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
108 'Test GetPendingModificationsCount()' );
110 ## Apply the modifications
111 Koha::Borrower::Modifications->ApproveModifications('2');
115 Koha::Borrower::Modifications->GetPendingModificationsCount() == 0,
116 'Test ApproveModifications() removes pending modification from db, again'
119 $new_borrower = GetMember( borrowernumber => '2' );
121 ## Test to verify the borrower has been updated with the original values
123 $new_borrower->{'surname'} eq $old_borrower->{'surname'},
124 'Test ApproveModifications() applys modification to borrower, again'