Lines 1-11
Link Here
|
1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
2 |
|
2 |
|
3 |
# Some tests for SIP::ILS::Patron |
3 |
# This file is part of Koha |
4 |
# This needs to be extended! Your help is appreciated.. |
4 |
# |
|
|
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <https://www.gnu.org/licenses>. |
5 |
|
17 |
|
6 |
use Modern::Perl; |
18 |
use Modern::Perl; |
7 |
use Test::NoWarnings; |
19 |
use Test::NoWarnings; |
8 |
use Test::More tests => 12; |
20 |
use Test::More tests => 10; |
|
|
21 |
use Test::Warn; |
9 |
|
22 |
|
10 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
11 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
Lines 17-64
use Koha::DateUtils qw( dt_from_string output_pref );
Link Here
|
17 |
use Koha::Patron::Attributes; |
30 |
use Koha::Patron::Attributes; |
18 |
use Koha::Patrons; |
31 |
use Koha::Patrons; |
19 |
|
32 |
|
20 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
21 |
$schema->storage->txn_begin; |
|
|
22 |
|
23 |
my $builder = t::lib::TestBuilder->new(); |
34 |
my $builder = t::lib::TestBuilder->new(); |
24 |
my $patron1 = $builder->build( { source => 'Borrower' } ); |
|
|
25 |
my $card = $patron1->{cardnumber}; |
26 |
|
27 |
# Check existing card number |
28 |
my $sip_patron = C4::SIP::ILS::Patron->new($card); |
29 |
is( defined $sip_patron, 1, "Patron is valid" ); |
30 |
|
35 |
|
31 |
# Check invalid cardnumber by deleting patron |
36 |
subtest "patron creation tests" => sub { |
32 |
$schema->resultset('Borrower')->search( { cardnumber => $card } )->delete; |
|
|
33 |
my $sip_patron2 = C4::SIP::ILS::Patron->new($card); |
34 |
is( $sip_patron2, undef, "Patron is not valid (anymore)" ); |
35 |
|
37 |
|
36 |
subtest "new tests" => sub { |
38 |
plan tests => 10; |
37 |
|
39 |
|
38 |
plan tests => 5; |
40 |
$schema->storage->txn_begin; |
39 |
|
|
|
40 |
my $patron = $builder->build( { source => 'Borrower' } ); |
41 |
|
41 |
|
|
|
42 |
my $patron = $builder->build( { source => 'Borrower' } ); |
42 |
my $cardnumber = $patron->{cardnumber}; |
43 |
my $cardnumber = $patron->{cardnumber}; |
43 |
my $userid = $patron->{userid}; |
44 |
my $userid = $patron->{userid}; |
44 |
my $borrowernumber = $patron->{borrowernumber}; |
45 |
my $borrowernumber = $patron->{borrowernumber}; |
45 |
|
46 |
|
46 |
my $ils_patron = C4::SIP::ILS::Patron->new($cardnumber); |
47 |
# Test valid patron creation |
47 |
is( ref($ils_patron), 'C4::SIP::ILS::Patron', 'Found patron via cardnumber scalar' ); |
48 |
my $sip_patron = C4::SIP::ILS::Patron->new($cardnumber); |
48 |
$ils_patron = C4::SIP::ILS::Patron->new($userid); |
49 |
is( ref($sip_patron), 'C4::SIP::ILS::Patron', 'Found patron via cardnumber scalar' ); |
49 |
is( ref($ils_patron), 'C4::SIP::ILS::Patron', 'Found patron via userid scalar' ); |
50 |
|
50 |
$ils_patron = C4::SIP::ILS::Patron->new( { borrowernumber => $borrowernumber } ); |
51 |
$sip_patron = C4::SIP::ILS::Patron->new($userid); |
51 |
is( ref($ils_patron), 'C4::SIP::ILS::Patron', 'Found patron via borrowernumber hashref' ); |
52 |
is( ref($sip_patron), 'C4::SIP::ILS::Patron', 'Found patron via userid scalar' ); |
52 |
$ils_patron = C4::SIP::ILS::Patron->new( { cardnumber => $cardnumber } ); |
53 |
|
53 |
is( ref($ils_patron), 'C4::SIP::ILS::Patron', 'Found patron via cardnumber hashref' ); |
54 |
$sip_patron = C4::SIP::ILS::Patron->new( { borrowernumber => $borrowernumber } ); |
54 |
$ils_patron = C4::SIP::ILS::Patron->new( { userid => $userid } ); |
55 |
is( ref($sip_patron), 'C4::SIP::ILS::Patron', 'Found patron via borrowernumber hashref' ); |
55 |
is( ref($ils_patron), 'C4::SIP::ILS::Patron', 'Found patron via userid hashref' ); |
56 |
|
|
|
57 |
$sip_patron = C4::SIP::ILS::Patron->new( { cardnumber => $cardnumber } ); |
58 |
is( ref($sip_patron), 'C4::SIP::ILS::Patron', 'Found patron via cardnumber hashref' ); |
59 |
|
60 |
$sip_patron = C4::SIP::ILS::Patron->new( { userid => $userid } ); |
61 |
is( ref($sip_patron), 'C4::SIP::ILS::Patron', 'Found patron via userid hashref' ); |
62 |
|
63 |
# Test invalid patron scenarios |
64 |
my $sip_patron2 = C4::SIP::ILS::Patron->new('NONEXISTENT'); |
65 |
is( $sip_patron2, undef, "Nonexistent patron returns undef" ); |
66 |
|
67 |
# Test undefined/empty input handling (no warnings expected) |
68 |
warnings_are { |
69 |
my $sip_patron3 = C4::SIP::ILS::Patron->new(undef); |
70 |
is( $sip_patron3, undef, "Undefined patron_id returns undef" ); |
71 |
} |
72 |
[], 'No warnings for undefined patron_id'; |
73 |
|
74 |
warnings_are { |
75 |
my $sip_patron4 = C4::SIP::ILS::Patron->new(''); |
76 |
is( $sip_patron4, undef, "Empty patron_id returns undef" ); |
77 |
} |
78 |
[], 'No warnings for empty patron_id'; |
79 |
|
80 |
$schema->storage->txn_rollback; |
56 |
}; |
81 |
}; |
57 |
|
82 |
|
58 |
subtest "OverduesBlockCirc tests" => sub { |
83 |
subtest "OverduesBlockCirc tests" => sub { |
59 |
|
84 |
|
60 |
plan tests => 6; |
85 |
plan tests => 6; |
61 |
|
86 |
|
|
|
87 |
$schema->storage->txn_begin; |
88 |
|
62 |
my $odue_patron = $builder->build( |
89 |
my $odue_patron = $builder->build( |
63 |
{ |
90 |
{ |
64 |
source => 'Borrower', |
91 |
source => 'Borrower', |
Lines 102-113
subtest "OverduesBlockCirc tests" => sub {
Link Here
|
102 |
$odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} ); |
129 |
$odue_sip_patron = C4::SIP::ILS::Patron->new( $good_patron->{cardnumber} ); |
103 |
is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'Block'" ); |
130 |
is( $odue_sip_patron->{charge_ok}, 1, "Not blocked without overdues when set to 'Block'" ); |
104 |
|
131 |
|
|
|
132 |
$schema->storage->txn_rollback; |
105 |
}; |
133 |
}; |
106 |
|
134 |
|
107 |
subtest "Test build_patron_attribute_string" => sub { |
135 |
subtest "Test build_patron_attribute_string" => sub { |
108 |
|
136 |
|
109 |
plan tests => 2; |
137 |
plan tests => 2; |
110 |
|
138 |
|
|
|
139 |
$schema->storage->txn_begin; |
140 |
|
111 |
my $patron = $builder->build( { source => 'Borrower' } ); |
141 |
my $patron = $builder->build( { source => 'Borrower' } ); |
112 |
|
142 |
|
113 |
my $attribute_type = $builder->build( { source => 'BorrowerAttributeType' } ); |
143 |
my $attribute_type = $builder->build( { source => 'BorrowerAttributeType' } ); |
Lines 146-157
subtest "Test build_patron_attribute_string" => sub {
Link Here
|
146 |
$attribute_string, "XYTest Attribute|YZAnother Test Attribute|", |
176 |
$attribute_string, "XYTest Attribute|YZAnother Test Attribute|", |
147 |
'Attribute field generated correctly with multiple params' |
177 |
'Attribute field generated correctly with multiple params' |
148 |
); |
178 |
); |
|
|
179 |
|
180 |
$schema->storage->txn_rollback; |
149 |
}; |
181 |
}; |
150 |
|
182 |
|
151 |
subtest "Test build_custom_field_string" => sub { |
183 |
subtest "Test build_custom_field_string" => sub { |
152 |
|
184 |
|
153 |
plan tests => 5; |
185 |
plan tests => 5; |
154 |
|
186 |
|
|
|
187 |
$schema->storage->txn_begin; |
188 |
|
155 |
my $patron = |
189 |
my $patron = |
156 |
$builder->build_object( { class => 'Koha::Patrons', value => { surname => "Duck", firstname => "Darkwing" } } ); |
190 |
$builder->build_object( { class => 'Koha::Patrons', value => { surname => "Duck", firstname => "Darkwing" } } ); |
157 |
|
191 |
|
Lines 199-210
subtest "Test build_custom_field_string" => sub {
Link Here
|
199 |
'Custom fields processed correctly, bad template generate no text' |
233 |
'Custom fields processed correctly, bad template generate no text' |
200 |
); |
234 |
); |
201 |
|
235 |
|
|
|
236 |
$schema->storage->txn_rollback; |
202 |
}; |
237 |
}; |
203 |
|
238 |
|
204 |
subtest "fine_items tests" => sub { |
239 |
subtest "fine_items tests" => sub { |
205 |
|
240 |
|
206 |
plan tests => 12; |
241 |
plan tests => 12; |
207 |
|
242 |
|
|
|
243 |
$schema->storage->txn_begin; |
244 |
|
208 |
my $patron = $builder->build( |
245 |
my $patron = $builder->build( |
209 |
{ |
246 |
{ |
210 |
source => 'Borrower', |
247 |
source => 'Borrower', |
Lines 261-275
subtest "fine_items tests" => sub {
Link Here
|
261 |
# Check an invalid start boundary |
298 |
# Check an invalid start boundary |
262 |
$fine_items = $sip_patron->fine_items( 98, 99 ); |
299 |
$fine_items = $sip_patron->fine_items( 98, 99 ); |
263 |
is( @$fine_items, 0, "Got zero fine items" ); |
300 |
is( @$fine_items, 0, "Got zero fine items" ); |
264 |
}; |
|
|
265 |
|
301 |
|
266 |
$schema->storage->txn_rollback; |
302 |
$schema->storage->txn_rollback; |
|
|
303 |
}; |
267 |
|
304 |
|
268 |
subtest "Patron expiration tests" => sub { |
305 |
subtest "Patron expiration tests" => sub { |
269 |
|
306 |
|
270 |
plan tests => 5; |
307 |
plan tests => 5; |
271 |
|
308 |
|
272 |
$schema->storage->txn_begin; |
309 |
$schema->storage->txn_begin; |
|
|
310 |
|
273 |
my $patron = $builder->build_object( |
311 |
my $patron = $builder->build_object( |
274 |
{ |
312 |
{ |
275 |
class => 'Koha::Patrons', |
313 |
class => 'Koha::Patrons', |
Lines 326-332
subtest "Patron expiration tests" => sub {
Link Here
|
326 |
); |
364 |
); |
327 |
|
365 |
|
328 |
$schema->storage->txn_rollback; |
366 |
$schema->storage->txn_rollback; |
329 |
|
|
|
330 |
}; |
367 |
}; |
331 |
|
368 |
|
332 |
subtest "NoIssuesChargeGuarantees tests" => sub { |
369 |
subtest "NoIssuesChargeGuarantees tests" => sub { |
Lines 521-528
subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub {
Link Here
|
521 |
}; |
558 |
}; |
522 |
|
559 |
|
523 |
subtest "Patron messages tests" => sub { |
560 |
subtest "Patron messages tests" => sub { |
|
|
561 |
|
524 |
plan tests => 2; |
562 |
plan tests => 2; |
|
|
563 |
|
525 |
$schema->storage->txn_begin; |
564 |
$schema->storage->txn_begin; |
|
|
565 |
|
526 |
my $today = output_pref( { dt => dt_from_string(), dateonly => 1 } ); |
566 |
my $today = output_pref( { dt => dt_from_string(), dateonly => 1 } ); |
527 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { opacnote => q{} } } ); |
567 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { opacnote => q{} } } ); |
528 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
568 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
529 |
- |
|
|