From: Graham Knop Date: Fri, 19 Jun 2020 21:13:07 +0000 (+0200) Subject: rewrite tests using Test::WWW::Mechanize::Catalyst to use Catalyst::Test X-Git-Tag: v5.90_127~10^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=77ca88e5173274b7efab6fcc4efa5c47152d0fc0 rewrite tests using Test::WWW::Mechanize::Catalyst to use Catalyst::Test These tests are trivially implementable using the built in Catalyst::Test, rather than relying on an external module that adds a dependency loop. --- diff --git a/Makefile.PL b/Makefile.PL index 8a882eb..c0ef18f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -85,7 +85,6 @@ my %META = ( develop => { requires => { 'CatalystX::LeakChecker' => '0.05', - 'Test::WWW::Mechanize::Catalyst' => '0.51', 'Test::TCP' => '2.00', 'File::Copy::Recursive' => '0.40', 'Starman' => 0, diff --git a/t/unicode_plugin_config.t b/t/unicode_plugin_config.t index 8335b1f..5c4aef7 100644 --- a/t/unicode_plugin_config.t +++ b/t/unicode_plugin_config.t @@ -8,21 +8,11 @@ BEGIN { $ENV{TESTAPP_ENCODING} = 'UTF-8' }; use FindBin qw($Bin); use lib "$Bin/lib"; -BEGIN { -if ( !eval { require Test::WWW::Mechanize::Catalyst; Test::WWW::Mechanize::Catalyst->VERSION('0.51')} ) { - plan skip_all => 'Need Test::WWW::Mechanize::Catalyst for this test'; -} -} - -# make sure testapp works -use_ok('TestAppUnicode'); - -use Test::WWW::Mechanize::Catalyst 'TestAppUnicode'; -my $mech = Test::WWW::Mechanize::Catalyst->new; +use Catalyst::Test 'TestAppUnicode'; { TestAppUnicode->encoding('UTF-8'); - $mech->get_ok('http://localhost/unicode', 'encoding configured ok'); + action_ok('/unicode', 'encoding configured ok'); } done_testing; diff --git a/t/unicode_plugin_live.t b/t/unicode_plugin_live.t index f3b5f90..b8e546b 100644 --- a/t/unicode_plugin_live.t +++ b/t/unicode_plugin_live.t @@ -6,80 +6,79 @@ use Test::More; use FindBin qw($Bin); use lib "$Bin/lib"; -BEGIN { - if ( !eval { require Test::WWW::Mechanize::Catalyst; Test::WWW::Mechanize::Catalyst->VERSION('0.51') } ) { - plan skip_all => 'Need Test::WWW::Mechanize::Catalyst for this test'; - } -} - -# make sure testapp works -use_ok('TestAppUnicode') or BAIL_OUT($@); +use Catalyst::Test qw(TestAppUnicode); -# a live test against TestAppUnicode, the test application -use Test::WWW::Mechanize::Catalyst 'TestAppUnicode'; -my $mech = Test::WWW::Mechanize::Catalyst->new; -$mech->get_ok('http://localhost/', 'get main page'); -$mech->content_like(qr/it works/i, 'see if it has our text'); -is ($mech->response->header('Content-Type'), 'text/html; charset=UTF-8', - 'Content-Type with charset' -); +{ + my $res = request('/'); + ok($res->is_success, 'get main page'); + like($res->decoded_content, qr/it works/i, 'see if it has our text'); + is ($res->header('Content-Type'), 'text/html; charset=UTF-8', + 'Content-Type with charset' + ); +} { - $mech->get_ok('http://localhost/unicode_no_enc', 'get unicode_no_enc'); + my $res = request('/unicode_no_enc'); + ok($res->is_success, 'get unicode_no_enc'); my $exp = "\xE3\x81\xBB\xE3\x81\x92"; - my $got = Encode::encode_utf8($mech->content); + my $got = Encode::encode_utf8($res->decoded_content); - is ($mech->response->header('Content-Type'), 'text/plain', + is ($res->header('Content-Type'), 'text/plain', 'Content-Type with no charset'); is($got, $exp, 'content contains hoge'); } { - $mech->get_ok('http://localhost/unicode', 'get unicode'); + my $res = request('/unicode'); + ok( $res->is_success, 'get unicode'); - is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8', + is ($res->header('Content-Type'), 'text/plain; charset=UTF-8', 'Content-Type with charset'); my $exp = "\xE3\x81\xBB\xE3\x81\x92"; - my $got = Encode::encode_utf8($mech->content); + my $got = Encode::encode_utf8($res->decoded_content); is($got, $exp, 'content contains hoge'); } { - $mech->get_ok('http://localhost/not_unicode', 'get bytes'); + my $res = request('/not_unicode'); + ok($res->is_success, 'get bytes'); my $exp = "\xE1\x88\xB4\xE5\x99\xB8"; - my $got = Encode::encode_utf8($mech->content); + my $got = Encode::encode_utf8($res->decoded_content); is($got, $exp, 'got 1234 5678'); } { - $mech->get_ok('http://localhost/file', 'get file'); - $mech->content_like(qr/this is a test/, 'got filehandle contents'); + my $res = request('/file'); + ok($res->is_success, 'get file'); + like($res->decoded_content, qr/this is a test/, 'got filehandle contents'); } { # The latin 1 case is the one everyone forgets. I want to really make sure # its right, so lets check the damn bytes. - $mech->get_ok('http://localhost/latin1', 'get latin1'); - is ($mech->response->header('Content-Type'), 'text/plain; charset=UTF-8', + my $res = request('/latin1'); + ok($res->is_success, 'get latin1'); + is ($res->header('Content-Type'), 'text/plain; charset=UTF-8', 'Content-Type with charset'); my $exp = "LATIN SMALL LETTER E WITH ACUTE: \xC3\xA9"; - my $got = Encode::encode_utf8($mech->content); + my $got = Encode::encode_utf8($res->decoded_content); is ($got, $exp, 'content octets are UTF-8'); } { - $mech->get_ok('http://localhost/shift_jis', 'get shift_jis'); - is ($mech->response->header('Content-Type'), 'text/plain; charset=Shift_JIS', 'Content-Type with charset'); + my $res = request('/shift_jis'); + ok($res->is_success, 'get shift_jis'); + is ($res->header('Content-Type'), 'text/plain; charset=Shift_JIS', 'Content-Type with charset'); my $exp = "\xE3\x81\xBB\xE3\x81\x92"; - my $got = Encode::encode_utf8($mech->content); + my $got = Encode::encode_utf8($res->decoded_content); is ($got, $exp, 'content octets are Shift_JIS'); }