From bde9fb59f28fb13fe00250b7b540e51ee9d076cc Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 27 Jul 2018 09:59:02 -0300 Subject: [PATCH] Bug 15836: Handle non-existent regexs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit For other types of split rules Sponsored-by: Goethe-Institut Signed-off-by: Christian Stelzenmüller Signed-off-by: Chris Cormack Signed-off-by: Nick Clemens --- Koha/ClassSplitRule.pm | 2 +- t/db_dependent/Koha/ClassSplitRules.t | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Koha/ClassSplitRule.pm b/Koha/ClassSplitRule.pm index 0505120abb..72f467399d 100644 --- a/Koha/ClassSplitRule.pm +++ b/Koha/ClassSplitRule.pm @@ -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 diff --git a/t/db_dependent/Koha/ClassSplitRules.t b/t/db_dependent/Koha/ClassSplitRules.t index 4f79707516..2224dcc17e 100644 --- a/t/db_dependent/Koha/ClassSplitRules.t +++ b/t/db_dependent/Koha/ClassSplitRules.t @@ -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'); -- 2.39.5