Skip to content

Commit

Permalink
Item12823: merge identical code blocks
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x01@17450 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Mar 26, 2014
1 parent 603317b commit a0745a3
Showing 1 changed file with 27 additions and 67 deletions.
94 changes: 27 additions & 67 deletions MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm
Expand Up @@ -9,7 +9,7 @@ our @ISA = qw( FoswikiFnTestCase );

use Foswiki::Contrib::MailerContrib();

my $testWeb2;
my $subWeb;

my @specs;
my $high_bit_disabled = 0;
Expand Down Expand Up @@ -63,10 +63,10 @@ sub set_up {

my $text;

$testWeb2 = "$this->{test_web}/SubWeb";
$subWeb = "$this->{test_web}/SubWeb";

# Will get torn down when the parent web dies
my $webObject = $this->populateNewWeb($testWeb2);
my $webObject = $this->populateNewWeb($subWeb);
$webObject->finish();

$this->registerUser( "tu1", "Test", "User1", "test1\@example.com" );
Expand Down Expand Up @@ -248,7 +248,9 @@ sub set_up {
foreach my $spec (@specs) {
$s .= " * $spec->{entry}\n";
}
foreach my $web ( $this->{test_web}, $testWeb2 ) {

# Create the same test data in two separate webs
foreach my $web ( $this->{test_web}, $subWeb ) {
my ($meta) =
Foswiki::Func::readTopic( $web, $Foswiki::cfg{NotifyTopicName} );
$meta->put( "TOPICPARENT", { name => "$web.WebHome" } );
Expand Down Expand Up @@ -308,26 +310,19 @@ sub set_up {
# OK, we should have a bunch of changes
}

sub testSimple {
sub checkSpecs {
my $this = shift;

my @webs = ( $this->{test_web}, $this->{users_web} );
Foswiki::Contrib::MailerContrib::mailNotify( \@webs, 0, undef, 0, 0 );

#print "REPORT\n",join("\n\n", @FoswikiFnTestCase::mails);

# Check that expected - and only specced - mails were received
my %matched;
foreach my $msg (@FoswikiFnTestCase::mails) {
my $message = $msg;
foreach my $message (@FoswikiFnTestCase::mails) {
next unless $message;
$message =~ /^To: (.*)$/m;
my $mailto = $1;
$this->assert($mailto);
$message =
join( "\n", grep { /^- \w+ \(/ } split( /\n/, $message ) ) . "\n";
$this->assert( $mailto, $message );
foreach my $spec (@specs) {
if ( $mailto eq $spec->{email} ) {
$this->assert( !$matched{$mailto}, $mailto );
$this->assert( !$matched{$mailto} );
$matched{$mailto} = 1;
my $xpect = $spec->{topicsout};
my @tops;
Expand Down Expand Up @@ -369,78 +364,43 @@ sub testSimple {
if ( $spec->{topicsout} ne "" ) {
$this->assert(
$matched{ $spec->{email} },
"$spec->{name}: Expected mails for "
"Expected mails for "
. $spec->{email}
. " but only got "
. " but only saw mails for "
. join( " ", keys %matched )
);
}
else {
$this->assert(
!$matched{ $spec->{email} },
"$spec->{name}: Unexpected mails for "
"Didn't expect mails for "
. $spec->{email}
. " (got "
. "; got "
. join( " ", keys %matched )
);
}
}
}

sub testSubweb {
sub testSimple {
my $this = shift;

my @webs = ( $testWeb2, $this->{users_web} );
my @webs = ( $this->{test_web}, $this->{users_web} );
Foswiki::Contrib::MailerContrib::mailNotify( \@webs, 0, undef, 0, 0 );

#print "REPORT\n",join("\n\n", @FoswikiFnTestCase::mails);
$this->checkSpecs();
}

my %matched;
foreach my $message (@FoswikiFnTestCase::mails) {
next unless $message;
$message =~ /^To: (.*)$/m;
my $mailto = $1;
$this->assert( $mailto, $message );
foreach my $spec (@specs) {
if ( $mailto eq $spec->{email} ) {
$this->assert( !$matched{$mailto} );
$matched{$mailto} = 1;
my $xpect = $spec->{topicsout};
if ( $xpect eq '*' ) {
$xpect = join ' ', keys %expectedRevs;
}
foreach my $x ( split( /\s+/, $xpect ) ) {
$this->assert_matches( qr/^- $x \(.*\) $expectedRevs{$x}/m,
$message );
sub testSubweb {
my $this = shift;

#$this->assert_matches(qr/$finalText{$x}/m, $message);
$message =~ s/^- $x \(.*\n//m;
}
$this->assert_does_not_match( qr/^- \w+ \(/, $message );
last;
}
}
}
foreach my $spec (@specs) {
if ( $spec->{topicsout} ne "" ) {
$this->assert(
$matched{ $spec->{email} },
"Expected mails for "
. $spec->{email}
. " but only saw mails for "
. join( " ", keys %matched )
);
}
else {
$this->assert(
!$matched{ $spec->{email} },
"Didn't expect mails for "
. $spec->{email}
. "; got "
. join( " ", keys %matched )
);
}
}
my @webs = ( $subWeb, $this->{users_web} );
Foswiki::Contrib::MailerContrib::mailNotify( \@webs, 0, undef, 0, 0 );

#print "REPORT\n",join("\n\n", @FoswikiFnTestCase::mails);

$this->checkSpecs();
}

sub testCovers {
Expand Down

0 comments on commit a0745a3

Please sign in to comment.