diff --git a/examples/login/t/login.t b/examples/login/t/login.t index 52134adc30..68aa33dcff 100644 --- a/examples/login/t/login.t +++ b/examples/login/t/login.t @@ -7,16 +7,23 @@ my $t = Test::Mojo->new('LoginApp'); $t->ua->max_redirects(1); subtest 'Test login workflow' => sub { - $t->get_ok('/')->status_is(200)->element_exists('form input[name="user"]')->element_exists('form input[name="pass"]') + $t->get_ok('/') + ->status_is(200) + ->element_exists('form input[name="user"]') + ->element_exists('form input[name="pass"]') ->element_exists('form input[type="submit"]'); - $t->post_ok('/' => form => {user => 'sebastian', pass => 'secr3t'})->status_is(200) + $t->post_ok('/' => form => {user => 'sebastian', pass => 'secr3t'}) + ->status_is(200) ->text_like('html body' => qr/Welcome sebastian/); $t->get_ok('/protected')->status_is(200)->text_like('a' => qr/Logout/); - $t->get_ok('/logout')->status_is(200)->element_exists('form input[name="user"]') - ->element_exists('form input[name="pass"]')->element_exists('form input[type="submit"]'); + $t->get_ok('/logout') + ->status_is(200) + ->element_exists('form input[name="user"]') + ->element_exists('form input[name="pass"]') + ->element_exists('form input[type="submit"]'); }; done_testing(); diff --git a/lib/Mojolicious/Command/version.pm b/lib/Mojolicious/Command/version.pm index 2ce70456b9..286ca87ab6 100644 --- a/lib/Mojolicious/Command/version.pm +++ b/lib/Mojolicious/Command/version.pm @@ -41,8 +41,10 @@ EOF # Check latest version on CPAN my $latest = eval { - $self->app->ua->max_redirects(10)->tap(sub { $_->proxy->detect }) - ->get('fastapi.metacpan.org/v1/release/Mojolicious')->result->json->{version}; + $self->app->ua->max_redirects(10) + ->tap(sub { $_->proxy->detect }) + ->get('fastapi.metacpan.org/v1/release/Mojolicious') + ->result->json->{version}; } or return; my $msg = 'This version is up to date, have fun!'; diff --git a/t/mojo/promise.t b/t/mojo/promise.t index bbc44c0ee6..345c7ccdce 100644 --- a/t/mojo/promise.t +++ b/t/mojo/promise.t @@ -116,7 +116,9 @@ subtest 'Resolved chained' => sub { subtest 'Rejected chained' => sub { my $promise = Mojo::Promise->new; my @errors; - $promise->then(undef, sub {"$_[0]:1"})->then(sub {"$_[0]:2"}, sub {"$_[0]:fail"})->then(sub {"$_[0]:3"}) + $promise->then(undef, sub {"$_[0]:1"}) + ->then(sub {"$_[0]:2"}, sub {"$_[0]:fail"}) + ->then(sub {"$_[0]:3"}) ->then(sub { push @errors, "$_[0]:4" }); $promise->reject('tset'); Mojo::IOLoop->one_tick; @@ -226,7 +228,10 @@ subtest 'Clone' => sub { subtest 'Exception in chain' => sub { my $promise = Mojo::Promise->new; my (@results, @errors); - $promise->then(sub {@_})->then(sub {@_})->then(sub { die "test: $_[0]\n" })->then(sub { push @results, 'fail' }) + $promise->then(sub {@_}) + ->then(sub {@_}) + ->then(sub { die "test: $_[0]\n" }) + ->then(sub { push @results, 'fail' }) ->catch(sub { @errors = @_ }); $promise->resolve('works'); Mojo::IOLoop->one_tick; diff --git a/t/mojo/websocket.t b/t/mojo/websocket.t index 0dc02085e6..4806be6407 100644 --- a/t/mojo/websocket.t +++ b/t/mojo/websocket.t @@ -356,8 +356,10 @@ subtest 'Promises' => sub { $ua->websocket_p('/foo')->then(sub { $result = 'test failed' })->catch(sub { $result = shift })->wait; is $result, 'WebSocket handshake failed', 'right result'; $result = undef; - $ua->websocket_p($ua->server->url->to_abs->scheme('wsss'))->then(sub { $result = 'test failed' }) - ->catch(sub { $result = shift })->wait; + $ua->websocket_p($ua->server->url->to_abs->scheme('wsss')) + ->then(sub { $result = 'test failed' }) + ->catch(sub { $result = shift }) + ->wait; is $result, 'Unsupported protocol: wsss', 'right result'; }; diff --git a/t/mojolicious/app.t b/t/mojolicious/app.t index 506981c4a9..eeabc1f31c 100644 --- a/t/mojolicious/app.t +++ b/t/mojolicious/app.t @@ -165,14 +165,20 @@ is $t->app->plugins->emit_chain(custom_chain => 4), 8, 'hook has been emitted'; is $t->app->start(qw(test_command --to)), 'works too!', 'right result'; # Plugin::Test::SomePlugin2::register (security violation) -$t->get_ok('/plugin-test-some_plugin2/register')->status_isnt(404)->status_is(500) - ->header_is(Server => 'Mojolicious (Perl)')->content_unlike(qr/Something/) +$t->get_ok('/plugin-test-some_plugin2/register') + ->status_isnt(404) + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_unlike(qr/Something/) ->content_like(qr/Class "MojoliciousTest::Plugin::Test::SomePlugin2" is not a controller/); # Plugin::Test::SomePlugin2::register (security violation again) my $logs = $t->app->log->capture('trace'); -$t->get_ok('/plugin-test-some_plugin2/register')->status_isnt(404)->status_is(500) - ->header_is(Server => 'Mojolicious (Perl)')->content_unlike(qr/Something/) +$t->get_ok('/plugin-test-some_plugin2/register') + ->status_isnt(404) + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_unlike(qr/Something/) ->content_like(qr/Class "MojoliciousTest::Plugin::Test::SomePlugin2" is not a controller/); like $logs, qr/Class "MojoliciousTest::Plugin::Test::SomePlugin2" is not a controller/, 'right message'; undef $logs; @@ -180,50 +186,93 @@ undef $logs; # Foo::fun (with a lot of different tests) my $url = $t->ua->server->url; $url->path('/fun/time'); -$t->get_ok($url => {'X-Test' => 'Hi there!'})->status_isnt(404)->status_is(200)->status_is(200, 'with description') - ->status_isnt(500)->status_isnt(500, 'with description')->header_is('X-Bender' => undef) - ->header_is(Server => 'Mojolicious (Perl)')->header_is(Server => 'Mojolicious (Perl)', 'with description') - ->header_isnt(Server => 'Whatever')->header_isnt(Server => 'Whatever', 'with description') - ->header_like(Server => qr/Mojolicious/)->header_like(Server => qr/Mojolicious/, 'with description') - ->header_unlike(Server => qr/Bender/)->header_unlike(Server => qr/Bender/, 'with description') - ->content_type_is('text/html;charset=UTF-8')->content_type_is('text/html;charset=UTF-8', 'with description') - ->content_type_isnt('text/plain')->content_type_isnt('text/plain', 'with description')->content_type_like(qr/html/) - ->content_type_like(qr/html/, 'with description')->content_type_unlike(qr/plain/) - ->content_type_unlike(qr/plain/, 'with description')->content_isnt('Have')->content_isnt('Have', 'with description') - ->content_is('

Have fun!

')->content_is('

Have fun!

', 'with description')->content_like(qr/fun/) - ->content_like(qr/fun/, 'with description')->content_unlike(qr/boring/) - ->content_unlike(qr/boring/, 'with description')->element_exists('p')->element_exists('p', 'with description') - ->element_exists_not('b')->element_exists_not('b', 'with description')->text_is('p', 'Have fun!') - ->text_is('p', 'Have fun!', 'with description')->text_is('notfound', undef)->text_isnt('p', 'Have') - ->text_isnt('p', 'Have', 'with description')->text_like('p', qr/fun/)->text_like('p', qr/fun/, 'with description') - ->text_unlike('p', qr/boring/)->text_unlike('p', qr/boring/, 'with description'); +$t->get_ok($url => {'X-Test' => 'Hi there!'}) + ->status_isnt(404) + ->status_is(200) + ->status_is(200, 'with description') + ->status_isnt(500) + ->status_isnt(500, 'with description') + ->header_is('X-Bender' => undef) + ->header_is(Server => 'Mojolicious (Perl)') + ->header_is(Server => 'Mojolicious (Perl)', 'with description') + ->header_isnt(Server => 'Whatever') + ->header_isnt(Server => 'Whatever', 'with description') + ->header_like(Server => qr/Mojolicious/) + ->header_like(Server => qr/Mojolicious/, 'with description') + ->header_unlike(Server => qr/Bender/) + ->header_unlike(Server => qr/Bender/, 'with description') + ->content_type_is('text/html;charset=UTF-8') + ->content_type_is('text/html;charset=UTF-8', 'with description') + ->content_type_isnt('text/plain') + ->content_type_isnt('text/plain', 'with description') + ->content_type_like(qr/html/) + ->content_type_like(qr/html/, 'with description') + ->content_type_unlike(qr/plain/) + ->content_type_unlike(qr/plain/, 'with description') + ->content_isnt('Have') + ->content_isnt('Have', 'with description') + ->content_is('

Have fun!

') + ->content_is('

Have fun!

', 'with description') + ->content_like(qr/fun/) + ->content_like(qr/fun/, 'with description') + ->content_unlike(qr/boring/) + ->content_unlike(qr/boring/, 'with description') + ->element_exists('p') + ->element_exists('p', 'with description') + ->element_exists_not('b') + ->element_exists_not('b', 'with description') + ->text_is('p', 'Have fun!') + ->text_is('p', 'Have fun!', 'with description') + ->text_is('notfound', undef) + ->text_isnt('p', 'Have') + ->text_isnt('p', 'Have', 'with description') + ->text_like('p', qr/fun/) + ->text_like('p', qr/fun/, 'with description') + ->text_unlike('p', qr/boring/) + ->text_unlike('p', qr/boring/, 'with description'); # Foo::joy (testing HTML attributes in template) -$t->get_ok('/fun/joy')->status_is(200)->attr_is('p.joy', 'style', 'background-color: darkred;') - ->attr_is('p.joy', 'style', 'background-color: darkred;', 'with description')->attr_is('p.joy', 'data-foo', '0') - ->attr_is('p.joy', 'data-empty', '')->attr_is('notfound', 'style', undef) - ->attr_isnt('p.joy', 'style', 'float: left;')->attr_isnt('p.joy', 'style', 'float: left;', 'with description') - ->attr_like('p.joy', 'style', qr/color/)->attr_like('p.joy', 'style', qr/color/, 'with description') - ->attr_unlike('p.joy', 'style', qr/^float/)->attr_unlike('p.joy', 'style', qr/^float/, 'with description'); +$t->get_ok('/fun/joy') + ->status_is(200) + ->attr_is('p.joy', 'style', 'background-color: darkred;') + ->attr_is('p.joy', 'style', 'background-color: darkred;', 'with description') + ->attr_is('p.joy', 'data-foo', '0') + ->attr_is('p.joy', 'data-empty', '') + ->attr_is('notfound', 'style', undef) + ->attr_isnt('p.joy', 'style', 'float: left;') + ->attr_isnt('p.joy', 'style', 'float: left;', 'with description') + ->attr_like('p.joy', 'style', qr/color/) + ->attr_like('p.joy', 'style', qr/color/, 'with description') + ->attr_unlike('p.joy', 'style', qr/^float/) + ->attr_unlike('p.joy', 'style', qr/^float/, 'with description'); # Foo::baz (missing action without template) $logs = $t->app->log->capture('trace'); -$t->get_ok('/foo/baz')->status_is(500)->header_is(Server => 'Mojolicious (Perl)')->content_unlike(qr/Something/) +$t->get_ok('/foo/baz') + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_unlike(qr/Something/) ->content_like(qr/Route without action and nothing to render/); like $logs, qr/Action not found in controller/, 'right message'; undef $logs; # Foo::yada (action-less template) -$t->get_ok('/foo/yada')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/yada') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/look ma! no action!/); # SyntaxError::foo (syntax error in controller) -$t->get_ok('/syntax_error/foo')->status_is(500)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/syntax_error/foo') + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Missing right curly/); # Foo::syntaxerror (syntax error in template) $logs = $t->app->log->capture('trace'); -$t->get_ok('/foo/syntaxerror')->status_is(500)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/syntaxerror') + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Missing right curly/); like $logs, qr/Rendering template "syntaxerror.html.epl"/, 'right message'; like $logs, qr/Missing right curly/, 'right message'; @@ -233,119 +282,181 @@ like $logs, qr/500 Internal Server Error/, 'right messa undef $logs; # Exceptional::this_one_dies (action dies) -$t->get_ok('/exceptional/this_one_dies')->status_is(500)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/exceptional/this_one_dies') + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("doh!\n\n"); # Exceptional::this_one_might_die (bridge dies) -$t->get_ok('/exceptional_too/this_one_dies')->status_is(500)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/exceptional_too/this_one_dies') + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("double doh!\n\n"); # Exceptional::this_one_dies (action behind bridge dies) -$t->get_ok('/exceptional_too/this_one_dies' => {'X-DoNotDie' => 1})->status_is(500) - ->header_is(Server => 'Mojolicious (Perl)')->content_is("doh!\n\n"); +$t->get_ok('/exceptional_too/this_one_dies' => {'X-DoNotDie' => 1}) + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is("doh!\n\n"); # Exceptional::this_one_does_not_exist (action does not exist) -$t->get_ok('/exceptional/this_one_does_not_exist')->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/exceptional/this_one_does_not_exist') + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Exceptional::this_one_does_not_exist (action behind bridge does not exist) -$t->get_ok('/exceptional_too/this_one_does_not_exist' => {'X-DoNotDie' => 1})->status_is(404) - ->header_is(Server => 'Mojolicious (Perl)')->content_like(qr/Page Not Found/); +$t->get_ok('/exceptional_too/this_one_does_not_exist' => {'X-DoNotDie' => 1}) + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_like(qr/Page Not Found/); # Foo::fun -$t->get_ok('/fun/time' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is('X-Bender' => undef) - ->header_is(Server => 'Mojolicious (Perl)')->content_is('

Have fun!

'); +$t->get_ok('/fun/time' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is('X-Bender' => undef) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('

Have fun!

'); # Foo::fun $url = $t->ua->server->url; $logs = $t->app->log->capture('trace'); $url->path('/fun/time'); -$t->get_ok($url => {'X-Test' => 'Hi there!'})->status_is(200)->header_is('X-Bender' => undef) - ->header_is(Server => 'Mojolicious (Perl)')->content_is('

Have fun!

'); +$t->get_ok($url => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is('X-Bender' => undef) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('

Have fun!

'); like $logs, qr!Rendering cached template "foo/fun\.html\.ep" from DATA section!, 'right message'; undef $logs; # Foo::fun -$t->get_ok('/happy/fun/time' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is('X-Bender' => undef) - ->header_is(Server => 'Mojolicious (Perl)')->content_is('

Have fun!

'); +$t->get_ok('/happy/fun/time' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is('X-Bender' => undef) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('

Have fun!

'); # Foo::test -$t->get_ok('/foo/test' => {'X-Test' => 'Hi there!'})->status_is(200) - ->header_is('X-Bender' => 'Bite my shiny metal ass!')->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/test' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is('X-Bender' => 'Bite my shiny metal ass!') + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr!/bar/test!); # Foo::index -$t->get_ok('/foo' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr|\s+23\nHello Mojo from the template /foo! He|); # Foo::Bar::index -$t->get_ok('/foo-bar' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo-bar' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr|Hello Mojo from the other template /foo-bar!|); # Foo::something -$t->put_ok('/somethingtest' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->put_ok('/somethingtest' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('/test4/42'); -$t->post_ok('/somethingtest?_method=PUT' => {'X-Test' => 'Hi there!'})->status_is(200) - ->header_is(Server => 'Mojolicious (Perl)')->content_is('/test4/42'); -$t->get_ok('/somethingtest?_method=PUT' => {'X-Test' => 'Hi there!'})->status_is(500) +$t->post_ok('/somethingtest?_method=PUT' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('/test4/42'); +$t->get_ok('/somethingtest?_method=PUT' => {'X-Test' => 'Hi there!'}) + ->status_is(500) ->content_like(qr/Controller "MojoliciousTest::Somethingtest" does not exist/); # Foo::url_for_missing -$t->get_ok('/something_missing' => {'X-Test' => 'Hi there!'})->status_is(200) - ->header_is(Server => 'Mojolicious (Perl)')->content_is('does_not_exist'); +$t->get_ok('/something_missing' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('does_not_exist'); # Foo::templateless -$t->get_ok('/foo/templateless' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/templateless' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Hello Mojo from a templateless renderer!/); # Foo::withlayout -$t->get_ok('/foo/withlayout' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/withlayout' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Same old in green Seems to work!/); # Foo::withBlock -$t->get_ok('/withblock.txt' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') - ->content_type_isnt('text/html')->content_type_is('text/plain;charset=UTF-8') +$t->get_ok('/withblock.txt' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_type_isnt('text/html') + ->content_type_is('text/plain;charset=UTF-8') ->content_like(qr/Hello Baerbel\.\s+Hello Wolfgang\./); # MojoliciousTest2::Foo::test -$t->get_ok('/test2' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is('X-Bender' => 'Bite my shiny metal ass!') - ->header_is(Server => 'Mojolicious (Perl)')->content_like(qr!/test2!); +$t->get_ok('/test2' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is('X-Bender' => 'Bite my shiny metal ass!') + ->header_is(Server => 'Mojolicious (Perl)') + ->content_like(qr!/test2!); # MojoliciousTestController::index -$t->get_ok('/test3' => {'X-Test' => 'Hi there!'})->status_is(500)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/test3' => {'X-Test' => 'Hi there!'}) + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Namespace "MojoliciousTest2::Foo" requires a controller/); # MojoliciousTest::Foo::Bar (no action) -$t->get_ok('/test1' => {'X-Test' => 'Hi there!'})->status_is(500)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/test1' => {'X-Test' => 'Hi there!'}) + ->status_is(500) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Controller "MojoliciousTest::Controller::Foo::Bar" requires an action/); # MojoliciousTestController::index (no namespace) -$t->get_ok('/test6' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is('X-Bender' => 'Bite my shiny metal ass!') - ->header_is(Server => 'Mojolicious (Perl)')->content_is('/test6'); +$t->get_ok('/test6' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is('X-Bender' => 'Bite my shiny metal ass!') + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('/test6'); # MojoliciousTest::Foo::Bar::test (controller class shortcut) -$t->get_ok('/test7' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/test7' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("Class works!\n"); # MojoliciousTest::Foo::Bar::test (controller class) -$t->get_ok('/test8' => {'X-Test' => 'Hi there!'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/test8' => {'X-Test' => 'Hi there!'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("Class works!\n"); # MojoliciousTest3::Bar::index (controller class in development namespace) -$t->get_ok('/test9')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/test9') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('Development namespace works!'); # MojoliciousTest3::Baz::index (controller class precedence) -$t->get_ok('/test10')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/test10') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('Development namespace has high precedence!'); # 404 -$t->get_ok('/' => {'X-Test' => 'Hi there!'})->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/' => {'X-Test' => 'Hi there!'}) + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Static file /another/file (no extension) -$t->get_ok('/another/file')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') - ->content_type_is('application/octet-stream')->content_like(qr/Hello Mojolicious!/); +$t->get_ok('/another/file') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_type_is('application/octet-stream') + ->content_like(qr/Hello Mojolicious!/); # Static directory /another $logs = $t->app->log->capture('trace'); @@ -359,68 +470,99 @@ my $size = Mojo::Asset::File->new(path => $path)->size; my $mtime = Mojo::Date->new(Mojo::Asset::File->new(path => $path)->mtime)->to_string; # Static file /hello.txt -$t->get_ok('/hello.txt')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') - ->header_is('Last-Modified' => $mtime)->header_like('ETag' => qr/^"\w+"$/)->header_is('Content-Length' => $size) - ->content_type_is('text/plain;charset=UTF-8')->content_like(qr/Hello Mojo from a development static file!/); +$t->get_ok('/hello.txt') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->header_is('Last-Modified' => $mtime) + ->header_like('ETag' => qr/^"\w+"$/) + ->header_is('Content-Length' => $size) + ->content_type_is('text/plain;charset=UTF-8') + ->content_like(qr/Hello Mojo from a development static file!/); # Try to access a file which is not under the web root via path traversal -$t->get_ok('/../../mojolicious/secret.txt')->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/../../mojolicious/secret.txt') + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Try to access a file which is not under the web root via path traversal (goes # back and forth one directory) -$t->get_ok('/another/../../../mojolicious/secret.txt')->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/another/../../../mojolicious/secret.txt') + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Try to access a file which is not under the web root via path traversal # (triple dot) -$t->get_ok('/.../mojolicious/secret.txt')->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/.../mojolicious/secret.txt') + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Try to access a file which is not under the web root via path traversal # (backslashes) -$t->get_ok('/..\\..\\mojolicious\\secret.txt')->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/..\\..\\mojolicious\\secret.txt') + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Try to access a file which is not under the web root via path traversal # (escaped backslashes) -$t->get_ok('/..%5C..%5Cmojolicious%5Csecret.txt')->status_is(404)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/..%5C..%5Cmojolicious%5Csecret.txt') + ->status_is(404) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Page Not Found/); # Check that backslashes in query or fragment parts don't block access $t->get_ok('/another/file?one=\\1#two=\\2')->status_is(200)->content_like(qr/Hello Mojolicious!/); # Check If-Modified-Since -$t->get_ok('/hello.txt' => {'If-Modified-Since' => $mtime})->status_is(304)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/hello.txt' => {'If-Modified-Since' => $mtime}) + ->status_is(304) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is(''); # Check If-None-Match my $etag = $t->tx->res->headers->etag; -$t->get_ok('/hello.txt' => {'If-None-Match' => $etag})->status_is(304)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/hello.txt' => {'If-None-Match' => $etag}) + ->status_is(304) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is(''); # Check weak If-None-Match against strong ETag -$t->get_ok('/hello.txt' => {'If-None-Match' => qq{W/"$etag"}})->status_is(200) - ->header_is(Server => 'Mojolicious (Perl)')->content_like(qr/Hello Mojo from a development static file!/); +$t->get_ok('/hello.txt' => {'If-None-Match' => qq{W/"$etag"}}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_like(qr/Hello Mojo from a development static file!/); # Check If-None-Match and If-Last-Modified -$t->get_ok('/hello.txt' => {'If-None-Match' => $etag, 'If-Last-Modified' => $mtime})->status_is(304) - ->header_is(Server => 'Mojolicious (Perl)')->content_is(''); +$t->get_ok('/hello.txt' => {'If-None-Match' => $etag, 'If-Last-Modified' => $mtime}) + ->status_is(304) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is(''); # Bad If-None-Match with correct If-Modified-Since -$t->get_ok('/hello.txt' => {'If-None-Match' => '"123"', 'If-Modified-Since' => $mtime})->status_is(200) - ->header_is(Server => 'Mojolicious (Perl)')->content_like(qr/Hello Mojo from a development static file!/); +$t->get_ok('/hello.txt' => {'If-None-Match' => '"123"', 'If-Modified-Since' => $mtime}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_like(qr/Hello Mojo from a development static file!/); # Bad If-Modified-Since with correct If-None-Match -$t->get_ok('/hello.txt' => {'If-Modified-Since' => Mojo::Date->new(23), 'If-None-Match' => $etag})->status_is(200) - ->header_is(Server => 'Mojolicious (Perl)')->content_like(qr/Hello Mojo from a development static file!/); +$t->get_ok('/hello.txt' => {'If-Modified-Since' => Mojo::Date->new(23), 'If-None-Match' => $etag}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->content_like(qr/Hello Mojo from a development static file!/); # Embedded development static file -$t->get_ok('/some/static/file.txt')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/some/static/file.txt') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("Development static file with high precedence.\n"); # Embedded development template -$t->get_ok('/just/some/template')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/just/some/template') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("Development template with high precedence.\n"); { @@ -454,7 +596,9 @@ like $tx->res->body, qr|Hello Mojo from the template /foo! Hello World!|, 'right $t = Test::Mojo->new('SingleFileTestApp'); # SingleFileTestApp::Foo::index -$t->get_ok('/foo')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Same old in green Seems to work!/); # SingleFileTestApp (helper) @@ -470,16 +614,23 @@ $t->get_ok('/foo/conf')->status_is(200)->header_is(Server => 'Mojolicious (Perl) $t->get_ok('/foo/data_template')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is("23 works!\n"); # SingleFileTestApp::Foo::data_template -$t->get_ok('/foo/data_template2')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/data_template2') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("This one works too!\n"); # SingleFileTestApp::Foo::data_static -$t->get_ok('/foo/data_static')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/foo/data_static') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("And this one... ALL GLORY TO THE HYPNOTOAD!\n"); # SingleFileTestApp::Foo::routes -$t->get_ok('/foo/routes')->status_is(200)->header_is('X-Bender' => 'Bite my shiny metal ass!') - ->header_is(Server => 'Mojolicious (Perl)')->content_is('/foo/routes'); +$t->get_ok('/foo/routes') + ->status_is(200) + ->header_is('X-Bender' => 'Bite my shiny metal ass!') + ->header_is(Server => 'Mojolicious (Perl)') + ->content_is('/foo/routes'); # SingleFileTestApp::Redispatch::handler $t->app->log->level('trace')->unsubscribe('message'); @@ -495,7 +646,9 @@ $t->get_ok('/redispatch/render')->status_is(200)->header_is(Server => 'Mojolicio $t->get_ok('/redispatch/secret')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('Redispatch!'); # SingleFileTestApp::Redispatch::secret -$t->get_ok('/redispatch/secret?rly=1')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/redispatch/secret?rly=1') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('Secret!'); subtest 'Override deployment plugins' => sub { @@ -507,15 +660,21 @@ subtest 'Override deployment plugins' => sub { $t = Test::Mojo->new('MojoliciousTest'); # MojoliciousTestController::Foo::plugin_upper_case -$t->get_ok('/plugin/upper_case')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/plugin/upper_case') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('WELCOME aboard!'); # MojoliciousTestController::Foo::plugin_camel_case -$t->get_ok('/plugin/camel_case')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/plugin/camel_case') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('Welcome aboard!'); # MojoliciousTestController::Foo::stage2 -$t->get_ok('/staged' => {'X-Pass' => 1})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/staged' => {'X-Pass' => 1}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('Welcome aboard!'); # MojoliciousTestController::Foo::stage1 @@ -523,8 +682,11 @@ $t->get_ok('/staged')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') # MojoliciousTestController::Foo::suspended $logs = $t->app->log->capture('trace'); -$t->get_ok('/suspended')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') - ->header_is('X-Suspended' => '0, 1, 1, 2')->content_is('

Have fun!

'); +$t->get_ok('/suspended') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->header_is('X-Suspended' => '0, 1, 1, 2') + ->content_is('

Have fun!

'); like $logs, qr!GET "/suspended"!, 'right message'; like $logs, qr/Routing to controller "MojoliciousTest::Foo" and action "suspended"/, 'right message'; like $logs, qr/Routing to controller "MojoliciousTest::Foo" and action "fun"/, 'right message'; @@ -549,11 +711,16 @@ $t->get_ok('/shortcut/ctrl')->status_is(200)->header_is(Server => 'Mojolicious ( $t->get_ok('/shortcut/act')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('act'); # Session with domain -$t->get_ok('/foo/session')->status_is(200)->header_like('Set-Cookie' => qr/; domain=\.example\.com/) - ->header_like('Set-Cookie' => qr!; path=/bar!)->content_is('Bender rockzzz!'); +$t->get_ok('/foo/session') + ->status_is(200) + ->header_like('Set-Cookie' => qr/; domain=\.example\.com/) + ->header_like('Set-Cookie' => qr!; path=/bar!) + ->content_is('Bender rockzzz!'); # Mixed formats -$t->get_ok('/rss.xml')->status_is(200)->content_type_is('application/rss+xml') +$t->get_ok('/rss.xml') + ->status_is(200) + ->content_type_is('application/rss+xml') ->content_like(qr!<\?xml version="1.0" encoding="UTF-8"\?>!); # Missing controller has no side effects diff --git a/t/mojolicious/charset_lite_app.t b/t/mojolicious/charset_lite_app.t index 4197add697..4e7ac3e8aa 100644 --- a/t/mojolicious/charset_lite_app.t +++ b/t/mojolicious/charset_lite_app.t @@ -59,20 +59,29 @@ my $t = Test::Mojo->new; $t->post_ok('/' => form => {foo => 'yatta'})->status_is(200)->content_is('foo: yatta'); # Send raw Shift_JIS octets (like browsers do) -$t->post_ok('/' => form => {foo => $yatta_sjis} => charset => undef)->status_is(200) - ->content_type_unlike(qr/application/)->content_type_like(qr/Shift_JIS/)->content_like(qr/$yatta/); +$t->post_ok('/' => form => {foo => $yatta_sjis} => charset => undef) + ->status_is(200) + ->content_type_unlike(qr/application/) + ->content_type_like(qr/Shift_JIS/) + ->content_like(qr/$yatta/); # Send raw Shift_JIS octets (like browsers do, multipart message) $t->post_ok('/' => {'Content-Type' => 'multipart/form-data'} => form => {foo => $yatta_sjis} => charset => undef) - ->status_is(200)->content_type_like(qr/Shift_JIS/)->content_like(qr/$yatta/); + ->status_is(200) + ->content_type_like(qr/Shift_JIS/) + ->content_like(qr/$yatta/); # Send as string -$t->post_ok('/' => form => {foo => $yatta} => charset => 'shift_jis')->status_is(200)->content_type_like(qr/Shift_JIS/) +$t->post_ok('/' => form => {foo => $yatta} => charset => 'shift_jis') + ->status_is(200) + ->content_type_like(qr/Shift_JIS/) ->content_like(qr/$yatta/); # Send as string (multipart message) $t->post_ok('/' => {'Content-Type' => 'multipart/form-data'} => form => {foo => $yatta} => charset => 'shift_jis') - ->status_is(200)->content_type_like(qr/Shift_JIS/)->content_like(qr/$yatta/); + ->status_is(200) + ->content_type_like(qr/Shift_JIS/) + ->content_like(qr/$yatta/); # Unicode renderer $t->get_ok('/unicode')->status_is(200)->content_type_is('text/plain;charset=UTF-8')->content_is($yatta); diff --git a/t/mojolicious/dispatcher_lite_app.t b/t/mojolicious/dispatcher_lite_app.t index e60bf66114..e59a31efab 100644 --- a/t/mojolicious/dispatcher_lite_app.t +++ b/t/mojolicious/dispatcher_lite_app.t @@ -127,7 +127,9 @@ subtest 'Normal route' => sub { }; subtest 'Normal static file' => sub { - $t->get_ok('/test.txt')->status_is(200)->header_is('Cache-Control' => 'max-age=3600, must-revalidate') + $t->get_ok('/test.txt') + ->status_is(200) + ->header_is('Cache-Control' => 'max-age=3600, must-revalidate') ->content_is("Normal static file!\n"); }; @@ -144,22 +146,30 @@ subtest 'Custom dispatcher' => sub { }; subtest 'Static file' => sub { - $t->get_ok('/res.txt')->status_is(200)->header_is('Cache-Control' => 'max-age=3600, must-revalidate') + $t->get_ok('/res.txt') + ->status_is(200) + ->header_is('Cache-Control' => 'max-age=3600, must-revalidate') ->content_is("Static response!\n"); }; subtest ' Custom response' => sub { - $t->get_ok('/res.txt?route=1')->status_is(202)->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate') + $t->get_ok('/res.txt?route=1') + ->status_is(202) + ->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate') ->content_is('Custom response!'); }; subtest 'Conditional response' => sub { - $t->get_ok('/res.txt?route=1&res=1')->status_is(201)->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate') + $t->get_ok('/res.txt?route=1&res=1') + ->status_is(201) + ->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate') ->content_is('Conditional response!'); }; subtest 'Another custom dispatcher' => sub { - $t->get_ok('/custom_too')->status_is(200)->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate') + $t->get_ok('/custom_too') + ->status_is(200) + ->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate') ->content_is('this works too'); }; diff --git a/t/mojolicious/embedded_lite_app.t b/t/mojolicious/embedded_lite_app.t index 3b7254dfe5..3451499313 100644 --- a/t/mojolicious/embedded_lite_app.t +++ b/t/mojolicious/embedded_lite_app.t @@ -260,7 +260,8 @@ subtest 'Stream from myapp.pl with Unicode prefix' => sub { }; subtest 'URL from myapp.pl with Unicode prefix' => sub { - $t->get_ok('/x/♥/url/☃')->status_is(200) + $t->get_ok('/x/♥/url/☃') + ->status_is(200) ->content_is('/x/%E2%99%A5/url/%E2%98%83.json -> /x/%E2%99%A5/%E2%98%83/stream!'); }; @@ -326,7 +327,9 @@ EOF }; subtest 'Host from myapp.pl with domain' => sub { - $t->get_ok('/host' => {Host => 'mojolicious.org'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/host' => {Host => 'mojolicious.org'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('mojolicious.org'); }; @@ -344,7 +347,9 @@ EOF }; subtest 'Host from myapp.pl with domain again' => sub { - $t->get_ok('/host' => {Host => 'mojolicious.org'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/host' => {Host => 'mojolicious.org'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('mojolicious.org'); }; @@ -362,17 +367,23 @@ EOF }; subtest 'Host from myapp.pl with wildcard domain' => sub { - $t->get_ok('/host' => {Host => 'ExAmPlE.CoM'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/host' => {Host => 'ExAmPlE.CoM'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('ExAmPlE.CoM'); }; subtest 'Host from myapp.pl with wildcard domain again' => sub { - $t->get_ok('/host' => {Host => 'www.example.com'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/host' => {Host => 'www.example.com'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('www.example.com'); }; subtest 'Host from myapp.pl with wildcard domain again' => sub { - $t->get_ok('/host' => {Host => 'foo.bar.example.com'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/host' => {Host => 'foo.bar.example.com'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('foo.bar.example.com'); }; @@ -390,7 +401,9 @@ EOF }; subtest 'Host from myapp.pl with wildcard domain and Unicode prefix' => sub { - $t->get_ok('/♥/123/host' => {Host => 'foo-bar.de'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/♥/123/host' => {Host => 'foo-bar.de'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('foo-bar.de'); }; @@ -399,7 +412,9 @@ subtest 'Echo from myapp.pl with wildcard domain and Unicode prefix' => sub { }; subtest 'Host from myapp.pl with wildcard domain and Unicode prefix again' => sub { - $t->get_ok('/♥/123/host' => {Host => 'www.foo-bar.de'})->status_is(200)->header_is('X-Message' => 'it works!') + $t->get_ok('/♥/123/host' => {Host => 'www.foo-bar.de'}) + ->status_is(200) + ->header_is('X-Message' => 'it works!') ->content_is('www.foo-bar.de'); }; @@ -424,8 +439,10 @@ subtest 'Another invalid domain' => sub { }; subtest 'Embedded WebSocket' => sub { - $t->websocket_ok('/x/♥/url_for')->send_ok('ws_test') - ->message_ok->message_like(qr!^ws://127\.0\.0\.1:\d+/x/%E2%99%A5/url_for$!)->send_ok('index') + $t->websocket_ok('/x/♥/url_for') + ->send_ok('ws_test') + ->message_ok->message_like(qr!^ws://127\.0\.0\.1:\d+/x/%E2%99%A5/url_for$!) + ->send_ok('index') ->message_ok->message_like(qr!^http://127\.0\.0\.1:\d+/x/%E2%99%A5$!)->finish_ok; }; diff --git a/t/mojolicious/exception_lite_app.t b/t/mojolicious/exception_lite_app.t index 40f52afa4b..a1486c85c7 100644 --- a/t/mojolicious/exception_lite_app.t +++ b/t/mojolicious/exception_lite_app.t @@ -208,14 +208,20 @@ subtest 'Dead included template' => sub { }; subtest 'Dead template with layout' => sub { - $t->get_ok('/dead_template_with_layout')->status_is(500)->content_like(qr/dead template with layout!/) - ->content_like(qr/line 2/)->content_unlike(qr/Green/); + $t->get_ok('/dead_template_with_layout') + ->status_is(500) + ->content_like(qr/dead template with layout!/) + ->content_like(qr/line 2/) + ->content_unlike(qr/Green/); like $log, qr/dead template with layout!/, 'right result'; }; subtest 'Dead action' => sub { - $t->get_ok('/dead_action')->status_is(500)->content_type_is('text/html;charset=UTF-8') - ->content_like(qr!get '/dead_action'!)->content_like(qr/dead action!/) + $t->get_ok('/dead_action') + ->status_is(500) + ->content_type_is('text/html;charset=UTF-8') + ->content_like(qr!get '/dead_action'!) + ->content_like(qr/dead action!/) ->text_is('#error' => "dead action!\n"); like $log, qr/dead action!/, 'right result'; }; @@ -225,18 +231,26 @@ subtest 'Dead action with different format' => sub { }; subtest 'Dead action with unsupported format' => sub { - $t->get_ok('/dead_action.json')->status_is(500)->content_type_is('text/html;charset=UTF-8') - ->content_like(qr!get '/dead_action'!)->content_like(qr/dead action!/); + $t->get_ok('/dead_action.json') + ->status_is(500) + ->content_type_is('text/html;charset=UTF-8') + ->content_like(qr!get '/dead_action'!) + ->content_like(qr/dead action!/); }; subtest 'Dead action with custom exception rendering' => sub { - $t->get_ok('/dead_action' => {Accept => 'text/plain'})->status_is(500)->content_type_is('text/plain;charset=UTF-8') + $t->get_ok('/dead_action' => {Accept => 'text/plain'}) + ->status_is(500) + ->content_type_is('text/plain;charset=UTF-8') ->content_like(qr/^dead action!\n/); }; subtest 'Action dies twice' => sub { - $t->get_ok('/double_dead_action_☃')->status_is(500)->content_like(qr!get '/double_dead_action_☃'!) - ->content_like(qr/File.+lite_app\.t\", line \d/)->content_like(qr/double dead action!/); + $t->get_ok('/double_dead_action_☃') + ->status_is(500) + ->content_like(qr!get '/double_dead_action_☃'!) + ->content_like(qr/File.+lite_app\.t\", line \d/) + ->content_like(qr/double dead action!/); }; subtest 'Trapped exception' => sub { @@ -256,33 +270,46 @@ subtest 'Exception in helper' => sub { }; subtest 'Missing template' => sub { - $t->get_ok('/missing_template')->status_is(500)->content_type_is('text/html;charset=UTF-8') + $t->get_ok('/missing_template') + ->status_is(500) + ->content_type_is('text/html;charset=UTF-8') ->content_like(qr/Route without action and nothing to render/); }; subtest 'Missing template with different format' => sub { - $t->get_ok('/missing_template.xml')->status_is(500)->content_type_is('application/xml') + $t->get_ok('/missing_template.xml') + ->status_is(500) + ->content_type_is('application/xml') ->content_is("bad\n"); }; subtest 'Missing template with unsupported format' => sub { - $t->get_ok('/missing_template.json')->status_is(500)->content_type_is('text/html;charset=UTF-8') + $t->get_ok('/missing_template.json') + ->status_is(500) + ->content_type_is('text/html;charset=UTF-8') ->content_like(qr/Route without action and nothing to render/); }; subtest 'Missing template with custom rendering' => sub { - $t->get_ok('/missing_template.txt')->status_is(500)->content_type_is('text/plain;charset=UTF-8') + $t->get_ok('/missing_template.txt') + ->status_is(500) + ->content_type_is('text/plain;charset=UTF-8') ->content_is('Missing template, whatever.'); }; subtest 'Missing template (failed rendering)' => sub { - $t->get_ok('/missing_template/too')->status_is(500)->content_type_is('text/html;charset=UTF-8') + $t->get_ok('/missing_template/too') + ->status_is(500) + ->content_type_is('text/html;charset=UTF-8') ->content_like(qr/Could not render a response/); }; subtest 'Missing helper (correct context)' => sub { - $t->get_ok('/missing_helper')->status_is(500)->content_type_is('text/html;charset=UTF-8') - ->content_like(qr/Server Error/)->content_like(qr/shift->missing_helper/); + $t->get_ok('/missing_helper') + ->status_is(500) + ->content_type_is('text/html;charset=UTF-8') + ->content_like(qr/Server Error/) + ->content_like(qr/shift->missing_helper/); }; subtest 'Reuse exception' => sub { @@ -298,39 +325,57 @@ subtest 'Reuse exception' => sub { subtest 'JSON exceptions' => sub { $t->app->mode('development'); is $t->app->exception_format('json')->exception_format, 'json', 'right exception format'; - $t->get_ok('/dead_template')->status_is(500)->content_type_is('application/json;charset=UTF-8') + $t->get_ok('/dead_template') + ->status_is(500) + ->content_type_is('application/json;charset=UTF-8') ->json_like('/error', qr/dead template!/); - $t->get_ok('/does_not_exist')->status_is(404)->content_type_is('application/json;charset=UTF-8') + $t->get_ok('/does_not_exist') + ->status_is(404) + ->content_type_is('application/json;charset=UTF-8') ->json_is({error => 'Not Found'}); my $stash; $t->app->hook(after_dispatch => sub { $stash = shift->stash }); - $t->get_ok('/txt/exception')->status_is(500)->header_is('X-Text' => 'txt') - ->content_type_is('text/plain;charset=UTF-8')->content_like(qr/Text exception/); + $t->get_ok('/txt/exception') + ->status_is(500) + ->header_is('X-Text' => 'txt') + ->content_type_is('text/plain;charset=UTF-8') + ->content_like(qr/Text exception/); ok $stash->{exception}, 'exception exists in stash'; isa_ok $stash->{exception}, 'Mojo::Exception', 'is stash exception correct type?'; $t->app->mode('production'); - $t->get_ok('/dead_template')->status_is(500)->content_type_is('application/json;charset=UTF-8') + $t->get_ok('/dead_template') + ->status_is(500) + ->content_type_is('application/json;charset=UTF-8') ->json_is({error => 'Internal Server Error'}); - $t->get_ok('/does_not_exist')->status_is(404)->content_type_is('application/json;charset=UTF-8') + $t->get_ok('/does_not_exist') + ->status_is(404) + ->content_type_is('application/json;charset=UTF-8') ->json_is({error => 'Not Found'}); }; subtest 'Text exceptions' => sub { $t->app->mode('development'); is $t->app->exception_format('txt')->exception_format, 'txt', 'right exception format'; - $t->get_ok('/dead_template')->status_is(500)->content_type_is('text/plain;charset=UTF-8') + $t->get_ok('/dead_template') + ->status_is(500) + ->content_type_is('text/plain;charset=UTF-8') ->content_like(qr/dead template!/); $t->get_ok('/does_not_exist')->status_is(404)->content_type_is('text/plain;charset=UTF-8')->content_is('Not Found'); my $stash; $t->app->hook(after_dispatch => sub { $stash = shift->stash }); - $t->get_ok('/txt/exception')->status_is(500)->header_is('X-Text' => 'txt') - ->content_type_is('text/plain;charset=UTF-8')->content_like(qr/Text exception/); + $t->get_ok('/txt/exception') + ->status_is(500) + ->header_is('X-Text' => 'txt') + ->content_type_is('text/plain;charset=UTF-8') + ->content_like(qr/Text exception/); ok $stash->{exception}, 'exception exists in stash'; isa_ok $stash->{exception}, 'Mojo::Exception', 'is stash exception correct type?'; $t->app->mode('production'); - $t->get_ok('/dead_template')->status_is(500)->content_type_is('text/plain;charset=UTF-8') + $t->get_ok('/dead_template') + ->status_is(500) + ->content_type_is('text/plain;charset=UTF-8') ->content_is('Internal Server Error'); $t->get_ok('/does_not_exist')->status_is(404)->content_type_is('text/plain;charset=UTF-8')->content_is('Not Found'); }; diff --git a/t/mojolicious/group_lite_app.t b/t/mojolicious/group_lite_app.t index a8ed526642..e9dea77f00 100644 --- a/t/mojolicious/group_lite_app.t +++ b/t/mojolicious/group_lite_app.t @@ -194,7 +194,9 @@ $t->reset_session; $t->get_ok('/multi')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is("\n\n\n\n\n\n\n\n"); # Multiple cookies with same name (again) -$t->get_ok('/multi')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/multi') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("two\nthree\none\ntwo\nfive\nsix\nfour\nfive\n"); # Missing action behind bridge @@ -213,15 +215,25 @@ undef $logs; $t->get_ok('/suspended?ok=0')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is('stopped!'); # Authenticated with header -$t->get_ok('/with_under' => {'X-Bender' => 'Rodriguez'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') - ->header_is('X-Under' => '23, 24')->header_like('X-Under' => qr/23, 24/)->content_is('Unders are cool!'); +$t->get_ok('/with_under' => {'X-Bender' => 'Rodriguez'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->header_is('X-Under' => '23, 24') + ->header_like('X-Under' => qr/23, 24/) + ->content_is('Unders are cool!'); # Authenticated with header too -$t->get_ok('/with_under_too' => {'X-Bender' => 'Rodriguez'})->status_is(200)->header_is(Server => 'Mojolicious (Perl)') - ->header_is('X-Under' => '23, 24')->header_like('X-Under' => qr/23, 24/)->content_is('Unders are cool too!'); +$t->get_ok('/with_under_too' => {'X-Bender' => 'Rodriguez'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->header_is('X-Under' => '23, 24') + ->header_like('X-Under' => qr/23, 24/) + ->content_is('Unders are cool too!'); # Not authenticated with header -$t->get_ok('/with_under_too')->status_is(401)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/with_under_too') + ->status_is(401) + ->header_is(Server => 'Mojolicious (Perl)') ->content_like(qr/Unauthorized/); # Not authenticated with parameter @@ -229,14 +241,18 @@ $t->get_ok('/param_auth')->status_is(200)->header_is(Server => 'Mojolicious (Per is $stash->{_name}, undef, 'no "_name" value'; # Authenticated with parameter -$t->get_ok('/param_auth?name=Bender')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/param_auth?name=Bender') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is("Bender!\n"); # Not authenticated with parameter $t->get_ok('/param_auth/too')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')->content_is("Not Bender!\n"); # Authenticated with parameter too -$t->get_ok('/param_auth/too?name=Bender')->status_is(200)->header_is(Server => 'Mojolicious (Perl)') +$t->get_ok('/param_auth/too?name=Bender') + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') ->content_is('You could be Bender too!'); # No cookies, session or flash @@ -246,7 +262,8 @@ is $stash->{_name}, 'stash', 'right "_name" value'; # Cookies, session and flash $logs = $t->app->log->capture('trace'); -$t->get_ok('/bridge2stash')->status_is(200) +$t->get_ok('/bridge2stash') + ->status_is(200) ->content_is("stash too!cookie!!signed_cookie!!bad_cookie--12345678!session!flash!\n"); like $logs, qr/Cookie "foo" is not signed/, 'right message'; like $logs, qr/Cookie "bad" has bad signature/, 'right message'; @@ -264,7 +281,8 @@ is $t->tx->res->cookie('mojolicious')->samesite, undef, 'no SameSite value'; $t->reset_session; my $session = b("☃☃☃☃☃")->encode->b64_encode(''); my $hmac = $session->clone->hmac_sha1_sum($t->app->secrets->[0]); -$t->get_ok('/bridge2stash' => {Cookie => "mojolicious=$session--$hmac"})->status_is(200) +$t->get_ok('/bridge2stash' => {Cookie => "mojolicious=$session--$hmac"}) + ->status_is(200) ->content_is("stash too!!!!!!!!\n"); # Not collecting cookies @@ -283,12 +301,14 @@ $t->get_ok('/mojo/logo-white.png')->status_is(200); $t->get_ok('/mojo/logo-white.png')->status_is(200); # With cookies, session and flash again -$t->get_ok('/bridge2stash')->status_is(200) +$t->get_ok('/bridge2stash') + ->status_is(200) ->content_is("stash too!cookie!!signed_cookie!!bad_cookie--12345678!session!flash!\n"); # With cookies and session but no flash (rotating secrets) $t->app->secrets(['test2', 'test1']); -$t->get_ok('/bridge2stash' => {'X-Flash2' => 1})->status_is(200) +$t->get_ok('/bridge2stash' => {'X-Flash2' => 1}) + ->status_is(200) ->content_is("stash too!cookie!!signed_cookie!!bad_cookie--12345678!session!!\n"); ok $t->tx->res->cookie('mojolicious')->expires < time, 'session cookie expires'; @@ -306,20 +326,26 @@ $t->get_ok('/late/session')->status_is(200)->content_is('works!'); $t->get_ok('/late/session')->status_is(200)->content_is('works!'); # Counter -$t->get_ok('/with/under/count' => {'X-Bender' => 'Rodriguez'})->status_is(200) - ->header_is(Server => 'Mojolicious (Perl)')->header_is('X-Under' => 1)->content_is("counter\n"); +$t->get_ok('/with/under/count' => {'X-Bender' => 'Rodriguez'}) + ->status_is(200) + ->header_is(Server => 'Mojolicious (Perl)') + ->header_is('X-Under' => 1) + ->content_is("counter\n"); is $stash->{_name}, undef, 'no "_name" value'; # Cookies, session and no flash again -$t->get_ok('/bridge2stash' => {'X-Flash' => 1})->status_is(200) +$t->get_ok('/bridge2stash' => {'X-Flash' => 1}) + ->status_is(200) ->content_is("stash too!cookie!!signed_cookie!!bad_cookie--12345678!session!!\n"); # With cookies, session and flash -$t->get_ok('/bridge2stash')->status_is(200) +$t->get_ok('/bridge2stash') + ->status_is(200) ->content_is("stash too!cookie!!signed_cookie!!bad_cookie--12345678!session!flash!\n"); # With cookies and session but no flash -$t->get_ok('/bridge2stash' => {'X-Flash2' => 1})->status_is(200) +$t->get_ok('/bridge2stash' => {'X-Flash2' => 1}) + ->status_is(200) ->content_is("stash too!cookie!!signed_cookie!!bad_cookie--12345678!session!!\n"); # Prefix @@ -362,7 +388,9 @@ $t->get_ok('/authgroup?ok=1')->status_is(200)->content_type_is('text/html;charse $t->get_ok('/authgroup')->status_is(200)->content_type_is('text/html;charset=UTF-8')->content_is("You're not ok."); # Authenticated by group (with format) -$t->get_ok('/authgroup.txt?ok=1')->status_is(200)->content_type_is('text/plain;charset=UTF-8') +$t->get_ok('/authgroup.txt?ok=1') + ->status_is(200) + ->content_type_is('text/plain;charset=UTF-8') ->content_is("You're ok."); # Not authenticated by group (with format) @@ -372,7 +400,9 @@ $t->get_ok('/authgroup.txt')->status_is(200)->content_type_is('text/plain;charse $t->get_ok('/noauthgroup')->status_is(200)->content_is("Whatever one.\n"); # Disabled format detection -$t->get_ok('/no_format')->status_is(200)->content_type_is('text/html;charset=UTF-8') +$t->get_ok('/no_format') + ->status_is(200) + ->content_type_is('text/html;charset=UTF-8') ->content_is('No format detection.'); # Invalid format @@ -382,11 +412,15 @@ $t->get_ok('/no_format.txt')->status_is(404)->content_type_is('text/html;charset $t->get_ok('/some_formats')->status_is(404)->content_type_is('text/html;charset=UTF-8')->content_is("Oops!\n"); # Format "txt" has been detected -$t->get_ok('/some_formats.txt')->status_is(200)->content_type_is('text/plain;charset=UTF-8') +$t->get_ok('/some_formats.txt') + ->status_is(200) + ->content_type_is('text/plain;charset=UTF-8') ->content_is('Some format detection.'); # Format "json" has been detected -$t->get_ok('/some_formats.json')->status_is(200)->content_type_is('application/json;charset=UTF-8') +$t->get_ok('/some_formats.json') + ->status_is(200) + ->content_type_is('application/json;charset=UTF-8') ->content_is('Some format detection.'); # Invalid format @@ -396,7 +430,9 @@ $t->get_ok('/some_formats.xml')->status_is(404)->content_type_is('text/html;char $t->get_ok('/no_real_format')->status_is(404)->content_type_is('text/html;charset=UTF-8')->content_is("Oops!\n"); # No format detected -$t->get_ok('/no_real_format.xml')->status_is(200)->content_type_is('text/html;charset=UTF-8') +$t->get_ok('/no_real_format.xml') + ->status_is(200) + ->content_type_is('text/html;charset=UTF-8') ->content_is('No real format.'); # Invalid format diff --git a/t/mojolicious/layouted_lite_app.t b/t/mojolicious/layouted_lite_app.t index 8756f96587..ff9cdf2d86 100644 --- a/t/mojolicious/layouted_lite_app.t +++ b/t/mojolicious/layouted_lite_app.t @@ -118,17 +118,23 @@ subtest '"0" content reassignment' => sub { }; subtest 'Template with layout' => sub { - $t->get_ok('/works')->status_is(200)->content_type_is('text/html;charset=UTF-8') + $t->get_ok('/works') + ->status_is(200) + ->content_type_is('text/html;charset=UTF-8') ->content_is("DefaultJust worksThis