Mojolicious-Plugin-PlackMiddleware
view release on metacpan or search on metacpan
xt/compat/lite_app.t view on Meta::CPAN
->content_like(qr/works!/);
# Dead renderer
$t->get_ok('/dead_renderer')->status_is(500)
->header_is(Server => 'Mojolicious (Perl)')
->content_like(qr/renderer works!/);
# Dead renderer with auto rendering
$t->get_ok('/dead_auto_renderer')->status_is(500)
->header_is(Server => 'Mojolicious (Perl)')
->content_like(qr/renderer works!/);
# Dead template
$t->get_ok('/dead_template')->status_is(500)
->header_is(Server => 'Mojolicious (Perl)')->content_like(qr/works too!/);
# Regex in name
$t->get_ok('/regex/in/template')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_is("test(test)(\\Qtest\\E)(\n");
# Chunked response with basic auth
$t->get_ok('//sri:foo@/stream' => form => {foo => 'bar'})->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_like(qr!^foobarsri:foohttp://127\.0\.0\.1:\d+/stream$!);
# Ajax
$t->get_ok('/maybe/ajax')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('not ajax');
$t->get_ok('/maybe/ajax' => {'X-Requested-With' => 'XMLHttpRequest'})
->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->content_is('is ajax');
# With finish event
my $stash;
$t->app->plugins->once(before_dispatch => sub { $stash = shift->stash });
$t->get_ok('/finished')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('so far so good!');
is $stash->{finished}, 2, 'finish event has been emitted once';
# IRI
$t->get_ok('/пÑивеÑ/миÑ')->status_is(200)
->content_type_is('text/html;charset=UTF-8')
->content_is('пÑÐ¸Ð²ÐµÑ Ð¼Ð¸Ñ');
# Route with format
$t->get_ok('/root.html')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is("/\n");
# Fallback route without format
$t->get_ok('/root')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->content_is('root fallback!');
$t->get_ok('/root.txt')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')->content_is('root fallback!');
# Root with format
$t->get_ok('/.html')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->content_is("/root.html\n/root.html\n/root.html\n/root.html\n/root.html\n");
# Reverse proxy with "X-Forwarded-For"
{
local $ENV{MOJO_REVERSE_PROXY} = 1;
$t->ua->server->restart;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})
->status_is(200)->header_unlike('X-Original' => qr/192\.0\.2\.1/)
->content_like(qr!http://127\.0\.0\.1:\d+/0-192\.0\.2\.1-0$!);
}
# Reverse proxy with "X-Forwarded-Proto"
{
local $ENV{MOJO_REVERSE_PROXY} = 1;
$t->ua->server->restart;
$t->get_ok('/0' => {'X-Forwarded-Proto' => 'https'})->status_is(200)
->content_like(qr!^https://127\.0\.0\.1:\d+/0-!)->content_like(qr/-0$/)
->content_unlike(qr!-192\.0\.2\.1-0$!);
}
# "X-Forwarded-For"
$t->ua->server->restart;
$t->get_ok('/0' => {'X-Forwarded-For' => '192.0.2.2, 192.0.2.1'})
->status_is(200)->content_like(qr!^http://127\.0\.0\.1:\d+/0-!)
->content_like(qr/-0$/)->content_unlike(qr!-192\.0\.2\.1-0$!);
# "X-Forwarded-Proto"
$t->get_ok('/0' => {'X-Forwarded-Proto' => 'https'})->status_is(200)
->content_like(qr!^http://127\.0\.0\.1:\d+/0-!)->content_like(qr/-0$/)
->content_unlike(qr!-192\.0\.2\.1-0$!);
# Inline "epl" template
$t->delete_ok('/inline/epl')->status_is(200)->content_is("2 â\n");
# Inline "ep" template
$t->get_ok('/inline/ep?foo=bar')->status_is(200)->content_is("barworks!\n");
# Inline "ep" template "0"
$t->get_ok('/inline/ep/too')->status_is(200)->content_is("0\n");
# Inline template with include
$t->get_ok('/inline/ep/include')->status_is(200)
->content_is("â¥just â¥\nworks!\n");
# Rewritten localized arguments
$t->get_ok('/to_string')->status_is(200)->content_is('beforeafter');
# Render static file outside of public directory
$t->get_ok('/source')->status_is(200)
->content_type_is('text/plain;charset=UTF-8')->header_isnt('X-Missing' => 1)
->content_like(qr!get_ok\('/source!);
# File does not exist
$log = '';
$cb = $t->app->log->on(message => sub { $log .= pop });
$t->get_ok('/source?fail=1')->status_is(404)->header_is('X-Missing' => 1)
->content_is("Oops!\n");
like $log, qr/Static file "does_not_exist.txt" not found/, 'right message';
$t->app->log->unsubscribe(message => $cb);
# With body and max message size
{
local $ENV{MOJO_MAX_MESSAGE_SIZE} = 1024;
$t->get_ok('/', '1234' x 1024)->status_is(200)
->header_is(Connection => 'close')
->content_is("Maximum message size exceeded\n"
. "/root.html\n/root.html\n/root.html\n/root.html\n/root.html\n");
}
# Relaxed placeholder
$t->get_ok('/foo_relaxed/123')->status_is(200)->content_is('1230');
$t->get_ok('/foo_relaxed/123.html')->status_is(200)->content_is('123.html0');
$t->get_ok('/foo_relaxed/123' => {DNT => 1})->status_is(200)
->content_is('1231');
$t->get_ok('/foo_relaxed/')->status_is(404);
# Wildcard placeholder
$t->get_ok('/foo_wildcard/123')->status_is(200)->content_is('123');
$t->get_ok('/foo_wildcard/IQ==%0A')->status_is(200)->content_is("IQ==\x0a");
$t->get_ok('/foo_wildcard/')->status_is(404);
$t->get_ok('/foo_wildcard_too/123')->status_is(200)->content_is('123');
$t->get_ok('/foo_wildcard_too/')->status_is(404);
( run in 2.526 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )