Koha/t/db_dependent/Circulation.t
Kyle M Hall fc4e74371d Bug 8220 - QA Followup - Unit Test
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>

All tests and qa script pass.

Tests done:
- created a .koc file with return, issue and fine payments.
- queued that file into Koha
- created some transactions using the Firefox plugin
- queued that into Koha
- processed files and checked outcome was ok
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
2013-03-21 20:35:37 -04:00

127 lines
3.8 KiB
Perl
Executable file

#!/usr/bin/perl
use Test::More tests => 16;
BEGIN {
use_ok('C4::Circulation');
}
my $CircControl = C4::Context->preference('CircControl');
my $HomeOrHoldingBranch = C4::Context->preference('HomeOrHoldingBranch');
my $item = {
homebranch => 'ItemHomeBranch',
holdingbranch => 'ItemHoldingBranch'
};
my $borrower = {
branchcode => 'BorrowerBranch'
};
# No userenv, PickupLibrary
C4::Context->set_preference('CircControl', 'PickupLibrary');
is(
C4::Context->preference('CircControl'),
'PickupLibrary',
'CircControl changed to PickupLibrary'
);
is(
C4::Circulation::_GetCircControlBranch($item, $borrower),
$item->{$HomeOrHoldingBranch},
'_GetCircControlBranch returned item branch (no userenv defined)'
);
# No userenv, PatronLibrary
C4::Context->set_preference('CircControl', 'PatronLibrary');
is(
C4::Context->preference('CircControl'),
'PatronLibrary',
'CircControl changed to PatronLibrary'
);
is(
C4::Circulation::_GetCircControlBranch($item, $borrower),
$borrower->{branchcode},
'_GetCircControlBranch returned borrower branch'
);
# No userenv, ItemHomeLibrary
C4::Context->set_preference('CircControl', 'ItemHomeLibrary');
is(
C4::Context->preference('CircControl'),
'ItemHomeLibrary',
'CircControl changed to ItemHomeLibrary'
);
is(
$item->{$HomeOrHoldingBranch},
C4::Circulation::_GetCircControlBranch($item, $borrower),
'_GetCircControlBranch returned item branch'
);
diag('Now, set a userenv');
C4::Context->_new_userenv('xxx');
C4::Context::set_userenv(0,0,0,'firstname','surname', 'CurrentBranch', 'CurrentBranchName', '', '', '');
is(C4::Context->userenv->{branch}, 'CurrentBranch', 'userenv set');
# Userenv set, PickupLibrary
C4::Context->set_preference('CircControl', 'PickupLibrary');
is(
C4::Context->preference('CircControl'),
'PickupLibrary',
'CircControl changed to PickupLibrary'
);
is(
C4::Circulation::_GetCircControlBranch($item, $borrower),
'CurrentBranch',
'_GetCircControlBranch returned current branch'
);
# Userenv set, PatronLibrary
C4::Context->set_preference('CircControl', 'PatronLibrary');
is(
C4::Context->preference('CircControl'),
'PatronLibrary',
'CircControl changed to PatronLibrary'
);
is(
C4::Circulation::_GetCircControlBranch($item, $borrower),
$borrower->{branchcode},
'_GetCircControlBranch returned borrower branch'
);
# Userenv set, ItemHomeLibrary
C4::Context->set_preference('CircControl', 'ItemHomeLibrary');
is(
C4::Context->preference('CircControl'),
'ItemHomeLibrary',
'CircControl changed to ItemHomeLibrary'
);
is(
C4::Circulation::_GetCircControlBranch($item, $borrower),
$item->{$HomeOrHoldingBranch},
'_GetCircControlBranch returned item branch'
);
# Reset initial configuration
C4::Context->set_preference('CircControl', $CircControl);
is(
C4::Context->preference('CircControl'),
$CircControl,
'CircControl reset to its initial value'
);
# Test C4::Circulation::ProcessOfflinePayment
my $sth = C4::Context->dbh->prepare("SELECT COUNT(*) FROM accountlines WHERE amount = '-123.45' AND accounttype = 'Pay'");
$sth->execute();
my ( $original_count ) = $sth->fetchrow_array();
C4::Context->dbh->do("INSERT INTO borrowers ( cardnumber, surname, firstname, categorycode, branchcode ) VALUES ( '99999999999', 'Hall', 'Kyle', 'S', 'MPL' )");
C4::Circulation::ProcessOfflinePayment({ cardnumber => '99999999999', amount => '123.45' });
$sth->execute();
my ( $new_count ) = $sth->fetchrow_array();
ok( $new_count == $original_count + 1, 'ProcessOfflinePayment makes payment correctly' );
C4::Context->dbh->do("DELETE FROM accountlines WHERE borrowernumber IN ( SELECT borrowernumber FROM borrowers WHERE cardnumber = '99999999999' )");
C4::Context->dbh->do("DELETE FROM borrowers WHERE cardnumber = '99999999999'");