Lines 6-19
Link Here
|
6 |
use strict; |
6 |
use strict; |
7 |
use warnings; |
7 |
use warnings; |
8 |
|
8 |
|
9 |
use Test::More tests => 4; |
9 |
use Test::More tests => 7; |
|
|
10 |
|
11 |
use MARC::Record; |
12 |
use MARC::Field; |
10 |
|
13 |
|
11 |
BEGIN { |
14 |
BEGIN { |
12 |
use FindBin; |
15 |
use FindBin; |
13 |
use lib "$FindBin::Bin/../../C4/SIP"; |
16 |
use lib "$FindBin::Bin/../../C4/SIP"; |
14 |
use_ok('C4::SIP::ILS'); |
17 |
use_ok('C4::SIP::ILS'); |
|
|
18 |
new C4::Context; |
15 |
}; |
19 |
}; |
16 |
|
20 |
|
|
|
21 |
use C4::Members; |
22 |
use Koha::Borrower::Debarments; |
23 |
use C4::Circulation; |
24 |
use C4::Biblio; |
25 |
use C4::Items; |
26 |
use Sip; |
27 |
|
28 |
#Make the database handle non-autocommitting |
29 |
my $dbh = C4::Context->dbh; |
30 |
$dbh->{AutoCommit} = 0; |
31 |
$dbh->{RaiseError} = 1; |
32 |
|
33 |
# Now, set a userenv |
34 |
C4::Context->_new_userenv('xxx'); |
35 |
C4::Context::set_userenv(0,0,0,'firstname','surname', 'CPL', 'Joensuun pääkirjasto', '', '', ''); |
36 |
|
37 |
testCheckinDebarredBorrower(); |
38 |
|
17 |
my $transaction = ILS::Transaction::RenewAll->new(); |
39 |
my $transaction = ILS::Transaction::RenewAll->new(); |
18 |
|
40 |
|
19 |
$transaction->patron(my $patron = ILS::Patron->new(23529000120056)); |
41 |
$transaction->patron(my $patron = ILS::Patron->new(23529000120056)); |
Lines 27-29
$transaction2->patron(my $patron2 = ILS::Patron->new("ABCDE12345"));
Link Here
|
27 |
ok(!defined $patron2, "patron code: ABCDE12345 is invalid"); |
49 |
ok(!defined $patron2, "patron code: ABCDE12345 is invalid"); |
28 |
|
50 |
|
29 |
ok($transaction->do_renew_all(), "items renewed correctly"); |
51 |
ok($transaction->do_renew_all(), "items renewed correctly"); |
30 |
- |
52 |
|
|
|
53 |
=head testCheckinDebarredBorrower |
54 |
|
55 |
There is a nasty bug where checking in Items from a debarred Borrower takes dozens of seconds. |
56 |
In this time SIP-connections timeout. |
57 |
This test creates two Borrowers, two Items and two Checkouts, the first being a normal case, |
58 |
and the second being the debarred case. |
59 |
First test: we check-in the normal Item and time the performance. |
60 |
Second test: we check-in the bugged Item and time the performance. |
61 |
=cut |
62 |
sub testCheckinDebarredBorrower { |
63 |
my ($borrowers, $biblios, $items) = _init_testCheckinDebarredBorrower(); |
64 |
|
65 |
my $borrower = $biblios->[0]; |
66 |
my $borrowerDebarred = $biblios->[1]; |
67 |
my $item = $items->[0]; |
68 |
my $ilsItem = new ILS::Item $item->{barcode}; |
69 |
my $itemForDebarred = $items->[1]; |
70 |
my $ilsItemForDebarred = new ILS::Item $itemForDebarred->{barcode}; |
71 |
|
72 |
#Test1 |
73 |
my $startTime = time; |
74 |
my $checkin = new ILS::Transaction::Checkin; |
75 |
# BEGIN TRANSACTION |
76 |
$checkin->item($ilsItem); |
77 |
$checkin->do_checkin( C4::Context->userenv->{'branch'} , Sip::timestamp(DateTime->now(time_zone => C4::Context->tz())->iso8601()) ); |
78 |
my $endTime = time; |
79 |
ok(($endTime-$startTime) < 5, 'Check-in debarred borrower: Normally check-in happens in < 5 seconds.'); |
80 |
|
81 |
#Test2 |
82 |
$startTime = time; |
83 |
my $checkinForDebarred = new ILS::Transaction::Checkin; |
84 |
# BEGIN TRANSACTION |
85 |
$checkin->item($ilsItemForDebarred); |
86 |
$checkin->do_checkin( C4::Context->userenv->{'branch'} , Sip::timestamp(DateTime->now(time_zone => C4::Context->tz())->iso8601()) ); |
87 |
$endTime = time; |
88 |
ok(($endTime-$startTime) < 5, "Check-in debarred borrower: Check-in for a debarred borrower doesn't take more than 5 seconds."); |
89 |
} |
90 |
sub _init_testCheckinDebarredBorrower { |
91 |
my $borrowernumberDebarred = C4::Members::AddMember( |
92 |
cardnumber => 'asdAasdasdasd', |
93 |
firstname => 'Asd', |
94 |
surname => 'Asdasd', |
95 |
categorycode => 'PT', |
96 |
branchcode => 'CPL', |
97 |
dateofbirth => '1985-10-12', |
98 |
# dateexpiry => '9999-12-31', #IF we enable dateexpiry for year 9999, we get the same issue for borrowers than we get here for Issues. |
99 |
userid => 'asd123' |
100 |
); |
101 |
my $borrowernumber = C4::Members::AddMember( |
102 |
cardnumber => 'asdAdebarred', |
103 |
firstname => 'De', |
104 |
surname => 'Barred', |
105 |
categorycode => 'PT', |
106 |
branchcode => 'CPL', |
107 |
dateofbirth => '1985-10-12', |
108 |
# dateexpiry => '9999-12-31', |
109 |
userid => 'debarred' |
110 |
); |
111 |
my $borrowerDebarred = C4::Members::GetMember(borrowernumber => $borrowernumberDebarred); |
112 |
my $borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); |
113 |
Koha::Borrower::Debarments::AddDebarment({ |
114 |
borrowernumber => $borrowernumberDebarred, |
115 |
# expiration => '', |
116 |
# type => '', |
117 |
comment => 'TESTING DEBARRMENT SETTING', |
118 |
}); |
119 |
|
120 |
# Generate a record with just the ISBN |
121 |
my $marc_record = MARC::Record->new; |
122 |
$marc_record->append_fields( MARC::Field->new('020','','','a' => '0590353403') ); |
123 |
$marc_record->append_fields( MARC::Field->new('245','','','a' => 'Debarred test biblio') ); |
124 |
# Add the record to the DB |
125 |
my( $biblionumber, $biblioitemnumber ) = C4::Biblio::AddBiblio( $marc_record, '' ); |
126 |
my $biblio = C4::Biblio::GetBiblioData( $biblionumber ); |
127 |
|
128 |
#Generate Items |
129 |
my $itemBarcodeForDebarred = 'asdNasdasdasd1'; |
130 |
my $itemBarcode2 = 'asdNdebarreda2'; |
131 |
my ($item_bibnum, $item_bibitemnum, $itemnumberForDebarred, $itemnumber2); |
132 |
($item_bibnum, $item_bibitemnum, $itemnumberForDebarred) = C4::Items::AddItem({ itype => 'BK', homebranch => 'CPL', holdingbranch => 'CPL', barcode => $itemBarcodeForDebarred } , $biblionumber); |
133 |
($item_bibnum, $item_bibitemnum, $itemnumber2) = C4::Items::AddItem({ itype => 'BK', homebranch => 'CPL', holdingbranch => 'CPL', barcode => $itemBarcode2 } , $biblionumber); |
134 |
my $itemForDebarred = C4::Items::GetItem($itemnumberForDebarred); |
135 |
my $item2 = C4::Items::GetItem($itemnumber2); |
136 |
|
137 |
#Checkout Items |
138 |
C4::Circulation::AddIssue($borrowerDebarred, $itemBarcodeForDebarred); |
139 |
C4::Circulation::AddIssue($borrower, $itemBarcode2); |
140 |
|
141 |
#Update borrower references to the DB, since they have been modified. |
142 |
$borrowerDebarred = C4::Members::GetMember(borrowernumber => $borrowernumberDebarred); |
143 |
$borrower = C4::Members::GetMember(borrowernumber => $borrowernumber); |
144 |
|
145 |
return ([$borrower, $borrowerDebarred],[$biblio],[$item2, $itemForDebarred]); |
146 |
} |
147 |
|
148 |
|
149 |
# End transaction |
150 |
$dbh->rollback; |