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

(-)a/t/db_dependent/Koha/Objects.t (-3 / +67 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 15;
22
use Test::More tests => 16;
23
use Test::Exception;
23
use Test::Warn;
24
use Test::Warn;
24
25
25
use Koha::Authority::Types;
26
use Koha::Authority::Types;
Lines 237-240 subtest '->is_paged and ->pager tests' => sub { Link Here
237
       'Koha::Objects->pager returns a valid DBIx::Class object' );
238
       'Koha::Objects->pager returns a valid DBIx::Class object' );
238
239
239
    $schema->storage->txn_rollback;
240
    $schema->storage->txn_rollback;
240
}
241
};
242
243
subtest '_build_query_params_from_api' => sub {
244
245
    plan tests => 5;
246
247
    my $filtered_params = {
248
        title  => "Ender",
249
        author => "Orson"
250
    };
251
252
    subtest '_match => contains' => sub {
253
        plan tests => 2;
254
        my $reserved_params = { _match => 'contains' };
255
        my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
256
257
        is_deeply( $params->{author}, { like => '%Orson%' } );
258
        is_deeply( $params->{title}, { like => '%Ender%' } );
259
    };
260
261
    subtest '_match => starts_with' => sub {
262
        plan tests => 2;
263
        my $reserved_params = { _match => 'starts_with' };
264
        my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
265
266
        is_deeply( $params->{author}, { like => 'Orson%' } );
267
        is_deeply( $params->{title}, { like => 'Ender%' } );
268
    };
269
270
    subtest '_match => ends_with' => sub {
271
        plan tests => 2;
272
        my $reserved_params = { _match => 'ends_with' };
273
        my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
274
275
        is_deeply( $params->{author}, { like => '%Orson' } );
276
        is_deeply( $params->{title}, { like => '%Ender' } );
277
    };
278
279
    subtest '_match => exact' => sub {
280
        plan tests => 2;
281
        my $reserved_params = { _match => 'exact' };
282
        my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
283
284
        is( $params->{author}, 'Orson' );
285
        is( $params->{title},  'Ender' );
286
    };
287
288
    subtest '_match => blah' => sub {
289
        plan tests => 2;
290
291
        my $reserved_params = { _match => 'blah' };
292
        throws_ok {
293
            Koha::Objects::_build_query_params_from_api( $filtered_params,
294
                $reserved_params );
295
        }
296
        'Koha::Exceptions::WrongParameter',
297
          'Exception thrown on invalid _match parameter';
298
299
        is( $@,
300
            'Invalid value for _match param (blah)',
301
            'Exception carries the right message'
302
        );
303
    };
304
};
305
241
- 

Return to bug 19410