CGI-Application-MailPage

 view release on metacpan or  search on metacpan

t/01.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More;
use Test::LongString;
use File::Temp;
use HTTP::Request;
use LWP::UserAgent;

plan(tests => 47);

require_ok('CGI');
require_ok('CGI::Application::MailPage');
my $options = {
    page         => 'http://unused/test.html',
    rm           => 'send_mail',
    name         => 'Sammy Sender',
    from_email   => 'sam@tregar.com',
    subject      => 'Test Subject',
    to_emails    => 'sam@tregar.com',
    note         => '',
    format       => 'both_attachment',
};

$ENV{CGI_APP_RETURN_ONLY} = 1;
$ENV{REMOTE_ADDR} = '123.45.67.89';
my $good_url = 'http://www.perl.com';


# 3-4
# test a the 'both_attachment' format
{
    my $query = CGI->new($options);
    my $mail;
    my $mailpage = CGI::Application::MailPage->new(
        QUERY => $query,
        PARAMS => {
            document_root => './',
            smtp_server => 'unused',
            dump_mail => \$mail,
            use_page_param => 1,
        }
    );
    my $output = $mailpage->run();
    die if($output !~ /Mail Dumped/);
    contains_string($mail, 'This is the test HTML page', 'Test page as both');
    contains_string($mail, 'X-Originating-Ip: 123.45.67.89');
}

# 5 
# test a the 'html' format
{
    $options->{format} = 'html';
    my $query = CGI->new($options);
    my $mail;
    my $mailpage = CGI::Application::MailPage->new(
        QUERY => $query,
        PARAMS => {
            document_root => './',
            smtp_server => 'unused',
            dump_mail => \$mail,
            use_page_param => 1,
        }
    );
    my $output = $mailpage->run();
    die if($output !~ /Mail Dumped/);
    ok($mail =~ /<H1>This is the test HTML page<\/H1>/, 'Test page as HTML');



( run in 1.199 second using v1.01-cache-2.11-cpan-0d23b851a93 )