Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion t/mailform.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use Test::More tests => 4;
use Test::More tests => 11;

# Need CGI.pm for tests
use CGI;



SKIP: {
# Check for Net::SMTP
Expand All @@ -20,3 +25,70 @@ SKIP: {
# Did it inherit the run method?
can_ok($mf, qw/run/);
}

# Instantiate CGI::Application::Mailform
# run() CGI::Application::Mailform object.
# Expect redirect header + body
{
my $app = CGI::Application::Mailform->new();
isa_ok($app, 'CGI::Application::Mailform');

$app->query(CGI->new(""));
$app->param(MAIL_FROM=>'a');
$app->param(MAIL_TO => 'b');
$app->param(HTMLFORM_REDIRECT_URL => 'redirect_url');
$app->param(SUCCESS_REDIRECT_URL => 'd');
$app->param(FORM_FIELDS => []);


response_like(
$app,
qr/^Status: 302/,
qr/Continue: <a href="redirect_url">redirect_url<\/a>/,
'TestApp, redirect_test'
);
}

# Instantiate CGI::Application::Mailform with missing params
# run() CGI::Application::Mailform object.
# Expect error
{
my $app = CGI::Application::Mailform->new();
isa_ok($app, 'CGI::Application::Mailform');

$app->query(CGI->new(""));

my $output;
eval { $output = $app->run; };

like( $@, qr/Missing or invalid required parameters/, "Missing paramters");
}

# Instantiate CGI::Application::Mailform with invalid params
# run() CGI::Application::Mailform object.
# Expect error
{
my $app = CGI::Application::Mailform->new();
isa_ok($app, 'CGI::Application::Mailform');

$app->query(CGI->new(""));
$app->param(MAIL_FROM=>'');
$app->param(FORM_FIELDS => 'not an arrayref');


my $output;
eval { $output = $app->run; };

like( $@, qr/Missing or invalid required parameters/, "Missing paramters");
}


sub response_like {
my ($app, $header_re, $body_re, $comment) = @_;

local $ENV{CGI_APP_RETURN_ONLY} = 1;
my $output = $app->run;
my ($header, $body) = split /\r\n\r\n/m, $output;
like($header, $header_re, "$comment (header match)");
like($body, $body_re, "$comment (body match)");
}
34 changes: 26 additions & 8 deletions t/run_as_psgi.t
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,32 @@ sub setup {
}

package main;
# Run as PSGI Application directly
{
my $app = TestApp->new( QUERY => CGI::PSGI->new($env) );

my $app = TestApp->new( QUERY => CGI::PSGI->new($env) );
my $response = $app->run_as_psgi;

my $response = $app->run_as_psgi;
is_deeply $response, [
'200',
[ 'Content-Type' => 'text/html; charset=ISO-8859-1' ],
[ 'Hello World' ],
],
"run_as_psgi: reality check basic response";
}

# Retrieve the PGSI app as a subroutine
{
my $app = TestApp->new( QUERY => CGI::PSGI->new($env) );

my $psgi_app = $app->psgi_app;

is_deeply $response, [
'200',
[ 'Content-Type' => 'text/html; charset=ISO-8859-1' ],
[ 'Hello World' ],
],
"run_as_psgi: reality check basic response";
my $response = $psgi_app->();

is_deeply $response, [
'200',
[ 'Content-Type' => 'text/html; charset=ISO-8859-1' ],
[ 'Hello World' ],
],
"run_as_psgi: reality check basic response";
}