X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fjson.t;h=6fb604674efdaa74da81481dccaeea841ebad5a9;hb=ecb598eff7eefd9ad9a113303e2c6f578a12a3b4;hp=e3a13dad2d5e16ba55c94f24f4635d5d186b3ecf;hpb=2f7533ed98d3c3821696968844cbe4ff12159490;p=catagits%2FCatalyst-Action-REST.git diff --git a/t/json.t b/t/json.t index e3a13da..6fb6046 100644 --- a/t/json.t +++ b/t/json.t @@ -5,15 +5,15 @@ use FindBin; use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib"); use Test::Rest; +use utf8; -eval 'require JSON'; -plan skip_all => 'Install JSON to run this test' if ($@); +eval 'use JSON 2.12'; +plan skip_all => 'Install JSON 2.12 or later to run this test' if ($@); -plan tests => 9; use_ok 'Catalyst::Test', 'Test::Serialize'; -my $json = JSON->new; +my $json = JSON->new->utf8; # The text/x-json should throw a warning for ('text/x-json', 'application/json') { my $t = Test::Rest->new('content_type' => $_); @@ -26,10 +26,25 @@ for ('text/x-json', 'application/json') { my $post_data = { 'sushi' => 'is good for monkey', + 'chicken' => ' 佐藤 純', }; my $mres_post = request($t->post(url => '/monkey_put', data => $json->encode($post_data))); ok( $mres_post->is_success, "POST to the monkey succeeded"); - is_deeply($mres_post->content, "is good for monkey", "POST data matches"); + my $exp = "is good for monkey 佐藤 純"; + utf8::encode($exp); + is_deeply($mres_post->content, $exp, "POST data matches"); +} + +{ + my $t = Test::Rest->new('content_type' => 'application/json'); + my $json_data = '{ "sushi":"is good for monkey", }'; + my $mres_post = request($t->post(url => '/monkey_put', data => $json_data)); + ok( ! $mres_post->is_success, "Got expected failed status due to invalid JSON" ); + + my $relaxed_post = request( $t->post(url => "/monkey_json_put", data => $json_data)); + ok( $relaxed_post->is_success, "Got success due to setting relaxed JSON input" ); } 1; + +done_testing;