-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
use strict; | ||
use warnings; | ||
use Data::Dumper; | ||
use English qw(-no_match_vars); | ||
use File::Temp qw(); | ||
use Test::More; | ||
|
@@ -32,14 +33,18 @@ my $tempdir = File::Temp->newdir(CLEANUP => ($ENV{TEST_DEBUG} ? 0 : 1)); | |
|
||
queuesubscribe => $tempdir . '/auth', | ||
bounce_path => $tempdir . '/bounce', | ||
etc => $tempdir . '/etc', | ||
); | ||
mkdir $Conf::Conf{queuesubscribe}; | ||
mkdir $Conf::Conf{bounce_path}; | ||
mkdir $Conf::Conf{bounce_path} . '/' . $listname . '@' . $Conf::Conf{domain}; | ||
mkdir $Conf::Conf{etc}; | ||
mkdir $Conf::Conf{etc} . '/data_sources'; | ||
|
||
my $fake_list = bless { | ||
name => $listname, | ||
domain => $Conf::Conf{'domain'}, | ||
dir => $tempdir . '/list', | ||
admin => { | ||
available_user_options => {reception => [qw(mail digest)],}, | ||
default_user_options => { | ||
|
@@ -55,8 +60,17 @@ my $fake_list = bless { | |
reception => 'nomail', | ||
visibility => 'conceal', | ||
}, | ||
|
||
member_include => [{source => 'include_file',}], | ||
owner_include => [{source => 'include_file',}], | ||
editor_include => [{source => 'include_file',}], | ||
}, | ||
} => 'Sympa::List'; | ||
mkdir $tempdir . '/list'; | ||
open my $fh, '>', $Conf::Conf{etc} . '/data_sources/include_file.incl' | ||
or die $ERRNO; | ||
print $fh "include_file $tempdir/source\n"; | ||
close $fh; | ||
|
||
Sympa::Log->instance->{level} = -1; | ||
do { | ||
|
@@ -68,6 +82,8 @@ $SIG{__WARN__} = sub { | |
print STDERR @_ unless 0 == index $_[0], 'Use of uninitialized value'; | ||
}; | ||
|
||
my $sdm = Sympa::DatabaseManager->instance or die; | ||
|
||
# Now do testing | ||
|
||
my $member_none = '[email protected]'; | ||
|
@@ -202,6 +218,51 @@ do_test( | |
name => 'del moderators' | ||
); | ||
|
||
do_test_include( | ||
role => 'member', | ||
source => [$member1], | ||
data => [$member1], | ||
name => 'include subscriber', | ||
); | ||
sleep 2; | ||
do_test_include( | ||
role => 'member', | ||
source => [], | ||
data => [], | ||
name => 'include subscriber: emptied', | ||
); | ||
do_test_include( | ||
role => 'member', | ||
source => [$member1], | ||
data => [$member1], | ||
name => 'include subscriber', | ||
); | ||
do_test_include( | ||
role => 'owner', | ||
source => [[@{$owner1}[1, 2]]], | ||
data => [$owner1], | ||
name => 'include owner', | ||
); | ||
do_test_include( | ||
role => 'editor', | ||
source => [[@{$editor1}[1, 2]]], | ||
data => [$editor1, $owner1], | ||
name => 'include moderator', | ||
); | ||
sleep 2; | ||
do_test_include( | ||
role => 'owner', | ||
source => [], | ||
data => [$editor1], | ||
name => 'include owner: emptied', | ||
); | ||
do_test_include( | ||
role => 'editor', | ||
source => [], | ||
data => [], | ||
name => 'include moderator: emptied', | ||
); | ||
|
||
done_testing(); | ||
|
||
sub do_test { | ||
|
@@ -243,7 +304,69 @@ sub do_test { | |
|
||
return unless $options{data}; | ||
|
||
my $sdm = Sympa::DatabaseManager->instance or die; | ||
if ('member' eq $role) { | ||
is_deeply $sdm->do_prepared_query( | ||
q{SELECT user_subscriber, comment_subscriber, | ||
reception_subscriber, visibility_subscriber | ||
FROM subscriber_table | ||
ORDER BY user_subscriber} | ||
)->fetchall_arrayref, $options{data}, $options{name}; | ||
} else { | ||
is_deeply $sdm->do_prepared_query( | ||
q{SELECT role_admin, user_admin, comment_admin, | ||
profile_admin, reception_admin, visibility_admin | ||
FROM admin_table | ||
ORDER BY user_admin} | ||
)->fetchall_arrayref, $options{data}, $options{name}; | ||
} | ||
} | ||
|
||
sub do_test_include { | ||
my %options = @_; | ||
|
||
my $role = $options{role} or die 'no role specified'; | ||
|
||
open my $fh, '>', $tempdir . '/source' or die $ERRNO; | ||
foreach my $u (@{$options{source} // []}) { | ||
printf $fh "%s %s\n", $u->[0], $u->[1]; | ||
} | ||
close $fh; | ||
|
||
my @stash; | ||
my $spindle = Sympa::Spindle::ProcessRequest->new( | ||
context => $fake_list, | ||
action => 'include', | ||
role => $role, | ||
sender => $Conf::Conf{listmaster}, | ||
stash => \@stash, | ||
scenario_context => {skip => 1}, | ||
); | ||
die unless $spindle and $spindle->spin; | ||
|
||
if ($options{result}) { | ||
unless ( | ||
grep { | ||
my $s = $_; | ||
grep { $_->[0] eq $s->[1] and $_->[1] eq $s->[2] } | ||
@{$options{result}} | ||
} @stash | ||
) { | ||
fail $options{name}; | ||
diag 'No result ' . join "\n", | ||
map { sprintf '"%s" "%s"', @$_ } @{$options{result}}; | ||
diag join "\n", map { join ',', @$_ } @stash; | ||
} | ||
} elsif ( | ||
grep { | ||
$_->[1] ne 'notice' | ||
} @stash | ||
) { | ||
fail $options{name}; | ||
diag join "\n", map { join ',', @$_ } @stash; | ||
} | ||
|
||
return unless $options{data}; | ||
|
||
if ('member' eq $role) { | ||
is_deeply $sdm->do_prepared_query( | ||
q{SELECT user_subscriber, comment_subscriber, | ||
|