Bug 19382: Adjust comment in test
[koha.git] / t / db_dependent / SIP / ILS.t
1 #!/usr/bin/perl
2
3 # Tests for C4::SIP::ILS
4 # Please help to extend them!
5
6 # This file is part of Koha.
7 #
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.
12 #
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.
17 #
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>.
20
21 use Modern::Perl;
22
23 use Test::More tests => 10;
24
25 use t::lib::TestBuilder;
26 use t::lib::Mocks;
27
28 use C4::Reserves;
29 use Koha::CirculationRules;
30 use Koha::Database;
31
32 BEGIN {
33     use_ok('C4::SIP::ILS');
34 }
35
36 my $schema = Koha::Database->new->schema;
37 $schema->storage->txn_begin;
38
39 my $builder = t::lib::TestBuilder->new();
40
41 my $class = 'C4::SIP::ILS';
42 my $institution = { id => 'CPL', };
43
44 my $ils = $class->new( $institution );
45
46 isa_ok( $ils, $class );
47
48 # Check all methods required for interface are there
49 my @methods = qw(
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
53 );
54
55 can_ok( $ils, @methods );
56
57 is( $ils->institution(), 'CPL', 'institution method returns id' );
58
59 is( $ils->institution_id(), 'CPL', 'institution_id method returns id' );
60
61 is( $ils->supports('checkout'), 1, 'checkout supported' );
62
63 is( $ils->supports('security_inhibit'),
64     q{}, 'unsupported feature returns false' );
65
66 is( $ils->test_cardnumber_compare( 'A1234', 'a1234' ),
67     1, 'borrower bc test is case insensitive' );
68
69 is( $ils->test_cardnumber_compare( 'A1234', 'b1234' ),
70     q{}, 'borrower bc test identifies difference' );
71
72 subtest cancel_hold => sub {
73     plan tests => 5;
74
75     my $library = $builder->build_object ({ class => 'Koha::Libraries' });
76     my $patron = $builder->build_object(
77         {
78             class => 'Koha::Patrons',
79             value => {
80                 branchcode => $library->branchcode,
81             }
82         }
83     );
84     t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode, flags => 1 });
85
86     my $item = $builder->build_sample_item({
87         library       => $library->branchcode,
88     });
89
90     Koha::CirculationRules->set_rules(
91         {
92             categorycode => $patron->categorycode,
93             branchcode   => $library->branchcode,
94             itemtype     => $item->effective_itemtype,
95             rules        => {
96                 onshelfholds     => 1,
97                 reservesallowed  => 3,
98                 holds_per_record => 3,
99                 issuelength      => 5,
100                 lengthunit       => 'days',
101             }
102         }
103     );
104
105     my $reserve1 = AddReserve(
106         {
107             branchcode     => $library->branchcode,
108             borrowernumber => $patron->borrowernumber,
109             biblionumber   => $item->biblio->biblionumber,
110             itemnumber     => $item->itemnumber,
111         }
112     );
113     is( $item->biblio->holds->count(), 1, "Hold was placed on bib");
114     is( $item->holds->count(),1,"Hold was placed on specific item");
115
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);
119
120     is( $transaction->{screen_msg},"Hold Cancelled.","We get a success message when hold cancelled");
121
122     is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining");
123     is( $item->holds->count(), 0,  "Item has 0 holds remaining");
124 };
125 $schema->storage->txn_rollback;