X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fcontrollers%2Fhelpers%2Fparse_filter.t;h=2c10d036b79f22ca7c6357ca36f491c9d7dfc74f;hb=96f2dabc7d64e28c74358fb5745a6c68b18527f3;hp=c72c33fce83ebb89487f7cbed6cb8f8c2b540359;hpb=061cb2d3a9dda6f2fa93caad2c2ba26c967ff4cb;p=kivitendo-erp.git diff --git a/t/controllers/helpers/parse_filter.t b/t/controllers/helpers/parse_filter.t index c72c33fce..2c10d036b 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 => 23; +use Test::More tests => 38; 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 { @@ -247,3 +285,138 @@ test { ] ], }, 'object test with prefix but complex value', class => 'SL::DB::Manager::OrderItem'; + +test { + description => 'test' +}, { + query => [ description => 'test' ], + with_objects => [ 'order' ] +}, 'with_objects don\'t get clobbered', with_objects => [ 'order' ]; + +test { + customer => { + description => 'test' + } +}, { + query => [ 'customer.description' => 'test' ], + with_objects => [ 'order', 'customer' ] +}, 'with_objects get extended with auto infered objects', with_objects => [ 'order' ]; + +test { + customer => { + description => 'test' + } +}, { + query => [ 'customer.description' => 'test' ], + with_objects => [ 'order', 'customer' ] +}, 'with_objects get extended with auto infered objects with classes', class => 'SL::DB::Manager::Order', with_objects => [ 'order' ]; + +test { + customer => { + description => 'test' + } +}, { + query => [ 'customer.description' => 'test' ], + with_objects => [ 'customer' ] +}, 'with_objects: no duplicates', with_objects => [ 'customer' ]; + +test { + part => { + 'partnumber:substr::ilike' => '1', + }, +}, { + query => [ + 'part.partnumber', { + ilike => '%1%' + } + ], + with_objects => [ 'part' ], +}, 'Regression check: prefixing of fallback filtering in relation with custom filters', class => 'SL::DB::Manager::OrderItem'; +test { + 'description:substr:multi::ilike' => 'term1 term2', +}, { + query => [ + and => [ + description => { ilike => '%term1%' }, + description => { ilike => '%term2%' }, + ] + ] +}, 'simple :multi'; + +test { + part => { + 'all:substr:multi::ilike' => 'term1 term2', + }, +}, { + query => [ + and => [ + or => [ + 'part.partnumber' => { ilike => '%term1%' }, + 'part.description' => { ilike => '%term1%' }, + ], + or => [ + 'part.partnumber' => { ilike => '%term2%' }, + 'part.description' => { ilike => '%term2%' }, + ], + ] + ], +}, 'complex :multi with custom dispatch and prefix', class => 'SL::DB::Manager::OrderItem'; + +test { + 'description:substr:multi::ilike' => q|term1 "term2 and half" 'term3 and stuff'|, +}, { + query => [ + and => [ + description => { ilike => '%term1%' }, + description => { ilike => '%term2 and half%' }, + description => { ilike => '%term3 and stuff%' }, + ] + ] +}, ':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'; + +test { + 'orderitems.part.test.what:substr::ilike' => 2, +}, { + query => [ + 'orderitems.part.test' => { 'what', { ilike => '%2%' } }, + ] +}, 'relationship + additional tokens + filters + methods', class => 'SL::DB::Manager::Order'; + +test { + part => { + 'obsolete::lazy_bool_eq' => '0', + }, +}, { + query => [ + or => [ + 'part.obsolete' => undef, + 'part.obsolete' => 0 + ], + ], + with_objects => [ 'part' ], +}, 'complex methods modifying the key'; +