From 36b7bf7bb11f3875b818387aeda1fad363eb6c96 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 18 Feb 2015 10:50:03 +0100 Subject: [PATCH] ParseFilter: Laundern schon vor dem eigentlichen parsen. Erlaubt es indirekte Filter im Template roundtrip safe zu machen. --- SL/Controller/Helper/ParseFilter.pm | 4 +- t/controllers/helpers/parse_filter.t | 64 +++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/SL/Controller/Helper/ParseFilter.pm b/SL/Controller/Helper/ParseFilter.pm index 759e146c5..c38974e40 100644 --- a/SL/Controller/Helper/ParseFilter.pm +++ b/SL/Controller/Helper/ParseFilter.pm @@ -43,10 +43,10 @@ sub parse_filter { _add_uniq($objects, $_) for @$auto_objects; } - my $query = _parse_filter($flattened, $objects, %params); - _launder_keys($filter, $params{launder_to}) unless $params{no_launder}; + my $query = _parse_filter($flattened, $objects, %params); + return ($query && @$query ? (query => $query) : ()), ($objects && @$objects ? ( with_objects => [ uniq @$objects ]) : ()); diff --git a/t/controllers/helpers/parse_filter.t b/t/controllers/helpers/parse_filter.t index 583b26cd3..a53c8c469 100644 --- a/t/controllers/helpers/parse_filter.t +++ b/t/controllers/helpers/parse_filter.t @@ -1,6 +1,6 @@ use lib 't'; -use Test::More tests => 31; +use Test::More tests => 36; use Test::Deep; use Data::Dumper; @@ -179,6 +179,44 @@ test { } }, 'deep laundering, check for laundered hash', target => 'launder', launder_to => { }; +test { + part => { + 'sellprice:number' => '2', + 'sellprice:number::' => 'le', + } +}, { + part => { + 'sellprice:number' => '2', + 'sellprice:number::' => 'le', + } +}, 'laundering of indirect filters does not alter', target => 'filter', launder_to => { }; + +test { + part => { + 'sellprice:number' => '2', + 'sellprice:number::' => 'le', + } +}, { + part => { + 'sellprice_number' => '2', + 'sellprice_number__' => 'le', + } +}, 'laundering of indirect filters', target => 'launder', launder_to => { }; + +test { + part => { + 'sellprice:number' => '2', + 'sellprice:number::' => 'le', + } +}, { + part => { + 'sellprice:number' => '2', + 'sellprice:number::' => 'le', + 'sellprice_number' => '2', + 'sellprice_number__' => 'le', + } +}, 'laundering of indirect filters - inplace', target => 'filter'; + ### bug: sub objects test { @@ -335,3 +373,27 @@ test { ] ] }, ':multi with complex tokenizing'; + +# test tokenizing for custom filters by monkeypatching a custom filter into Part +SL::DB::Manager::Part->add_filter_specs( + test => sub { + my ($key, $value, $prefix, @additional) = @_; + return "$prefix$key" => { @additional, $value }; + } +); + +test { + 'part.test.what' => 2, +}, { + query => [ + 'part.test' => { 'what', 2 }, + ] +}, 'additional tokens', class => 'SL::DB::Manager::OrderItem'; + +test { + 'part.test.what:substr::ilike' => 2, +}, { + query => [ + 'part.test' => { 'what', { ilike => '%2%' } }, + ] +}, 'additional tokens + filters + methods', class => 'SL::DB::Manager::OrderItem'; -- 2.20.1