Lines 4-12
use Modern::Perl;
Link Here
|
4 |
|
4 |
|
5 |
use C4::Members qw/AddMember GetMember GetBorrowercategory/; |
5 |
use C4::Members qw/AddMember GetMember GetBorrowercategory/; |
6 |
use C4::Branch; |
6 |
use C4::Branch; |
|
|
7 |
use C4::Biblio; |
8 |
use C4::Items; |
9 |
use C4::Reserves; |
7 |
use CGI qw ( -utf8 ); |
10 |
use CGI qw ( -utf8 ); |
|
|
11 |
use t::lib::Mocks; |
8 |
|
12 |
|
9 |
use Test::More tests => 15; |
13 |
use Test::More tests => 23; |
10 |
|
14 |
|
11 |
BEGIN { |
15 |
BEGIN { |
12 |
use_ok('C4::ILSDI::Services'); |
16 |
use_ok('C4::ILSDI::Services'); |
Lines 18-23
my $dbh = C4::Context->dbh;
Link Here
|
18 |
$dbh->{AutoCommit} = 0; |
22 |
$dbh->{AutoCommit} = 0; |
19 |
$dbh->{RaiseError} = 1; |
23 |
$dbh->{RaiseError} = 1; |
20 |
|
24 |
|
|
|
25 |
my $maxallowedreserves = 3; |
26 |
t::lib::Mocks::mock_preference('maxreserves', $maxallowedreserves); |
27 |
|
21 |
# Create patron |
28 |
# Create patron |
22 |
my %data = ( |
29 |
my %data = ( |
23 |
firstname => 'my firstname', |
30 |
firstname => 'my firstname', |
Lines 29-34
my %data = (
Link Here
|
29 |
password => 'ilsdi-password', |
36 |
password => 'ilsdi-password', |
30 |
); |
37 |
); |
31 |
|
38 |
|
|
|
39 |
my %data2 = ( |
40 |
firstname => 'Joe', |
41 |
surname => 'John', |
42 |
categorycode => 'UT', |
43 |
branchcode => 'UT', |
44 |
cardnumber => '99999', |
45 |
userid => 'jjohn', |
46 |
password => 'ilsdi-password', |
47 |
); |
48 |
|
32 |
# Crate patron category |
49 |
# Crate patron category |
33 |
unless ( GetBorrowercategory('UT') ) { |
50 |
unless ( GetBorrowercategory('UT') ) { |
34 |
$dbh->do("INSERT INTO categories |
51 |
$dbh->do("INSERT INTO categories |
Lines 44-51
unless ( GetBranchDetail('UT') ) {
Link Here
|
44 |
|
61 |
|
45 |
|
62 |
|
46 |
my $borrowernumber = AddMember(%data); |
63 |
my $borrowernumber = AddMember(%data); |
|
|
64 |
my $borrowernumber2 = AddMember(%data2); |
47 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
65 |
my $borrower = GetMember( borrowernumber => $borrowernumber ); |
48 |
|
66 |
|
|
|
67 |
# Create biblio and item |
68 |
my %item_branch_infos = ( |
69 |
homebranch => 'UT', |
70 |
holdingbranch => 'UT', |
71 |
); |
72 |
|
73 |
my $record = MARC::Record->new; |
74 |
my $title = MARC::Field->new('200','','','a' => 'Hello world.'); |
75 |
$record->append_fields($title); |
76 |
|
77 |
my ($biblionumber) = AddBiblio($record, ''); |
78 |
my ($biblionumber2) = AddBiblio(MARC::Record->new, ''); |
79 |
my ($biblionumber3) = AddBiblio(MARC::Record->new, ''); |
80 |
my ($biblionumber4) = AddBiblio(MARC::Record->new, ''); |
81 |
my $itemnumber = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber); |
82 |
my $itemnumber2 = AddItem({ barcode => '0201', %item_branch_infos }, $biblionumber2); |
83 |
my $itemnumber3 = AddItem({ barcode => '0301', %item_branch_infos }, $biblionumber3); |
84 |
my $itemnumber4 = AddItem({ barcode => '0401', %item_branch_infos }, $biblionumber4); |
85 |
|
49 |
{ # AuthenticatePatron test |
86 |
{ # AuthenticatePatron test |
50 |
|
87 |
|
51 |
my $query = new CGI; |
88 |
my $query = new CGI; |
Lines 90-92
my $borrower = GetMember( borrowernumber => $borrowernumber );
Link Here
|
90 |
|
127 |
|
91 |
} |
128 |
} |
92 |
|
129 |
|
93 |
- |
130 |
{ # Add reserves tests |
|
|
131 |
|
132 |
my $query = new CGI; |
133 |
$query->param('patron_id',$borrowernumber); |
134 |
$query->param('bib_id', $biblionumber); |
135 |
$query->param('request_location','127.0.0.1'); |
136 |
my $reply = C4::ILSDI::Services::HoldTitle($query); |
137 |
is($reply->{'title'}, 'Hello world.'); |
138 |
is($reply->{'pickup_location'}, 'Unit test library', 'Hold title'); |
139 |
|
140 |
$reply = C4::ILSDI::Services::HoldTitle($query); |
141 |
is($reply->{'code'}, 'NotHoldable', 'Hold same title again - ILSDI'); |
142 |
|
143 |
$query->param('bib_id', $biblionumber2); |
144 |
$reply = C4::ILSDI::Services::HoldTitle($query); |
145 |
is($reply->{'pickup_location'}, 'Unit test library', 'Hold a second title - ILSDI'); |
146 |
|
147 |
$query->param('bib_id', $biblionumber3); |
148 |
$reply = C4::ILSDI::Services::HoldTitle($query); |
149 |
is($reply->{'pickup_location'}, 'Unit test library', 'Hold a third title - ILSDI'); |
150 |
|
151 |
$query->param('bib_id', $biblionumber4); |
152 |
$reply = C4::ILSDI::Services::HoldTitle($query); |
153 |
is($reply->{'code'}, 'NotHoldable', 'Hold a fourth title - ILSDI'); |
154 |
|
155 |
$query->param('bib_id', $biblionumber4); |
156 |
$query->param('item_id', $itemnumber4); |
157 |
$reply = C4::ILSDI::Services::HoldItem($query); |
158 |
is($reply->{'code'}, 'NotHoldable', 'Hold a fourth item - ILSDI'); |
159 |
|
160 |
$query->param('bib_id', $biblionumber); |
161 |
$query->param('patron_id',$borrowernumber2); |
162 |
$query->param('item_id', $itemnumber); |
163 |
$reply = C4::ILSDI::Services::HoldItem($query); |
164 |
is($reply->{'pickup_location'}, 'Unit test library', 'Joe John hold an item - ILSDI'); |
165 |
} |