Bug 16407: Fix Koha_borrower_modifications.t
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Sat, 30 Apr 2016 14:55:28 +0000 (16:55 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 20 Jun 2016 20:50:33 +0000 (08:50 +1200)
This test was using hardcoded borrower number, assuming they should be
present. Now we use TestBuilder.

Test plan:
Run the test.

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Test pass before and after patch.
No errors

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit d8d4277471908bf046d04b4e94eed6cd4c94f63b)
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
(cherry picked from commit 9112e88901c419f54ba34ff4eab0a6a744b31990)
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

t/db_dependent/Koha_borrower_modifications.t

index ff5d194..7e8ab7b 100755 (executable)
@@ -4,6 +4,7 @@ use Modern::Perl;
 use Test::More tests => 14;
 
 use C4::Context;
+use t::lib::TestBuilder;
 use C4::Members;
 
 use Koha::Borrower::Modifications;
@@ -48,7 +49,10 @@ ok(
 );
 
 ## Create new pending modification, but for an existing borrower
-Koha::Borrower::Modifications->new( borrowernumber => '2' )
+## But not a hardcoded borrowernumber of course (Bug 16407)
+my $builder = t::lib::TestBuilder->new;
+my $borr1 = $builder->build({ source => 'Borrower' })->{borrowernumber};
+Koha::Borrower::Modifications->new( borrowernumber => $borr1 )
   ->AddModifications( { surname => 'Hall', firstname => 'Kyle' } );
 
 ## Test the counter
@@ -56,7 +60,8 @@ ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
     'Test GetPendingModificationsCount()' );
 
 ## Create new pending modification for another existing borrower
-Koha::Borrower::Modifications->new( borrowernumber => '3' )
+my $borr2 = $builder->build({ source => 'Borrower' })->{borrowernumber};
+Koha::Borrower::Modifications->new( borrowernumber => $borr2 )
   ->AddModifications( { surname => 'Smith', firstname => 'Sandy' } );
 
 ## Test the counter
@@ -72,17 +77,17 @@ ok( $firstnames_mod[0] eq 'Kyle', 'Test GetPendingModifications()' );
 ok( $firstnames_mod[1] eq 'Sandy', 'Test GetPendingModifications() again' );
 
 ## This should delete the row from the table
-Koha::Borrower::Modifications->DenyModifications('3');
+Koha::Borrower::Modifications->DenyModifications($borr2);
 
 ## Test the counter
 ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
     'Test DenyModifications()' );
 
 ## Save a copy of the borrowers original data
-my $old_borrower = GetMember( borrowernumber => '2' );
+my $old_borrower = GetMember( borrowernumber => $borr1 );
 
 ## Apply the modifications
-Koha::Borrower::Modifications->ApproveModifications('2');
+Koha::Borrower::Modifications->ApproveModifications($borr1);
 
 ## Test the counter
 ok(
@@ -91,14 +96,14 @@ ok(
 );
 
 ## Get a copy of the borrowers current data
-my $new_borrower = GetMember( borrowernumber => '2' );
+my $new_borrower = GetMember( borrowernumber => $borr1 );
 
 ## Check to see that the approved modifications were saved
 ok( $new_borrower->{'surname'} eq 'Hall',
     'Test ApproveModifications() applys modification to borrower' );
 
 ## Now let's put it back the way it was
-Koha::Borrower::Modifications->new( borrowernumber => '2' )->AddModifications(
+Koha::Borrower::Modifications->new( borrowernumber => $borr1 )->AddModifications(
     {
         surname   => $old_borrower->{'surname'},
         firstname => $old_borrower->{'firstname'}
@@ -110,7 +115,7 @@ ok( Koha::Borrower::Modifications->GetPendingModificationsCount() == 1,
     'Test GetPendingModificationsCount()' );
 
 ## Apply the modifications
-Koha::Borrower::Modifications->ApproveModifications('2');
+Koha::Borrower::Modifications->ApproveModifications($borr1);
 
 ## Test the counter
 ok(
@@ -118,7 +123,7 @@ ok(
     'Test ApproveModifications() removes pending modification from db, again'
 );
 
-$new_borrower = GetMember( borrowernumber => '2' );
+$new_borrower = GetMember( borrowernumber => $borr1 );
 
 ## Test to verify the borrower has been updated with the original values
 ok(