Bug 14778: Make 3 tests pass
[koha.git] / t / db_dependent / Koha_borrower_modifications.t
blobff5d1945c7ede7657c9263c5e603610be928e6fd
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Test::More tests => 14;
6 use C4::Context;
7 use C4::Members;
9 use Koha::Borrower::Modifications;
11 my $dbh = C4::Context->dbh;
12 $dbh->{RaiseError} = 1;
13 $dbh->{AutoCommit} = 0;
15 $dbh->do("DELETE FROM borrower_modifications");
17 ## Create new pending modification
18 Koha::Borrower::Modifications->new( verification_token => '1234567890' )
19 ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
21 ## Get the new pending modification
22 my $borrower = Koha::Borrower::Modifications->GetModifications(
23 { verification_token => '1234567890' } );
25 ## Verify we get the same data
26 ok( $borrower->{'surname'} = 'Hall',
27 'Test AddModifications() and GetModifications()' );
29 ## Check the Verify method
30 ok(
31 Koha::Borrower::Modifications->Verify('1234567890'),
32 'Test that Verify() succeeds with a valid token'
35 ## Delete the pending modification
36 $borrower = Koha::Borrower::Modifications->DelModifications(
37 { verification_token => '1234567890' } );
39 ## Verify it's no longer in the database
40 $borrower = Koha::Borrower::Modifications->GetModifications(
41 { verification_token => '1234567890' } );
42 ok( !defined( $borrower->{'surname'} ), 'Test DelModifications()' );
44 ## Check the Verify method
45 ok(
46 !Koha::Borrower::Modifications->Verify('1234567890'),
47 'Test that Verify() method fails for a bad token'
50 ## Create new pending modification, but for an existing borrower
51 Koha::Borrower::Modifications->new( borrowernumber => '2' )
52 ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
54 ## Test the counter
55 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
56 'Test GetPendingModificationsCount()' );
58 ## Create new pending modification for another existing borrower
59 Koha::Borrower::Modifications->new( borrowernumber => '3' )
60 ->AddModifications( { surname => 'Smith', firstname => 'Sandy' } );
62 ## Test the counter
63 ok(
64 Koha::Borrower::Modifications->GetPendingModificationsCount() == 2,
65 'Add a new pending modification and test GetPendingModificationsCount() again'
68 ## Check GetPendingModifications
69 my $pendings = Koha::Borrower::Modifications->GetPendingModifications();
70 my @firstnames_mod = sort ( $pendings->[0]->{firstname}, $pendings->[1]->{firstname} );
71 ok( $firstnames_mod[0] eq 'Kyle', 'Test GetPendingModifications()' );
72 ok( $firstnames_mod[1] eq 'Sandy', 'Test GetPendingModifications() again' );
74 ## This should delete the row from the table
75 Koha::Borrower::Modifications->DenyModifications('3');
77 ## Test the counter
78 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
79 'Test DenyModifications()' );
81 ## Save a copy of the borrowers original data
82 my $old_borrower = GetMember( borrowernumber => '2' );
84 ## Apply the modifications
85 Koha::Borrower::Modifications->ApproveModifications('2');
87 ## Test the counter
88 ok(
89 Koha::Borrower::Modifications->GetPendingModificationsCount() == 0,
90 'Test ApproveModifications() removes pending modification from db'
93 ## Get a copy of the borrowers current data
94 my $new_borrower = GetMember( borrowernumber => '2' );
96 ## Check to see that the approved modifications were saved
97 ok( $new_borrower->{'surname'} eq 'Hall',
98 'Test ApproveModifications() applys modification to borrower' );
100 ## Now let's put it back the way it was
101 Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications(
103 surname => $old_borrower->{'surname'},
104 firstname => $old_borrower->{'firstname'}
108 ## Test the counter
109 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
110 'Test GetPendingModificationsCount()' );
112 ## Apply the modifications
113 Koha::Borrower::Modifications->ApproveModifications('2');
115 ## Test the counter
117 Koha::Borrower::Modifications->GetPendingModificationsCount() == 0,
118 'Test ApproveModifications() removes pending modification from db, again'
121 $new_borrower = GetMember( borrowernumber => '2' );
123 ## Test to verify the borrower has been updated with the original values
125 $new_borrower->{'surname'} eq $old_borrower->{'surname'},
126 'Test ApproveModifications() applys modification to borrower, again'
129 $dbh->rollback();