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

(-)a/t/db_dependent/ILSDI_Services.t (-2 / +109 lines)
Lines 6-12 use C4::Members qw/AddMember GetMember GetBorrowercategory/; Link Here
6
use Koha::Libraries;
6
use Koha::Libraries;
7
use CGI qw ( -utf8 );
7
use CGI qw ( -utf8 );
8
8
9
use Test::More tests => 15;
9
use Test::More tests => 16;
10
use t::lib::Mocks;
11
use t::lib::TestBuilder;
10
12
11
BEGIN {
13
BEGIN {
12
    use_ok('C4::ILSDI::Services');
14
    use_ok('C4::ILSDI::Services');
Lines 90-92 my $borrower = GetMember( borrowernumber => $borrowernumber ); Link Here
90
92
91
}
93
}
92
94
93
- 
95
# End transaction
96
$dbh->rollback;
97
$dbh->{AutoCommit} = 1;
98
$dbh->{RaiseError} = 0;
99
100
my $schema = Koha::Database->schema;
101
$schema->storage->txn_begin;
102
103
$schema->resultset( 'Borrower' )->delete_all;
104
$schema->resultset( 'BorrowerAttribute' )->delete_all;
105
$schema->resultset( 'BorrowerAttributeType' )->delete_all;
106
$schema->resultset( 'Category' )->delete_all;
107
$schema->resultset( 'Item' )->delete_all; # 'Branch' deps. on this
108
$schema->resultset( 'Branch' )->delete_all;
109
110
111
{ # GetPatronInfo/GetBorrowerAttributes test for extended patron attributes:
112
113
    # Configure Koha to enable ILS-DI server and extended attributes:
114
    t::lib::Mocks::mock_preference( 'ILS-DI', 1 );
115
    t::lib::Mocks::mock_preference( 'ExtendedPatronAttributes', 1 );
116
117
    my $builder = t::lib::TestBuilder->new;
118
119
    # Set up a library/branch for our user to belong to:
120
    my $lib = $builder->build( {
121
        source => 'Branch',
122
        value => {
123
            branchcode => 'T_ILSDI',
124
        }
125
    } );
126
127
    # Create a new category for user to belong to:
128
    my $cat = $builder->build( {
129
        source => 'Category',
130
        value  => {
131
            category_type                 => 'A',
132
            BlockExpiredPatronOpacActions => -1,
133
        }
134
    } );
135
136
    # Create a new attribute type:
137
    my $attr_type = $builder->build( {
138
        source => 'BorrowerAttributeType',
139
        value  => {
140
            code                      => 'DOORCODE',
141
            opac_display              => 0,
142
            authorised_value_category => '',
143
            class                     => '',
144
        }
145
    } );
146
147
    # Create a new user:
148
    my $brwr = $builder->build( {
149
        source => 'Borrower',
150
        value  => {
151
            categorycode => $cat->{'categorycode'},
152
            branchcode   => $lib,
153
        }
154
    } );
155
156
    # Authorised value:
157
    my $auth = $builder->build( {
158
        source => 'AuthorisedValue',
159
        value  => {
160
            category => $cat->{'categorycode'}
161
        }
162
    } );
163
164
    # Set the new attribute for our user:
165
    my $attr = $builder->build( {
166
        source => 'BorrowerAttribute',
167
        value  => {
168
            borrowernumber => $brwr->{'borrowernumber'},
169
            code           => $attr_type->{'code'},
170
            attribute      => '1337',
171
            password       => undef,
172
        }
173
    } );
174
175
    # Prepare and send web request for IL-SDI server:
176
    my $query = new CGI;
177
    $query->param( 'service', 'GetPatronInfo' );
178
    $query->param( 'patron_id', $brwr->{'borrowernumber'} );
179
    $query->param( 'show_attributes', '1' );
180
181
    my $reply = C4::ILSDI::Services::GetPatronInfo( $query );
182
183
    # Build a structure for comparision:
184
    my $cmp = {
185
        category_code     => $attr_type->{'category_code'},
186
        class             => $attr_type->{'class'},
187
        code              => $attr->{'code'},
188
        description       => $attr_type->{'description'},
189
        display_checkout  => $attr_type->{'display_checkout'},
190
        password          => undef,
191
        value             => $attr->{'attribute'},
192
        value_description => undef,
193
    };
194
195
    # Check results:
196
    is_deeply( $reply->{'attributes'}, [ $cmp ] );
197
}
198
199
# Cleanup
200
$schema->storage->txn_rollback;

Return to bug 14257