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 |
my $dbh = C4::Context->dbh; |
17 |
$dbh->{AutoCommit} = 0; |
18 |
$dbh->{RaiseError} = 1; |
19 |
|
20 |
$dbh->do(q|DELETE FROM borrowers|); |
21 |
$dbh->do(q|DELETE FROM branches|); |
22 |
$dbh->do(q|DELETE FROM biblio|); |
23 |
$dbh->do(q|DELETE FROM items|); |
24 |
$dbh->do(q|DELETE FROM categories|); |
25 |
|
26 |
my $branchcode = 'B'; |
27 |
ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } ); |
28 |
|
29 |
my $categorycode = 'C'; |
30 |
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)", |
31 |
undef, $categorycode ); |
32 |
|
33 |
my %item_branch_infos = ( |
34 |
homebranch => $branchcode, |
35 |
holdingbranch => $branchcode, |
36 |
); |
37 |
|
38 |
my ($biblionumber1) = AddBiblio( MARC::Record->new, '' ); |
39 |
my $itemnumber1 = |
40 |
AddItem( { barcode => '0101', %item_branch_infos }, $biblionumber1 ); |
41 |
my $itemnumber2 = |
42 |
AddItem( { barcode => '0102', %item_branch_infos }, $biblionumber1 ); |
43 |
|
44 |
my ($biblionumber2) = AddBiblio( MARC::Record->new, '' ); |
45 |
my $itemnumber3 = |
46 |
AddItem( { barcode => '0203', %item_branch_infos }, $biblionumber2 ); |
47 |
|
48 |
my $borrowernumber1 = |
49 |
AddMember( categorycode => $categorycode, branchcode => $branchcode ); |
50 |
my $borrowernumber2 = |
51 |
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 |
my $issues = |
59 |
C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); |
60 |
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); |
61 |
|
62 |
AddIssue( $borrower1, '0101' ); |
63 |
$issues = C4::Members::GetPendingIssues($borrowernumber1); |
64 |
is( @$issues, 1, 'GetPendingIssues returns the correct number of elements' ); |
65 |
is( $issues->[0]->{itemnumber}, |
66 |
$itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
67 |
my $issues_bis = |
68 |
C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); |
69 |
is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' ); |
70 |
$issues = C4::Members::GetPendingIssues($borrowernumber2); |
71 |
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); |
72 |
|
73 |
AddIssue( $borrower1, '0102' ); |
74 |
$issues = C4::Members::GetPendingIssues($borrowernumber1); |
75 |
is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' ); |
76 |
is( $issues->[0]->{itemnumber}, |
77 |
$itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
78 |
is( $issues->[1]->{itemnumber}, |
79 |
$itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); |
80 |
$issues_bis = |
81 |
C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); |
82 |
is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' ); |
83 |
$issues = C4::Members::GetPendingIssues($borrowernumber2); |
84 |
is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); |
85 |
|
86 |
AddIssue( $borrower2, '0203' ); |
87 |
$issues = C4::Members::GetPendingIssues($borrowernumber2); |
88 |
is( @$issues, 1, 'GetAllIssues returns the correct number of elements' ); |
89 |
is( $issues->[0]->{itemnumber}, |
90 |
$itemnumber3, 'GetPendingIssues returns the itemnumber correctly' ); |
91 |
$issues = C4::Members::GetPendingIssues($borrowernumber1); |
92 |
is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' ); |
93 |
is( $issues->[0]->{itemnumber}, |
94 |
$itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
95 |
is( $issues->[1]->{itemnumber}, |
96 |
$itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); |
97 |
$issues = C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); |
98 |
is( @$issues, 3, 'GetPendingIssues returns the correct number of elements' ); |
99 |
is( $issues->[0]->{itemnumber}, |
100 |
$itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); |
101 |
is( $issues->[1]->{itemnumber}, |
102 |
$itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); |
103 |
is( $issues->[2]->{itemnumber}, |
104 |
$itemnumber3, 'GetPendingIssues returns the itemnumber correctly' ); |
105 |
|
106 |
$issues = C4::Members::GetPendingIssues(); |
107 |
is( @$issues, 0, |
108 |
'GetPendingIssues without borrower numbers returns an empty array' ); |
109 |
|
110 |
$dbh->rollback(); |