#!perl -w use strict; use Test::More tests => 135; use File::Spec::Functions; use constant TEST_HTML => eval 'require HTML::Entities'; use_ok('SVN::Notify'); SKIP: { skip 'HTML::Entities did not load', 2 unless TEST_HTML; use_ok('SVN::Notify::HTML'); use_ok('SVN::Notify::HTML::ColorDiff'); } 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'], filters => ['Uppercase'], ); my $subj = "DId thIs, thAt, And thE «OthEr»."; my $qsubj; if (SVN::Notify::PERL58()) { Encode::_utf8_on( $subj ); $qsubj = quotemeta Encode::encode( 'MIME-Q', $subj ); } else { $qsubj = quotemeta $subj; } ############################################################################## # Basic Functionality. ############################################################################## ok( my $notifier = SVN::Notify->new(%args), 'Construct new notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare log_message filter checking'; ok $notifier->execute, 'Notify log_mesage filter checking'; my $email = get_output(); UTF8: { use utf8; like $email, qr/DID THIS, THAT, AND THE «OTHER»/, 'The log message should be uppercase'; } ############################################################################## # Multiple Filters. ############################################################################## ok( $notifier = SVN::Notify->new( %args, filters => [ 'Uppercase', 'LowerVowel' ], ), 'Construct new multi filter notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare log_message filter checking'; ok $notifier->execute, 'Notify log_mesage filter checking'; $email = get_output(); UTF8: { use utf8; like $email, qr/DiD THiS, THaT, aND THe «oTHeR»/, 'The log message should be uppercase but vowels lowercase'; } ############################################################################## # Recipients, From, and Subject filter. ############################################################################## ok( $notifier = SVN::Notify->new( %args, filters => [ 'LowerVowel' ], ), 'Construct recipients filter notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare recipients filter checking'; ok $notifier->execute, 'Notify recipients_mesage filter checking'; like $email, qr/^To: tEst[@]ExAmplE[.]cOm/m, 'The recipient should be modified'; like $email, qr/From: thEOry/m, 'The From header should be modified'; like $email, qr/Subject: \[111\] $qsubj/m, 'The Subject should be modified'; ############################################################################## # Metadata filter. ############################################################################## ok( $notifier = SVN::Notify->new( %args, filters => [ 'CapMeta' ], ), 'Construct new metadata filter notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare log_message filter checking'; ok $notifier->execute, 'Notify log_mesage filter checking'; $email = get_output(); like $email, qr/REVISION: 111/, 'Revision header should be uppercase'; like $email, qr/AUTHOR: theory/, 'Author header should be uppercase'; ############################################################################## # Headers filter. ############################################################################## ok( $notifier = SVN::Notify->new( %args, filters => [ 'AddHeader' ], ), 'Construct new headers filter notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare log_message filter checking'; ok $notifier->execute, 'Notify log_mesage filter checking'; $email = get_output(); like $email, qr/X-Foo: Bar\nContent-Type:/, 'New header should be included'; ############################################################################## # Start and End filters. ############################################################################## ok( $notifier = SVN::Notify->new( %args, filters => [ 'StartEnd' ], ), 'Construct start and end filter notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare log_message filter checking'; ok $notifier->execute, 'Notify log_mesage filter checking'; $email = get_output(); like $email, qr/In the beginning[.]{3}/, 'Start text should be present'; like $email, qr/The end[.]/, 'End text should be present'; ############################################################################## # HTML Testing. ############################################################################## SKIP: { skip 'HTML::Entities did not load', 12 unless TEST_HTML; ########################################################################## # Start and End filters with SVN::Notify::HTML. ########################################################################## ok( $notifier = SVN::Notify::HTML->new( %args, filters => [ 'StartEnd' ], ), 'Construct HTML start and end filter notifier' ); isa_ok($notifier, 'SVN::Notify'); ok $notifier->prepare, 'Prepare log_message filter checking'; ok $notifier->execute, 'Notify log_mesage filter checking'; $email = get_output(); like $email, qr/