View | Details | Raw Unified | Return to bug 21284
Collapse All | Expand All

(-)a/t/db_dependent/ILSDI_Services.t (-2 / +122 lines)
Lines 19-28 use Modern::Perl; Link Here
19
19
20
use CGI qw ( -utf8 );
20
use CGI qw ( -utf8 );
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
use Test::MockModule;
23
use Test::MockModule;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
use t::lib::TestBuilder;
25
use t::lib::TestBuilder;
26
use C4::Circulation;
27
use C4::Reserves;
26
28
27
use Koha::AuthUtils;
29
use Koha::AuthUtils;
28
30
Lines 34-39 my $schema = Koha::Database->schema; Link Here
34
my $dbh     = C4::Context->dbh;
36
my $dbh     = C4::Context->dbh;
35
my $builder = t::lib::TestBuilder->new;
37
my $builder = t::lib::TestBuilder->new;
36
38
39
# Mock userenv
40
local $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /redefined/ };
41
my $userenv;
42
*C4::Context::userenv = \&Mock_userenv;
43
44
# C4::Context->userenv
45
sub Mock_userenv {
46
    return $userenv;
47
}
48
49
50
37
subtest 'AuthenticatePatron test' => sub {
51
subtest 'AuthenticatePatron test' => sub {
38
52
39
    plan tests => 14;
53
    plan tests => 14;
Lines 92-97 subtest 'AuthenticatePatron test' => sub { Link Here
92
    $schema->storage->txn_rollback;
106
    $schema->storage->txn_rollback;
93
};
107
};
94
108
109
subtest 'GetPatronInfo test for holds' => sub {
110
    plan tests => 8;
111
112
    $schema->storage->txn_begin;
113
    $schema->resultset( 'Issue' )->delete_all;
114
    $schema->resultset( 'Reserve' )->delete_all;
115
    $schema->resultset( 'Borrower' )->delete_all;
116
    $schema->resultset( 'Category' )->delete_all;
117
    $schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
118
    $schema->resultset( 'Branch' )->delete_all;
119
120
    # Configure Koha to enable ILS-DI server
121
    t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
122
123
    # Set up a library/branch for our user to belong to:
124
    my $branchcode = 'T_ILSDI';
125
    my $lib = $builder->build( {
126
        source => 'Branch',
127
        value => {
128
            branchcode => $branchcode,
129
        }
130
    } );
131
132
    # Create a new category for user to belong to:
133
    my $cat = $builder->build( {
134
        source => 'Category',
135
        value  => {
136
            category_type                 => 'A',
137
            BlockExpiredPatronOpacActions => -1,
138
        }
139
    } );
140
141
    # Create new users:
142
    my $brwr = $builder->build( {
143
        source => 'Borrower',
144
        value  => {
145
            categorycode => $cat->{'categorycode'},
146
            branchcode   => $lib->{'branchcode'},
147
        }
148
    } );
149
    my $brwr2 = $builder->build( {
150
        source => 'Borrower',
151
        value  => {
152
            categorycode => $cat->{'categorycode'},
153
            branchcode   => $lib->{'branchcode'},
154
        }
155
    } );
156
    my $brwr3 = $builder->build( {
157
        source => 'Borrower',
158
        value  => {
159
            categorycode => $cat->{'categorycode'},
160
            branchcode   => $lib->{'branchcode'},
161
        }
162
    } );
163
164
165
    # Place a loan
166
    my $biblio = $builder->build( { source => 'Biblio', } );
167
    my $item = $builder->build( { source => 'Item', value => { biblionumber => $biblio->{biblionumber}, barcode => "mybarcode"} } );
168
    my $biblioitem = $builder->build( { source => 'Biblioitem', value => { biblionumber => $biblio->{biblionumber} } } );
169
    $userenv = { flags => 1, id => $brwr->{borrowernumber}, branch => 'T_ILSDI' };
170
    my $issue = AddIssue($brwr, $item->{barcode});
171
172
    # Prepare and send web request for IL-SDI server:
173
    my $query = new CGI;
174
    $query->param( 'service', 'GetPatronInfo' );
175
    $query->param( 'patron_id', $brwr->{'borrowernumber'} );
176
    $query->param( 'show_attributes', '0' );
177
    $query->param( 'show_loans', '1' );
178
    my $reply = C4::ILSDI::Services::GetPatronInfo( $query );
179
180
    # Check that this loan is not on hold
181
    is ( $reply->{loans}->{loan}[0]->{recordonhold}, "0", "Record is not on hold");
182
    is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is not on hold");
183
184
    # Add a hold on the biblio
185
    my $biblioreserve = AddReserve($branchcode, $brwr2->{'borrowernumber'}, $biblio->{biblionumber});
186
187
    # Check that it is on hold on biblio level
188
    $reply = C4::ILSDI::Services::GetPatronInfo( $query );
189
    is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold");
190
    is ( $reply->{loans}->{loan}[0]->{itemonhold}, "0", "Item is on hold");
191
192
    # Delete holds
193
    $schema->resultset( 'Reserve' )->delete_all;
194
195
    # Add a hold on the item
196
    my $itemreserve = AddReserve($branchcode, $brwr2->{'borrowernumber'}, $biblio->{biblionumber},
197
                                 [$biblio->{biblionumber}], undef, undef, undef, undef, undef, $item->{itemnumber});
198
199
    # When a specific item has a reserve, the item is on hold as well as the record
200
    $reply = C4::ILSDI::Services::GetPatronInfo( $query );
201
    is ( $reply->{loans}->{loan}[0]->{recordonhold}, "1", "Record is on hold");
202
    is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold");
203
204
    # Add another hold on the biblio
205
    $biblioreserve = AddReserve($branchcode, $brwr3->{'borrowernumber'}, $biblio->{biblionumber});
206
207
    # Check that there are 2 holds on the biblio and 1 on this specific item
208
    $reply = C4::ILSDI::Services::GetPatronInfo( $query );
209
    is ( $reply->{loans}->{loan}[0]->{recordonhold}, "2", "Record is on hold twice");
210
    is ( $reply->{loans}->{loan}[0]->{itemonhold}, "1", "Item is on hold");
211
212
    # Cleanup
213
    $schema->storage->txn_rollback;
214
215
};
95
216
96
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub {
217
subtest 'GetPatronInfo/GetBorrowerAttributes test for extended patron attributes' => sub {
97
218
98
- 

Return to bug 21284