#!perl -w # $Id: alt.t 3444 2008-02-20 00:20:50Z david $ use strict; use Test::More; use File::Spec::Functions; if (eval { require HTML::Entities }) { plan tests => 92; } else { plan skip_all => "SVN::Notify::Alternative requires HTML::Entities"; } use_ok 'SVN::Notify::Alternative' or die; my $ext = $^O eq 'MSWin32' ? '.bat' : ''; my $dir = catdir curdir, 't', 'scripts'; $dir = catdir curdir, 't', 'bin' unless -d $dir; my %args = ( svnlook => catfile($dir, "testsvnlook$ext"), sendmail => catfile($dir, "testsendmail$ext"), repos_path => 'tmp', revision => '111', to => 'test@example.com', handler => 'Alternative', ); ############################################################################## # Basic Functionality. ############################################################################## ok my $notifier = SVN::Notify->new(%args), 'Construct new alt notifier'; isa_ok $notifier, 'SVN::Notify::Alternative'; isa_ok $notifier, 'SVN::Notify'; ok $notifier->prepare, 'Prepare alt notifier'; ok $notifier->execute, 'Execute the alt notifier'; my $email = get_output(); my $mime_count = ($email =~ s/MIME-Version/MIME-Version/g); is $mime_count, 1, 'There should be only one MIME-Version header'; my ($bound) = $email =~ m{Content-Type: multipart/alternative; boundary="([^"]+)"}; ok $bound, 'There should be a multiplart/alternative header'; my $bound_count = ($email =~ s/--$bound/--$bound/g); is $bound_count, 3, 'There should be three instances of the boundary'; like $email, qr{--$bound--\s+$}, 'The message should end with the final boundary'; like $email, qr{Content-Type: text/plain; charset=UTF-8}, 'There should be a plain text content-type'; like $email, qr{Content-Type: text/html; charset=UTF-8}, 'There should be an HTML content-type'; # Make sure we have headers for each of the four kinds of changes. for my $header ( 'Log Message', 'Modified Paths', 'Added Paths', 'Removed Paths', 'Property Changed', ) { like $email, qr/^$header/m, $header; like $email, qr{^
\s*Did this, that, and the «other»[.] And then I did some more[.] Some\nit was done on a second line[.] “Go figure”[.] r1234\s*
}ms, 'Check for Trac formatting in the HTML part'; } ############################################################################## # Functions. ############################################################################## sub get_output { my $outfile = catfile qw(t data output.txt); open CAP, "<$outfile" or die "Cannot open '$outfile': $!\n"; binmode CAP, 'utf8' if SVN::Notify::PERL58(); return join '',