NAME
Test::Mojo::Role::SubmitForm - Test::Mojo role that allows to submit forms
SYNOPSIS
use Test::More;
use Test::Mojo::WithRoles 'SubmitForm';
my $t = Test::Mojo::WithRoles->new('MyApp');
# Submit a form without clicking any buttons: pass selector to the form
$t->get_ok('/')->status_is(200)->click_ok('form#one')->status_is(200);
# Click a particular button
$t->get_ok('/')->status_is(200)->click_ok('[type=submit]')->status_is(200);
# Submit a form while overriding form data
$t->get_ok('/')->status_is(200)
->click_ok('form#one', {
input1 => '42',
select1 => [ 1..3 ],
other_select => sub { my $r = shift; [ @$r, 42 ] },
another_input => sub { shift . 'offix'}
})->status_is(200);
done_testing;
DESCRIPTION
A Test::Mojo role that allows you submit forms, optionally overriding any of the values already present
METHODS
You have all the methods provided by Test::Mojo, plus these:
click_ok
$t->click_ok('form');
$t->click_ok('#button');
$t->click_ok('#button', {
input1 => '42',
select1 => [ 1..3 ],
other_select => sub { my $r = shift; [ @$r, 42 ] },
another_input => sub { shift . 'offix'}
})
First parameter specifies a CSS selector matching a <form>
you want to submit or a particular <button>
, <input type="submit">
, or <input type="image">
you want to click.
Specifying a second parameter allows you to override the form control values: the keys are name=""
s of controls to override and values can be either plain scalars (use arrayrefs for multiple values) or subrefs. Subrefs will be evaluated and their first @_
element will be the current value of the form control.
SEE ALSO
REPOSITORY
Fork this module on GitHub: https://github.com/zoffixznet/Test-Mojo-Role-SubmitForm
BUGS
To report bugs or request features, please use https://github.com/zoffixznet/Test-Mojo-Role-SubmitForm/issues
If you can't access GitHub, you can email your request to bug-test-mojo-role-SubmitForm at rt.cpan.org
AUTHOR
LICENSE
You can use and distribute this module under the same terms as Perl itself. See the LICENSE
file included in this distribution for complete details.