|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use Test::More tests => 22; |
| 6 |
use Test::MockModule; |
| 7 |
|
| 8 |
use C4::Biblio; |
| 9 |
use C4::Items; |
| 10 |
use C4::Members; |
| 11 |
use C4::Branch; |
| 12 |
use C4::Category; |
| 13 |
use MARC::Record; |
| 14 |
|
| 15 |
BEGIN { |
| 16 |
use_ok('C4::Circulation'); |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
my $dbh = C4::Context->dbh; |
| 21 |
$dbh->{AutoCommit} = 0; |
| 22 |
$dbh->{RaiseError} = 1; |
| 23 |
|
| 24 |
$dbh->do(q|DELETE FROM issues|); |
| 25 |
$dbh->do(q|DELETE FROM borrowers|); |
| 26 |
$dbh->do(q|DELETE FROM branches|); |
| 27 |
$dbh->do(q|DELETE FROM biblio|); |
| 28 |
$dbh->do(q|DELETE FROM items|); |
| 29 |
$dbh->do(q|DELETE FROM categories|); |
| 30 |
|
| 31 |
|
| 32 |
my $branchcode = 'B'; |
| 33 |
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' }); |
| 34 |
|
| 35 |
my $categorycode = 'C'; |
| 36 |
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode); |
| 37 |
|
| 38 |
my %item_branch_infos = ( |
| 39 |
homebranch => $branchcode, |
| 40 |
holdingbranch => $branchcode, |
| 41 |
); |
| 42 |
|
| 43 |
my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); |
| 44 |
my $barcode1 = '0101'; |
| 45 |
AddItem({ barcode => $barcode1, %item_branch_infos }, $biblionumber1); |
| 46 |
my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); |
| 47 |
my $barcode2 = '0202'; |
| 48 |
AddItem({ barcode => $barcode2, %item_branch_infos }, $biblionumber2); |
| 49 |
|
| 50 |
my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode); |
| 51 |
my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode); |
| 52 |
my $borrower1 = GetMember(borrowernumber => $borrowernumber1); |
| 53 |
my $borrower2 = GetMember(borrowernumber => $borrowernumber2); |
| 54 |
|
| 55 |
my $module = new Test::MockModule('C4::Context'); |
| 56 |
$module->mock('userenv', sub { { branch => $branchcode } }); |
| 57 |
|
| 58 |
|
| 59 |
my $check_if_issued = C4::Circulation::CheckIfIssuedToPatron(); |
| 60 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' ); |
| 61 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1); |
| 62 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' ); |
| 63 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, undef); |
| 64 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' ); |
| 65 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber1); |
| 66 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns unef' ); |
| 67 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber2); |
| 68 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 69 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber1); |
| 70 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 71 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2); |
| 72 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 73 |
|
| 74 |
AddIssue($borrower1, '0101'); |
| 75 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(); |
| 76 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' ); |
| 77 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1); |
| 78 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' ); |
| 79 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, undef); |
| 80 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' ); |
| 81 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber1); |
| 82 |
is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' ); |
| 83 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber2); |
| 84 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 85 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber1); |
| 86 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 87 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2); |
| 88 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 89 |
|
| 90 |
AddIssue($borrower2, '0202'); |
| 91 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(); |
| 92 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without argument returns undef' ); |
| 93 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron(undef, $biblionumber1); |
| 94 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the borrower number returns undef' ); |
| 95 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, undef); |
| 96 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron without the biblio number returns undef' ); |
| 97 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber1); |
| 98 |
is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' ); |
| 99 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber1, $biblionumber2); |
| 100 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 101 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber1); |
| 102 |
is( $check_if_issued, undef, 'CheckIfIssuedToPatron returns undef' ); |
| 103 |
$check_if_issued = C4::Circulation::CheckIfIssuedToPatron($borrowernumber2, $biblionumber2); |
| 104 |
is( $check_if_issued, 1, 'CheckIfIssuedToPatron returns true' ); |
| 105 |
|
| 106 |
$dbh->rollback(); |