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

(-)a/t/db_dependent/ILSDI_Services.t (-2 / +96 lines)
Lines 5-12 use Modern::Perl; Link Here
5
use C4::Members qw/AddMember GetMember GetBorrowercategory/;
5
use C4::Members qw/AddMember GetMember GetBorrowercategory/;
6
use C4::Branch;
6
use C4::Branch;
7
use CGI qw ( -utf8 );
7
use CGI qw ( -utf8 );
8
use t::lib::TestBuilder;
9
use t::lib::Mocks;
10
use XML::LibXML;
8
11
9
use Test::More tests => 15;
12
use Test::More tests => 18;
10
13
11
BEGIN {
14
BEGIN {
12
    use_ok('C4::ILSDI::Services');
15
    use_ok('C4::ILSDI::Services');
Lines 90-92 my $borrower = GetMember( borrowernumber => $borrowernumber ); Link Here
90
93
91
}
94
}
92
95
93
- 
96
# End transaction
97
$dbh->rollback;
98
$dbh->{AutoCommit} = 1;
99
$dbh->{RaiseError} = 0;
100
101
my $schema = Koha::Database->schema;
102
$schema->storage->txn_begin;
103
104
$schema->resultset( 'Borrower'              )->delete_all;
105
$schema->resultset( 'BorrowerAttribute'     )->delete_all;
106
$schema->resultset( 'BorrowerAttributeType' )->delete_all;
107
$schema->resultset( 'Category'              )->delete_all;
108
$schema->resultset( 'Biblio'                )->delete_all;
109
$schema->resultset( 'Biblioitem'            )->delete_all;
110
$schema->resultset( 'Item'                  )->delete_all; # 'Branch' dep.
111
$schema->resultset( 'Branch'                )->delete_all;
112
113
{ # GetLibrisAvailability: LIBRIS (Swedish national catalogue) status
114
115
    # Configure Koha to enable ILS-DI server and extended attributes:
116
    t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
117
118
    my $builder = t::lib::TestBuilder->new;
119
120
    # LIBRIS stores it's own unique ID in Control Field 001 in their
121
    # catalogue's MARC records. Luckily Koha indexes this field.
122
    # Swedish libraries imports the LIBRIS records, the central
123
    # catalogue then queries item status remotely by this ID.
124
    my $libris_id = '001337';
125
126
    # Set up a library/branch for our user to belong to:
127
    my $lib = $builder->build( {
128
        source => 'Branch',
129
        value => {
130
            branchcode => 'T_ILSDI',
131
        }
132
    } );
133
134
    # Create entries for the book we want to test:
135
    my $bib = $builder->build( {
136
        source => 'Biblio',
137
        values => {
138
        }
139
    });
140
141
    my $bibitem = $builder->build( {
142
        source => 'Biblioitem',
143
        value  => {
144
            bbiblionumber => $bib->{'biblionumber'},
145
        }
146
    });
147
148
    my $item = $builder->build( {
149
        source => 'Item',
150
        value  => {
151
            biblioitemnumber => $bibitem->{'biblioitemnumber'},
152
            homebranch       =>     $lib->{'branchcode'},
153
            holdingbranch    =>     $lib->{'branchcode'},
154
        }
155
    });
156
157
    # Set up test request:
158
    my $query = new CGI; my $reply;
159
    $query->param( 'service', 'GetLibrisAvailability' );
160
161
    my $parser = XML::LibXML->new;
162
163
    # Error handling tests, missing parameters, biblios and/or items.
164
    $query->param( 'id', undef );
165
    $reply = C4::ILSDI::Services::GetLibrisAvailability( $query );
166
    $reply = $parser->parse_string(
167
            C4::ILSDI::Services::GetLibrisAvailability( $query ))
168
            ->findnodes('/Error')->[0]->textContent();
169
    like( $reply, qr/missing parameter/i, 'Test missing id paramter' );
170
171
    $query->param( 'id', 'non-existant-id-string' );
172
    $reply = $parser->parse_string(
173
            C4::ILSDI::Services::GetLibrisAvailability( $query ))
174
            ->findnodes('/Error')->[0]->textContent();
175
    like( $reply, qr/no search result/i, 'Test missing search result' );
176
177
    # Expects to find $libris_id in Zebra but missing the
178
    # item info from the Koha SQL database.
179
    $query->param( 'id', $libris_id );
180
    $reply = $parser->parse_string(
181
            C4::ILSDI::Services::GetLibrisAvailability( $query ))
182
            ->findnodes('/Error')->[0]->textContent();
183
    like( $reply, qr/no item information/i, 'Test missing item info' );
184
}
185
186
# Cleanup
187
$schema->storage->txn_rollback;

Return to bug 15292