113 lines
4 KiB
Perl
113 lines
4 KiB
Perl
# vim:syntax=perl
|
|
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2007 Plain Black Corporation.
|
|
#-------------------------------------------------------------------
|
|
# Please read the legal notices (docs/legal.txt) and the license
|
|
# (docs/license.txt) that came with this distribution before using
|
|
# this software.
|
|
#------------------------------------------------------------------
|
|
# http://www.plainblack.com info@plainblack.com
|
|
#------------------------------------------------------------------
|
|
|
|
# This script tests the creation, sending, and queuing of mail messages
|
|
# TODO: There is plenty left to do in this script.
|
|
|
|
use FindBin;
|
|
use strict;
|
|
use lib "$FindBin::Bin/../lib";
|
|
use Test::More;
|
|
use WebGUI::Test;
|
|
|
|
use WebGUI::Mail::Send;
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Init
|
|
my $session = WebGUI::Test->session;
|
|
|
|
my $mail; # The WebGUI::Mail::Send object
|
|
my $mime; # for getMimeEntity
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Tests
|
|
|
|
plan tests => 5; # Increment this number for each test you create
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Test create
|
|
$mail = WebGUI::Mail::Send->create( $session );
|
|
isa_ok( $mail, 'WebGUI::Mail::Send',
|
|
"WebGUI::Mail::Send->create returns a WebGUI::Mail::Send object",
|
|
);
|
|
|
|
# Test that getMimeEntity works
|
|
$mime = $mail->getMimeEntity;
|
|
isa_ok( $mime, 'MIME::Entity',
|
|
"getMimeEntity",
|
|
);
|
|
|
|
# Test that create gets the appropriate defaults
|
|
# TODO
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Test addText
|
|
$mail = WebGUI::Mail::Send->create( $session );
|
|
my $text = <<'EOF';
|
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
|
EOF
|
|
|
|
$mail->addText($text);
|
|
$mime = $mail->getMimeEntity;
|
|
|
|
# addText should add newlines after 78 characters
|
|
my $newlines = length $text / 78;
|
|
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
|
"addText should add newlines after 78 characters",
|
|
);
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Test addHtml
|
|
$mail = WebGUI::Mail::Send->create( $session );
|
|
my $text = <<'EOF';
|
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
|
EOF
|
|
|
|
$mail->addHtml($text);
|
|
$mime = $mail->getMimeEntity;
|
|
|
|
# TODO: Test that addHtml creates an HTML wrapper if no html or body tag exists
|
|
# TODO: Test that addHtml creates a body with the right content type
|
|
|
|
# addHtml should add newlines after 78 characters
|
|
my $newlines = length $text / 78;
|
|
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
|
"addHtml should add newlines after 78 characters",
|
|
);
|
|
|
|
$mail = WebGUI::Mail::Send->create( $session );
|
|
# TODO: Test that addHtml does not create an HTML wrapper if html or body tag exist
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Test addHtmlRaw
|
|
$mail = WebGUI::Mail::Send->create( $session );
|
|
my $text = <<'EOF';
|
|
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Suspendisse eu lacus ut ligula fringilla elementum. Cras condimentum, velit commodo pretium semper, odio ante accumsan orci, a ultrices risus justo a nulla. Aliquam erat volutpat.
|
|
EOF
|
|
|
|
$mail->addHtmlRaw($text);
|
|
$mime = $mail->getMimeEntity;
|
|
|
|
# TODO: Test that addHtmlRaw doesn't add an HTML wrapper
|
|
|
|
# addHtmlRaw should add newlines after 78 characters
|
|
my $newlines = length $text / 78;
|
|
is( $mime->parts(0)->as_string =~ m/\n/, $newlines,
|
|
"addHtmlRaw should add newlines after 78 characters",
|
|
);
|
|
|
|
# TODO: Test that addHtml creates a body with the right content type
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Cleanup
|
|
END {
|
|
|
|
}
|