Bug 19410: Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>

Signed-off-by: Lari Taskula <lari.taskula@jns.fi>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Tomás Cohen Arazi 2017-10-06 12:49:27 -03:00 committed by Jonathan Druart
parent 7805ef2c01
commit dda7b2ce4d

View file

@ -19,7 +19,8 @@
use Modern::Perl;
use Test::More tests => 15;
use Test::More tests => 16;
use Test::Exception;
use Test::Warn;
use Koha::Authority::Types;
@ -237,4 +238,67 @@ subtest '->is_paged and ->pager tests' => sub {
'Koha::Objects->pager returns a valid DBIx::Class object' );
$schema->storage->txn_rollback;
}
};
subtest '_build_query_params_from_api' => sub {
plan tests => 5;
my $filtered_params = {
title => "Ender",
author => "Orson"
};
subtest '_match => contains' => sub {
plan tests => 2;
my $reserved_params = { _match => 'contains' };
my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
is_deeply( $params->{author}, { like => '%Orson%' } );
is_deeply( $params->{title}, { like => '%Ender%' } );
};
subtest '_match => starts_with' => sub {
plan tests => 2;
my $reserved_params = { _match => 'starts_with' };
my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
is_deeply( $params->{author}, { like => 'Orson%' } );
is_deeply( $params->{title}, { like => 'Ender%' } );
};
subtest '_match => ends_with' => sub {
plan tests => 2;
my $reserved_params = { _match => 'ends_with' };
my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
is_deeply( $params->{author}, { like => '%Orson' } );
is_deeply( $params->{title}, { like => '%Ender' } );
};
subtest '_match => exact' => sub {
plan tests => 2;
my $reserved_params = { _match => 'exact' };
my $params = Koha::Objects::_build_query_params_from_api( $filtered_params, $reserved_params );
is( $params->{author}, 'Orson' );
is( $params->{title}, 'Ender' );
};
subtest '_match => blah' => sub {
plan tests => 2;
my $reserved_params = { _match => 'blah' };
throws_ok {
Koha::Objects::_build_query_params_from_api( $filtered_params,
$reserved_params );
}
'Koha::Exceptions::WrongParameter',
'Exception thrown on invalid _match parameter';
is( $@,
'Invalid value for _match param (blah)',
'Exception carries the right message'
);
};
};