Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
use Modern::Perl; |
4 |
|
5 |
use Test::More tests => 20; |
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 C4::Circulation; |
14 |
use MARC::Record; |
15 |
|
16 |
|
17 |
my $dbh = C4::Context->dbh; |
18 |
$dbh->{AutoCommit} = 0; |
19 |
$dbh->{RaiseError} = 1; |
20 |
|
21 |
$dbh->do(q|DELETE FROM borrowers|); |
22 |
$dbh->do(q|DELETE FROM branches|); |
23 |
$dbh->do(q|DELETE FROM biblio|); |
24 |
$dbh->do(q|DELETE FROM items|); |
25 |
$dbh->do(q|DELETE FROM categories|); |
26 |
|
27 |
|
28 |
my $branchcode = 'B'; |
29 |
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' }); |
30 |
|
31 |
my $categorycode = 'C'; |
32 |
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode); |
33 |
|
34 |
my %item_branch_infos = ( |
35 |
homebranch => $branchcode, |
36 |
holdingbranch => $branchcode, |
37 |
); |
38 |
|
39 |
my ($biblionumber1) = AddBiblio(MARC::Record->new, ''); |
40 |
my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1); |
41 |
my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1); |
42 |
|
43 |
my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); |
44 |
my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2); |
45 |
|
46 |
my $borrowernumber1 = AddMember(categorycode => $categorycode, branchcode => $branchcode); |
47 |
my $borrowernumber2 = AddMember(categorycode => $categorycode, branchcode => $branchcode); |
48 |
my $borrower1 = GetMember(borrowernumber => $borrowernumber1); |
49 |
my $borrower2 = GetMember(borrowernumber => $borrowernumber2); |
50 |
|
51 |
my $module = new Test::MockModule('C4::Context'); |
52 |
$module->mock('userenv', sub { { branch => $branchcode } }); |
53 |
|
54 |
|
55 |
my $issues = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2); |
56 |
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); |
57 |
|
58 |
AddIssue($borrower1, '0101'); |
59 |
$issues = C4::Members::GetPendingIssues($borrowernumber1); |
60 |
is( @$issues, 1, 'GetPendingIssues returns the correct number of elements' ); |
61 |
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
62 |
my $issues_bis = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2); |
63 |
is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' ); |
64 |
$issues = C4::Members::GetPendingIssues($borrowernumber2); |
65 |
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); |
66 |
|
67 |
AddIssue($borrower1, '0102'); |
68 |
$issues = C4::Members::GetPendingIssues($borrowernumber1); |
69 |
is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' ); |
70 |
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
71 |
is( $issues->[1]->{itemnumber}, $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); |
72 |
$issues_bis = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2); |
73 |
is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' ); |
74 |
$issues = C4::Members::GetPendingIssues($borrowernumber2); |
75 |
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); |
76 |
|
77 |
AddIssue($borrower2, '0203'); |
78 |
$issues = C4::Members::GetPendingIssues($borrowernumber2); |
79 |
is( @$issues, 1, 'GetAllIssues returns the correct number of elements' ); |
80 |
is( $issues->[0]->{itemnumber}, $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' ); |
81 |
$issues = C4::Members::GetPendingIssues($borrowernumber1); |
82 |
is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' ); |
83 |
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
84 |
is( $issues->[1]->{itemnumber}, $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); |
85 |
$issues = C4::Members::GetPendingIssues($borrowernumber1, $borrowernumber2); |
86 |
is( @$issues, 3, 'GetPendingIssues returns the correct number of elements' ); |
87 |
is( $issues->[0]->{itemnumber}, $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
88 |
is( $issues->[1]->{itemnumber}, $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); |
89 |
is( $issues->[2]->{itemnumber}, $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' ); |
90 |
|
91 |
$issues = C4::Members::GetPendingIssues(); |
92 |
is( @$issues, 0, 'GetPendingIssues without borrower numbers returns an empty array' ); |
93 |
|
94 |
$dbh->rollback(); |