#!/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'");