diff options
author | Struan Donald <struan@exo.org.uk> | 2018-04-17 10:53:53 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2018-04-17 16:53:16 +0100 |
commit | ee28ece4c42d87dc45f5bda2aafb860c2eb317e7 (patch) | |
tree | 3ba6d05a60634ba821031650ec530539d1cfba14 /t/open311.t | |
parent | 193811edee2c42dcdb8d2d5cb18ed6dfaa92f5e9 (diff) |
[Open311] avoid spurious warning when params are undef
If there was an undefined parameter passed to `_post` then generating
the debug string would generate a warning about an undefined value in a
concatenation. So, check for undefined params and substitute empty
string to avoid.
Diffstat (limited to 't/open311.t')
-rw-r--r-- | t/open311.t | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/t/open311.t b/t/open311.t index ce18a6d0c..4dc1b2959 100644 --- a/t/open311.t +++ b/t/open311.t @@ -133,8 +133,38 @@ for my $test ( } ], params => [ - [ 'attribute[title]', 'A title', 'extra paramater used correctly' ] - ] + [ 'attribute[title]', 'A title', 'extra parameter used correctly' ] + ], + debug_contains => 'attribute\[title\]: A title', + }, + { + desc => 'undef extra values handled', + extra => [ + { + name => 'title', + value => undef, + } + ], + params => [ + [ 'attribute[title]', '', 'undef extra parameter used correctly' ] + ], + # multi line warnings are not handled well so just match the + # first line + warning => qr/POST requests.xml/, + debug_contains => 'attribute\[title\]: $', + }, + { + desc => '0 extra values handled', + extra => [ + { + name => 'title', + value => 0, + } + ], + params => [ + [ 'attribute[title]', '0', '0 extra parameter used correctly' ] + ], + debug_contains => 'attribute\[title\]: 0', }, { desc => 'first and last names in extra used correctly', @@ -178,11 +208,24 @@ for my $test ( my $extra = { url => 'http://example.com/report/1', }; - my $results = make_service_req( $problem, $extra, $problem->category, -'<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' - ); + my $results; + if ( $test->{warning} ) { + warnings_exist { + $results = make_service_req( $problem, $extra, $problem->category, + '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' + ); + } [ $test->{warning} ], 'warning generated by service request call'; + } else { + $results = make_service_req( $problem, $extra, $problem->category, + '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' + ); + } my $c = CGI::Simple->new( $results->{req}->content ); + if ( $test->{debug_contains} ) { + like $results->{o}->debug_details, qr/$test->{debug_contains}/m, 'extra handled correctly in debug'; + } + for my $param ( @{ $test->{params} } ) { is $c->param( $param->[0] ), $param->[1], $param->[2]; } @@ -762,5 +805,5 @@ sub _make_req { my $req = $o->test_req_used; - return { res => $res, req => $req }; + return { res => $res, req => $req, o => $o }; } |