3 # Tests for C4::SIP::ILS
4 # Please help to extend them!
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Test::More tests => 12;
25 use t::lib::TestBuilder;
30 use Koha::CirculationRules;
35 use_ok('C4::SIP::ILS');
38 my $schema = Koha::Database->new->schema;
39 $schema->storage->txn_begin;
41 my $builder = t::lib::TestBuilder->new();
43 my $class = 'C4::SIP::ILS';
44 my $institution = { id => 'CPL', };
46 my $ils = $class->new( $institution );
48 isa_ok( $ils, $class );
50 # Check all methods required for interface are there
52 find_patron find_item checkout_ok checkin_ok offline_ok status_update_ok
53 offline_ok checkout checkin end_patron_session pay_fee add_hold cancel_hold
54 alter_hold renew renew_all
57 can_ok( $ils, @methods );
59 is( $ils->institution(), 'CPL', 'institution method returns id' );
61 is( $ils->institution_id(), 'CPL', 'institution_id method returns id' );
63 is( $ils->supports('checkout'), 1, 'checkout supported' );
65 is( $ils->supports('security_inhibit'),
66 q{}, 'unsupported feature returns false' );
68 is( $ils->test_cardnumber_compare( 'A1234', 'a1234' ),
69 1, 'borrower bc test is case insensitive' );
71 is( $ils->test_cardnumber_compare( 'A1234', 'b1234' ),
72 q{}, 'borrower bc test identifies difference' );
74 subtest cancel_hold => sub {
77 my $library = $builder->build_object ({ class => 'Koha::Libraries' });
78 my $patron = $builder->build_object(
80 class => 'Koha::Patrons',
82 branchcode => $library->branchcode,
86 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
88 my $item = $builder->build_sample_item({
89 library => $library->branchcode,
92 Koha::CirculationRules->set_rules(
94 categorycode => $patron->categorycode,
95 branchcode => $library->branchcode,
96 itemtype => $item->effective_itemtype,
100 holds_per_record => 3,
102 lengthunit => 'days',
107 my $reserve1 = AddReserve(
109 branchcode => $library->branchcode,
110 borrowernumber => $patron->borrowernumber,
111 biblionumber => $item->biblio->biblionumber,
112 itemnumber => $item->itemnumber,
115 is( $item->biblio->holds->count(), 1, "Hold was placed on bib");
116 is( $item->holds->count(),1,"Hold was placed on specific item");
118 my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
119 my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
120 my $transaction = $ils->cancel_hold($patron->cardnumber,undef,$item->barcode,undef);
122 is( $transaction->{screen_msg},"Hold Cancelled.","We get a success message when hold cancelled");
124 is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining");
125 is( $item->holds->count(), 0, "Item has 0 holds remaining");
128 subtest checkout => sub {
131 my $library = $builder->build_object ({ class => 'Koha::Libraries' });
132 my $patron = $builder->build_object(
134 class => 'Koha::Patrons',
136 branchcode => $library->branchcode,
140 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
142 my $item = $builder->build_sample_item({
143 library => $library->branchcode,
146 Koha::CirculationRules->set_rules(
148 categorycode => $patron->categorycode,
149 branchcode => $library->branchcode,
150 itemtype => $item->effective_itemtype,
153 reservesallowed => 3,
154 holds_per_record => 3,
156 lengthunit => 'days',
157 renewalsallowed => 6,
162 AddIssue( $patron->unblessed, $item->barcode, undef, 0 );
163 my $checkout = $item->checkout;
164 ok( defined($checkout), "Checkout added");
165 is( $checkout->renewals, 0, "Correct renewals");
167 my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
168 my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
169 my $transaction = $ils->checkout($patron->cardnumber,$item->barcode,undef,undef);
171 is( $transaction->{screen_msg},"Item already checked out to you: renewing item.","We get a success message when issue is renewed");
173 $checkout->discard_changes();
174 is( $checkout->renewals, 1, "Renewals has been reduced");
177 subtest renew_all => sub {
180 my $library = $builder->build_object ({ class => 'Koha::Libraries' });
181 my $patron = $builder->build_object(
183 class => 'Koha::Patrons',
185 branchcode => $library->branchcode,
189 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
191 my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
193 # Send empty AD segments (i.e. empty string for patron_pwd)
194 my $transaction = $ils->renew_all( $patron->cardnumber, "", undef );
195 isnt( $transaction->{screen_msg}, 'Invalid patron password.', "Empty password succeeds" );
198 $schema->storage->txn_rollback;