use Modern::Perl;
-use Test::More tests => 31;
+use Test::More tests => 32;
use DateTime::Duration;
use t::lib::Mocks;
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;
$dbh->do(q|DELETE FROM issues|);
$dbh->do(q|DELETE FROM items|);
$dbh->do(q|DELETE FROM borrowers|);
-$dbh->do(q|DELETE FROM branches|);
$dbh->do(q|DELETE FROM categories|);
$dbh->do(q|DELETE FROM accountlines|);
$dbh->do(q|DELETE FROM issuingrules|);
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 = (
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;
$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;
# Test AddRenewal
+my $se = Test::MockModule->new( 'C4::Context' );
+$se->mock( 'interface', sub {return 'intranet'});
+
# Let's renew this one at a different library for statistical purposes to test Bug 17781
C4::Context->set_userenv(@USERENV_DIFFERENT_LIBRARY);
my $datedue3 = AddRenewal( $borrower_id1, $item_id1, $branchcode_1, $datedue1, $daysago10 );
my $stat = $dbh->selectrow_hashref("SELECT * FROM statistics WHERE type = 'renew' AND borrowernumber = ? AND itemnumber = ? AND branch = ?", undef, $borrower_id1, $item_id1, $branchcode_3 );
ok( $stat, "Bug 17781 - 'Improper branchcode set during renewal' still fixed" );
+$se->mock( 'interface', sub {return 'opac'});
+
#Let's do an opac renewal - whatever branchcode we send should be used
-my $opac_renew_issue = $builder->build({ source=>"Issue",value=>{
+my $opac_renew_issue = $builder->build({
+ source=>"Issue",
+ value=>{
date_due => '2017-01-01',
branch => $branchcode_1,
itype => $itemtype,
borrowernumber => $borrower_id1
- }
- });
+ }
+});
-my $datedue4 = AddRenewal( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, "Stavromula", $datedue1, $daysago10, 1 );
+my $datedue4 = AddRenewal( $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, "Stavromula", $datedue1, $daysago10 );
$stat = $dbh->selectrow_hashref("SELECT * FROM statistics WHERE type = 'renew' AND borrowernumber = ? AND itemnumber = ? AND branch = ?", undef, $opac_renew_issue->{borrowernumber}, $opac_renew_issue->{itemnumber}, "Stavromula" );
ok( $stat, "Bug 18572 - 'Bug 18572 - OpacRenewalBranch is now respected" );
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;