El viernes, 26 de mayo de 2017, 20:23:09 (UTC-3), iaw4 escribió:
>
>
> dear M users / stefan : still stuck. this probably has a simple answer.
> here is my attempt at a simple form page and a test:
>
> #!/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();
>
>
> on this code
>
> #!/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>
>
>
> Hi,
Here:
> <p>Get Result: <span><%= ($self->req->query_params->param("sometext"))
> || "no text yet" %></span></p>
>
you probably meant "getsometext" instead of "sometext", like:
<p>Get Result: <span><%= ($self->req->query_params->param("getsometext"))
|| "no text yet" %></span></p>
also as a suggestion in Mojo inside a template you can use the param
default helper and say:
<p>Get Result: <span><%= (param "getsometext") || "no text yet"
%></span></p>
(just another way)
And same for the postsometext param
After those changes the tests pass.
By the way, I had to run the lite app with morbo (in default port 3000),
and from another terminal the Mojo::Test script, because I see you included
'http://localhost:3000/...' in all your requests.
But you don't actually have to do that, Mojo supports a simpler way to run
tests, as explained here:
http://mojolicious.org/perldoc/Mojolicious/Guides/Tutorial#Testing
BR,
Daniel
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.