Skip to content

Instantly share code, notes, and snippets.

@hesco
Created February 21, 2013 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hesco/5001900 to your computer and use it in GitHub Desktop.
Save hesco/5001900 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Mojo;
use Data::Dumper;
use FindBin;
require "$FindBin::Bin/../scripts/www/admin/password_reset";
my $t = Test::Mojo->new();
# $t->app->log->level('error');
$t->get_ok('/password_reset')
->status_is(200)
->element_exists('form input[name="site_url"]')
->element_exists('form input[type="submit"]');
done_testing();
exit;
------------------------------------------------------------
#!/usr/bin/env perl
use Mojolicious::Lite;
use HTML::FormHandler;
# Documentation browser under "/perldoc"
plugin 'PODRenderer';
any [qw( get post )] => '/password_reset' => sub {
my $self = shift;
my @fields = (
{
name => 'site_url',
label => 'Site URL',
required => 1,
},
{
name => 'get_pw_reset_hash',
type => 'submit',
value => 'Obtain Password Reset Hash',
},
);
my %form = (
required_message => 'Please provide a valid and fully qualified URL',
);
my $form = HTML::FormHandler->new(
field_list => \@fields,
%form,
);
$form->process( params => $self->req->params->to_hash );
if( $form->validated ){
$self->render( text => 'Obtaining Password Reset Hash for: '
. $form->field('site_url')->value() );
} else {
$self->render( text => $form->render );
}
};
app->secret('very_secret');
app->start;
__DATA__
=pod
@@ password_reset.html.ep
% layout 'default';
% title 'Control Panel';
<h1>Control Panel</h1>
<div id="password_reset">
</div>
@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
<head><title><%= title %></title></head>
<body><%= content %></body>
</html>
-------------------------------------------------------------------
usage: t/104-www-admin-cp-reset-pw.t COMMAND [OPTIONS]
Tip: CGI and PSGI environments can be automatically detected very often and
work without commands.
These commands are currently available:
routes Show available routes.
daemon Start application with HTTP and WebSocket server.
prefork Start application with preforking HTTP and WebSocket server.
inflate Inflate embedded files to real files.
test Run unit tests.
eval Run code against application.
cgi Start application with CGI.
cpanify Upload distribution to CPAN.
get Perform HTTP request.
generate Generate files and directories from templates.
version Show versions of installed modules.
psgi Start application with PSGI.
These options are available for all commands:
-h, --help Get more information on a specific command.
--home <path> Path to your applications home directory, defaults to
the value of MOJO_HOME or auto detection.
-m, --mode <name> Run mode of your application, defaults to the value
of MOJO_MODE or "development".
See 't/104-www-admin-cp-reset-pw.t help COMMAND' for more information on a specific command.
ok 1 - get /drupal_password_reset
not ok 2 - 200 OK
# Failed test '200 OK'
# at t/104-www-admin-cp-reset-pw.t line 12.
# got: '500'
# expected: '200'
not ok 3 - element for selector "form input[name="site_url"]" exists
# Failed test 'element for selector "form input[name="site_url"]" exists'
# at t/104-www-admin-cp-reset-pw.t line 12.
not ok 4 - element for selector "form input[type="submit"]" exists
# Failed test 'element for selector "form input[type="submit"]" exists'
# at t/104-www-admin-cp-reset-pw.t line 12.
1..4
# Looks like you failed 3 tests of 4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment