X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fcontrollers%2Fhelpers%2Fparse_filter.t;h=856ae2e337658ae60931a08aeb7d5fde44e43829;hb=70ba777d43331b446755116b26c04913212d2f1f;hp=84547e05b603655da0fc6ead6a1c5eb042ba3e03;hpb=a5fe0a32e0e9c68db14c0bb7b34cb80b4a79a311;p=kivitendo-erp.git diff --git a/t/controllers/helpers/parse_filter.t b/t/controllers/helpers/parse_filter.t index 84547e05b..856ae2e33 100644 --- a/t/controllers/helpers/parse_filter.t +++ b/t/controllers/helpers/parse_filter.t @@ -1,25 +1,32 @@ use lib 't'; -use Test::More tests => 13; +use Test::More tests => 28; use Test::Deep; use Data::Dumper; use_ok 'Support::TestSetup'; use_ok 'SL::Controller::Helper::ParseFilter'; +use SL::DB::OrderItem; + undef *::any; # Test::Deep exports any (for junctions) and MoreCommon exports any (like in List::Moreutils) Support::TestSetup::login(); my ($filter, $expected); -sub test ($$$) { - my $got = { parse_filter($_[0]) }; +sub test ($$$;%) { + my ($filter, $expect, $msg, %params) = @_; + my $target = delete $params{target}; + my $args = { parse_filter($filter, %params) }; + my $got = $args; $target ||= ''; + $got = $filter if $target =~ /filter/; + $got = $params{launder_to} if $target =~ /launder/; cmp_deeply( $got, - $_[1], - $_[2] + $expect, + $msg, ) or do { - print STDERR "expected => ", Dumper($_[1]), "\ngot: => ", Dumper($got), $/; + print STDERR "expected => ", Dumper($expect), "\ngot: => ", Dumper($got), $/; } } @@ -30,10 +37,10 @@ test { name => 'Test', whut => 'moof', }, { - query => [ %{{ + query => bag( name => 'Test', whut => 'moof' - }} ], + ), }, 'basic test'; test { @@ -53,7 +60,7 @@ test { } }, { query => [ 'customer.chart.accno' => 'test' ], - with_objects => bag( 'customer', 'chart' ), + with_objects => bag( 'customer', 'customer.chart' ), }, 'nested joins'; test { @@ -77,7 +84,7 @@ test { }, { query => [ 'customer.chart.accno' => { like => '%1200' } ], - with_objects => bag('customer', 'chart' ), + with_objects => bag('customer', 'customer.chart' ), }, 'all together'; @@ -91,11 +98,11 @@ test { }, }, }, { - 'query' => [ %{{ + 'query' => bag( 'invoice.customer.name' => 'test', 'customer.name' => 'test', - }} ], - 'with_objects' => bag( 'invoice', 'customer' ) + ), + 'with_objects' => bag( 'invoice.customer', 'customer', 'invoice' ) }, 'object in more than one relationship'; test { @@ -126,3 +133,163 @@ test { ], }, 'arrays with filter'; + +########### laundering + +test { + 'sellprice:number' => [ + '123,4', '2,34', '0,4', + ] +}, { + 'sellprice:number' => [ '123,4', '2,34', '0,4' ], + 'sellprice_number_' => { '123,4' => 1, '2,34' => 1, '0,4' => 1 }, +}, 'laundering with array', target => 'filter'; + +my %args = ( + 'sellprice:number' => [ + '123,4', '2,34', '0,4', + ], +); +test { + %args, +}, { + %args +}, 'laundering into launder does not alter filter', target => 'filter', launder_to => {}; + + +test { + part => { + 'sellprice:number' => '123,4', + } +}, { + part => { + 'sellprice:number' => '123,4', + 'sellprice_number' => '123,4' + } +}, 'deep laundering', target => 'filter'; + + +test { + part => { + 'sellprice:number' => '123,4', + } +}, { + part => { + 'sellprice_number' => '123,4' + } +}, 'deep laundering, check for laundered hash', target => 'launder', launder_to => { }; + +### bug: sub objects + +test { + order => { + customer => { + 'name:substr::ilike' => 'test', + } + } +}, { + query => [ 'order.customer.name' => { ilike => '%test%' } ], + with_objects => bag('order.customer', 'order'), +}, 'sub objects have to retain their prefix'; + +### class filter dispatch +# +test { + name => 'Test', + whut => 'moof', +}, { + query => bag( + name => 'Test', + whut => 'moof' + ), +}, 'object test simple', class => 'SL::DB::Manager::Part'; + +test { + 'type' => 'assembly', +}, { + query => [ + 'assembly' => 1 + ], +}, 'object test without prefix', class => 'SL::DB::Manager::Part'; + +test { + 'part.type' => 'assembly', +}, { + query => [ + 'part.assembly' => 1 + ], +}, 'object test with prefix', class => 'SL::DB::Manager::OrderItem'; + +test { + 'type' => [ 'part', 'assembly' ], +}, { + query => [ + or => [ + and => [ or => [ assembly => 0, assembly => undef ], + "!inventory_accno_id" => 0, + "!inventory_accno_id" => undef, + ], + assembly => 1, + ] + ], +}, 'object test without prefix but complex value', class => 'SL::DB::Manager::Part'; + +test { + 'part.type' => [ 'part', 'assembly' ], +}, { + query => [ + or => [ + and => [ or => [ 'part.assembly' => 0, 'part.assembly' => undef ], + "!part.inventory_accno_id" => 0, + "!part.inventory_accno_id" => undef, + ], + 'part.assembly' => 1, + ] + ], +}, '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%' + } + ] +}, 'Regression check: prefixing of fallback filtering in relation with custom filters', class => 'SL::DB::Manager::OrderItem';