Bug 20287: Replace occurrences of AddMember with Koha::Patron->new->store->borrowernumber
[koha.git] / t / db_dependent / Circulation / issue.t
index fde7613..6f190f0 100644 (file)
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 31;
+use Test::More tests => 32;
 use DateTime::Duration;
 
 use t::lib::Mocks;
@@ -27,10 +27,11 @@ use C4::Biblio;
 use C4::Circulation;
 use C4::Context;
 use C4::Items;
-use C4::Members;
 use C4::Reserves;
+use Koha::Checkouts;
 use Koha::Database;
 use Koha::DateUtils;
+use Koha::Holds;
 use Koha::Library;
 use Koha::Patrons;
 
@@ -141,19 +142,19 @@ my @sampleitem2 = C4::Items::AddItem(
 my $item_id2 = $sampleitem2[2];
 
 #Add borrower
-my $borrower_id1 = C4::Members::AddMember(
+my $borrower_id1 = Koha::Patron->new({
     firstname    => 'firstname1',
     surname      => 'surname1 ',
     categorycode => $categorycode,
     branchcode   => $branchcode_1
-);
+})->store->borrowernumber;
 my $borrower_1 = Koha::Patrons->find( $borrower_id1 )->unblessed;
-my $borrower_id2 = C4::Members::AddMember(
+my $borrower_id2 = Koha::Patron->new({
     firstname    => 'firstname2',
     surname      => 'surname2 ',
     categorycode => $categorycode,
     branchcode   => $branchcode_2,
-);
+})->store->borrowernumber;
 my $borrower_2 = Koha::Patrons->find( $borrower_id2 )->unblessed;
 
 my @USERENV = (
@@ -190,11 +191,10 @@ like(
     qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/,
     "Koha::Schema::Result::Issue->date_due() returns a date"
 );
-my $issue_id1 = $dbh->last_insert_id( undef, undef, 'issues', undef );
+my $issue_id1 = $issue1->issue_id;
 
 my $issue2 = C4::Circulation::AddIssue( $borrower_1, 'nonexistent_barcode' );
 is( $issue2, undef, "AddIssue returns undef if no datedue is specified" );
-my $issue_id2 = $dbh->last_insert_id( undef, undef, 'issues', undef );
 
 $sth->execute;
 $countissue = $sth -> fetchrow_array;
@@ -206,8 +206,11 @@ $sth = $dbh->prepare($query);
 $sth->execute;
 my $countaccount = $sth -> fetchrow_array;
 is ($countaccount,0,"0 accountline exists");
-is( C4::Circulation::AddIssuingCharge( $item_id1, $borrower_id1, 10 ),
-    1, "An issuing charge has been added" );
+my $checkout = Koha::Checkouts->find( $issue_id1 );
+my $offset = C4::Circulation::AddIssuingCharge( $checkout, 10 );
+is( ref( $offset ), 'Koha::Account::Offset', "An issuing charge has been added" );
+my $charge = Koha::Account::Lines->find( $offset->debit_id );
+is( $charge->issue_id, $issue_id1, 'Issue id is set correctly for issuing charge' );
 my $account_id = $dbh->last_insert_id( undef, undef, 'accountlines', undef );
 $sth->execute;
 $countaccount = $sth -> fetchrow_array;
@@ -372,8 +375,8 @@ my $reserve_id = AddReserve($branchcode_1, $borrower_id1, $biblionumber,
     undef,  1, undef, undef, "a note", "a title", undef, '');
 ok( $reserve_id, 'The reserve should have been inserted' );
 AddIssue( $borrower_2, $barcode_1, dt_from_string, 'cancel' );
-my $reserve = GetReserve( $reserve_id );
-is( $reserve, undef, 'The reserve should have been correctly cancelled' );
+my $hold = Koha::Holds->find( $reserve_id );
+is( $hold, undef, 'The reserve should have been correctly cancelled' );
 
 #End transaction
 $schema->storage->txn_rollback;