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

(-)a/t/db_dependent/Koha/ILL/Backend/Standard.t (-4 / +102 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 3;
22
use Test::More tests => 4;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::NoWarnings;
24
use Test::NoWarnings;
25
25
Lines 116-127 subtest 'edititem() tests' => sub { Link Here
116
116
117
subtest 'metadata() tests' => sub {
117
subtest 'metadata() tests' => sub {
118
118
119
    plan tests => 9;
119
    plan tests => 14;
120
120
121
    $schema->storage->txn_begin;
121
    $schema->storage->txn_begin;
122
122
123
    # Create a test ILL request
123
    # Create a test ILL request
124
    my $request = $builder->build_object( { class => 'Koha::ILL::Requests' } );
124
    my $request = $builder->build_sample_ill_request( { backend => 'Standard' } );
125
125
126
    # Add various attributes including some that should be ignored
126
    # Add various attributes including some that should be ignored
127
    $request->add_or_update_attributes(
127
    $request->add_or_update_attributes(
Lines 159-163 subtest 'metadata() tests' => sub { Link Here
159
    ok( !exists $metadata->{Requested_partners},           'requested_partners excluded from metadata' );
159
    ok( !exists $metadata->{Requested_partners},           'requested_partners excluded from metadata' );
160
    ok( !exists $metadata->{Copyrightclearance_confirmed}, 'copyrightclearance_confirmed excluded from metadata' );
160
    ok( !exists $metadata->{Copyrightclearance_confirmed}, 'copyrightclearance_confirmed excluded from metadata' );
161
161
162
    my $new_request = $builder->build_sample_ill_request( { backend => 'Standard' } );
163
164
    is(
165
        scalar %{ $new_request->metadata }, 0,
166
        'metadata() returns empty if no metadata is set'
167
    );
168
169
    $builder->build_object(
170
        {
171
            class => 'Koha::ILL::Request::Attributes',
172
            value => {
173
                illrequest_id => $new_request->illrequest_id,
174
                type          => 'title',
175
                value         => 'The Hobbit',
176
                backend       => 'Standard',
177
            }
178
        }
179
    );
180
181
    is(
182
        scalar %{ $new_request->metadata }, 1,
183
        'metadata() returns non-empty if metadata is set'
184
    );
185
186
    $builder->build_object(
187
        {
188
            class => 'Koha::ILL::Request::Attributes',
189
            value => {
190
                illrequest_id => $new_request->illrequest_id,
191
                type          => 'author',
192
                value         => 'JRR Tolkien',
193
                backend       => 'Other_backend',
194
            }
195
        }
196
    );
197
198
    is(
199
        scalar %{ $new_request->metadata }, 1,
200
        'metadata() only returns attributes from Standard'
201
    );
202
203
    is(
204
        $new_request->metadata->{'Title'}, 'The Hobbit',
205
        'metadata() only returns attributes from Standard'
206
    );
207
208
    is(
209
        $new_request->metadata->{'Author'}, undef,
210
        'metadata() only returns attributes from Standard'
211
    );
212
213
    $schema->storage->txn_rollback;
214
};
215
216
subtest 'migrate() tests' => sub {
217
218
    plan tests => 2;
219
220
    $schema->storage->txn_begin;
221
222
    my $request = $builder->build_sample_ill_request( { backend => 'Other_backend' } );
223
224
    # Add attribute that Standard does not consider metadata
225
    $builder->build_object(
226
        {
227
            class => 'Koha::ILL::Request::Attributes',
228
            value => {
229
                illrequest_id => $request->illrequest_id,
230
                type          => 'Not_Standard_field',
231
                value         => 'test',
232
                backend       => 'Other_backend',
233
            }
234
        }
235
    );
236
237
    # Add attribute that Standard considers metadata
238
    $builder->build_object(
239
        {
240
            class => 'Koha::ILL::Request::Attributes',
241
            value => {
242
                illrequest_id => $request->illrequest_id,
243
                type          => 'DOI',
244
                value         => '123/abc',
245
                backend       => 'Other_backend',
246
            }
247
        }
248
    );
249
250
    my $test = $request->backend_migrate(
251
        {
252
            backend       => 'Standard',
253
            illrequest_id => $request->illrequest_id
254
        }
255
    );
256
257
    is( $request->metadata->{'Not_Standard_field'}, undef, 'Non standard field not migrated' );
258
259
    is( $request->metadata->{'DOI'}, '123/abc', 'Standard field migrated' );
260
162
    $schema->storage->txn_rollback;
261
    $schema->storage->txn_rollback;
163
};
262
};
164
- 

Return to bug 39934