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 => 10;
25 use t::lib::TestBuilder;
29 use Koha::CirculationRules;
33 use_ok('C4::SIP::ILS');
36 my $schema = Koha::Database->new->schema;
37 $schema->storage->txn_begin;
39 my $builder = t::lib::TestBuilder->new();
41 my $class = 'C4::SIP::ILS';
42 my $institution = { id => 'CPL', };
44 my $ils = $class->new( $institution );
46 isa_ok( $ils, $class );
48 # Check all methods required for interface are there
50 find_patron find_item checkout_ok checkin_ok offline_ok status_update_ok
51 offline_ok checkout checkin end_patron_session pay_fee add_hold cancel_hold
52 alter_hold renew renew_all
55 can_ok( $ils, @methods );
57 is( $ils->institution(), 'CPL', 'institution method returns id' );
59 is( $ils->institution_id(), 'CPL', 'institution_id method returns id' );
61 is( $ils->supports('checkout'), 1, 'checkout supported' );
63 is( $ils->supports('security_inhibit'),
64 q{}, 'unsupported feature returns false' );
66 is( $ils->test_cardnumber_compare( 'A1234', 'a1234' ),
67 1, 'borrower bc test is case insensitive' );
69 is( $ils->test_cardnumber_compare( 'A1234', 'b1234' ),
70 q{}, 'borrower bc test identifies difference' );
72 subtest cancel_hold => sub {
75 my $library = $builder->build_object ({ class => 'Koha::Libraries' });
76 my $patron = $builder->build_object(
78 class => 'Koha::Patrons',
80 branchcode => $library->branchcode,
84 t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
86 my $item = $builder->build_sample_item({
87 library => $library->branchcode,
90 Koha::CirculationRules->set_rules(
92 categorycode => $patron->categorycode,
93 branchcode => $library->branchcode,
94 itemtype => $item->effective_itemtype,
98 holds_per_record => 3,
100 lengthunit => 'days',
105 my $reserve1 = AddReserve(
107 branchcode => $library->branchcode,
108 borrowernumber => $patron->borrowernumber,
109 biblionumber => $item->biblio->biblionumber,
110 itemnumber => $item->itemnumber,
113 is( $item->biblio->holds->count(), 1, "Hold was placed on bib");
114 is( $item->holds->count(),1,"Hold was placed on specific item");
116 my $ils = C4::SIP::ILS->new({ id => $library->branchcode });
117 my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber );
118 my $transaction = $ils->cancel_hold($patron->cardnumber,undef,$item->barcode,undef);
120 is( $transaction->{screen_msg},"Hold Cancelled.","We get a success message when hold cancelled");
122 is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining");
123 is( $item->holds->count(), 0, "Item has 0 holds remaining");
125 $schema->storage->txn_rollback;