Bug 15836: Handle non-existent regexs

For other types of split rules

Sponsored-by: Goethe-Institut

Signed-off-by: Christian Stelzenmüller <christian.stelzenmueller@bsz-bw.de>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2018-07-27 09:59:02 -03:00 committed by Nick Clemens
parent 328046e59c
commit bde9fb59f2
2 changed files with 7 additions and 3 deletions

View File

@ -64,7 +64,7 @@ sub regexs {
my ( $self, $regexs ) = @_;
return $regexs
? $self->split_regex( to_json($regexs) )
: from_json( $self->split_regex );
: from_json( $self->split_regex || '[]' );
}
=head3 type

View File

@ -28,7 +28,7 @@ use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
subtest 'store + regexs' => sub {
plan tests => 1;
plan tests => 2;
$schema->storage->txn_begin;
my @regexs = ('s/\s/\n/g', 's/(\s?=)/\n=/g', 's/^(J|K)\n/$1 /');
@ -37,10 +37,14 @@ subtest 'store + regexs' => sub {
class_split_rule => 'split_rule',
description => 'a_split_test_1',
split_routine => 'regex',
regexs => \@regexs,
}
)->store;
$rule = Koha::ClassSplitRules->find("split_rule");
is_deeply($rule->regexs, [], '->regexs return an empty array when no regex is defined');
$rule->regexs(\@regexs)->store;
$rule = Koha::ClassSplitRules->find("split_rule");
is_deeply($rule->regexs, \@regexs, '->new and ->regexs correctly serialized/deserialized the regexs');