Bug 20287: Replace occurrences of AddMember with Koha::Patron->new->store->borrowernumber
[koha.git] / t / db_dependent / Members / IssueSlip.t
index d161602..cbf3a72 100644 (file)
 
 use Modern::Perl;
 
+use Data::Dumper; # REMOVEME with diag
 use Test::More tests => 3;
 use Test::MockModule;
+use Test::MockTime qw( set_fixed_time );
 use t::lib::TestBuilder;
 
 use C4::Biblio;
@@ -29,6 +31,7 @@ use C4::Circulation;
 
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Library;
+use Koha::Patrons;
 use DateTime::Duration;
 
 use MARC::Record;
@@ -40,12 +43,12 @@ my $dbh = C4::Context->dbh;
 $dbh->do(q|DELETE FROM issues|);
 $dbh->do(q|DELETE FROM borrowers|);
 $dbh->do(q|DELETE FROM items|);
-$dbh->do(q|DELETE FROM branches|);
 $dbh->do(q|DELETE FROM biblio|);
 $dbh->do(q|DELETE FROM categories|);
 $dbh->do(q|DELETE FROM letter|);
 
 my $builder = t::lib::TestBuilder->new;
+set_fixed_time(CORE::time());
 
 my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
 my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
@@ -116,8 +119,8 @@ my $itemnumber2 =
   AddItem( { barcode => $barcode2, %item_infos }, $biblionumber2 );
 
 my $borrowernumber =
-  AddMember( categorycode => $categorycode, branchcode => $branchcode );
-my $borrower = GetMember( borrowernumber => $borrowernumber );
+  Koha::Patron->new({ categorycode => $categorycode, branchcode => $branchcode })->store->borrowernumber;
+my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
 
 my $module = new Test::MockModule('C4::Context');
 $module->mock( 'userenv', sub { { branch => $branchcode } } );
@@ -158,6 +161,11 @@ EOS
         $issue_date = $yesterday_daily;
         AddIssue( $borrower, $barcode2, $date_due, undef, $issue_date );
 
+        # Set timestamps to the same value to avoid a different order
+        Koha::Checkouts->search(
+            { borrowernumber => $borrower->{borrowernumber} }
+        )->update( { timestamp => dt_from_string } );
+
         $expected_slip = <<EOS;
 Checked out:
 
@@ -223,6 +231,11 @@ EOS
         $issue_date = $yesterday->clone;
         AddIssue( $borrower, $barcode2, $date_due_in_time, undef, $issue_date );
 
+        # Set timestamps to the same value to avoid a different order
+        Koha::Checkouts->search(
+            { borrowernumber => $borrower->{borrowernumber} }
+        )->update( { timestamp => dt_from_string } );
+
         $expected_slip = <<EOS;
 Checked out:
 
@@ -240,7 +253,8 @@ Overdues:
 
 EOS
         $slip = IssueSlip( $branchcode, $borrowernumber );
-        is( $slip->{content}, $expected_slip, 'IssueSlip should return a slip with 2 checkouts' );
+        is( $slip->{content}, $expected_slip, 'IssueSlip should return a slip with 2 checkouts' )
+            or diag(Dumper(Koha::Checkouts->search({borrowernumber => $borrower->{borrowernumber}})->unblessed));
 
         AddReturn( $barcode1, $branchcode );
         AddReturn( $barcode2, $branchcode );
@@ -404,4 +418,3 @@ subtest 'bad calls' => sub {
 
 $schema->storage->txn_rollback;
 
-1;