#!/usr/bin/env perl
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new;
$t->get_ok('http://localhost:3000/')->status_is(200)->content_like(qr{<h1>TITLE: basic mojolicious cribsheet</h1>});
$t->get_ok('http://localhost:3000/')->status_is(200)->content_unlike(qr{<h1>bad: basic mojolicious cribsheet</h1>});
my $teststring='this-is-my-test-text';
# why is this not working?
$t->get_ok( 'http://localhost:3000/' => form => { from => 'http://localhost:3000/', getsometext => $teststring, id => 'formget' } )
->status_is(200)
->content_like( qr{<span>$teststring</span>}ms );
# or this?
$t->post_ok( 'http://localhost:3000/' => form => { from => 'http://localhost:3000/', postsometext => $teststring, id => 'formpost' } )
->status_is(200)
->content_like( qr{Post Result: <span>$teststring</span>}ms );
done_testing();
#!/usr/bin/env perl
use Mojolicious::Lite;
my $indexpage= sub {
my $c = shift;
$c->render(template => 'index' );
};
get '/' => $indexpage;
post '/' => $indexpage;
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'basic mojolicious cribsheet';
<h1>TITLE: <%= title %></h1>
<h2> FORM GET </h2>
<form action='/' method='GET' id="formget">
<input id="getsometext" name="sometext" value="this was get" />
<input id="getsubmit" type="submit">
</form>
<p>Get Result: <span><%= ($self->req->query_params->param("sometext")) || "no text yet" %></span></p>
<h2> FORM POST </h2>
<form action='/?ab=12' method='POST' id="formpost">
<input id="postsometext" name="somepost" value="this was post" />
<input id="postsubmit" type="submit">
</form>
<p>Post Result: <span><%= ($self->req->params->param("somepost")) || "no text yet" %></span> .<br />
Query Params: <span><%= ($self->req->query_params->param("ab")) || "ab not seen" %></span></p>
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body style="margin:3em; background-color:beige">
<%= content %>
</body>
</html>
Could someone please post a simple Mojo::Test example that
- enters text "abc" (or adds "123" at the end of the text already in the text) into an id'ed input text field of some specific form (also identified by some id)
- then presses the submit button (identified by some id) or a link
- and checks that the result from this request contains a certain string
<p>Get Result: <span><%= ($self->req->query_params->param("sometext")) || "no text yet" %></span></p>
#!/usr/bin/env perl
use Test::More;
use Test::Mojo;
use FindBin;
require "$FindBin::Bin/quicksheet";
my $t = Test::Mojo->new;
$t->get_ok('/')->status_is(200)->content_like(qr{<h1>TITLE: basic mojolicious cribsheet</h1>});
$t->get_ok('/')->status_is(200)->content_unlike(qr{<h1>bad: basic mojolicious cribsheet</h1>});
my $teststringG='this-is-my-Gtest-text';
$t->get_ok( '/' => form => { from => '/', someget => $teststringG, id => 'formget' } )
->status_is(200)
->content_like( qr{<span>$teststringG</span>}ms );
my $teststringP='this-is-my-Ptest-text';
$t->post_ok( '/' => form => { from => '/', somepost => $teststringP, id => 'formpost' } )
->status_is(200)
->content_like( qr{Post Result: <span>$teststringP</span>}ms );
done_testing();
#!/usr/bin/env perl
use Mojolicious::Lite;
my $indexpage= sub {
my $c = shift;
$c->render(template => 'index' );
};
get '/' => $indexpage;
post '/' => $indexpage;
app->start;
__DATA__
@@ index.html.ep
% layout 'default';
% title 'basic mojolicious cribsheet';
<h1>TITLE: <%= title %></h1>
<h2> FORM GET </h2>
<form action='/' method='GET
' id="formget">
<input id="getidsometext" name="someget" value="this was get" />
<input id="getsubmit" type="submit">
</form>
<p>Get Result: <span><%= ($self->req->query_params->param("someget")) || "no text yet" %></span></p>
<h2> FORM POST </h2>
<form action='
/?ab=12' method='POST' id="formpost">
<input id="postidsometext" name="somepost" value="this was post" />
<input id="postsubmit" type="submit">
</form>
<p>Post Result: <span><%= ($self->req->params->param("somepost")) || "no text yet" %></span> .<br />
Query Params: <span><%= ($self->req->query_params->param("ab")) || "ab not seen" %></span></p>
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head>
<title><%= title %></title>
</head>
<body style="margin:3em; background-color:beige">
<%= content %>
</body>
</html>