diff options
author | dakkar <dakkar@thenautilus.net> | 2016-06-17 18:06:36 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2016-06-17 18:06:36 +0100 |
commit | 8399a72d9b3561616e79d8d389a32cbc022b96fe (patch) | |
tree | c90e01f0011929665d30615630bf2a50eb0bf8b3 /t/lib/Test | |
parent | 'bag' is in Test2::Suite 0.000032! (diff) | |
download | Sietima-8399a72d9b3561616e79d8d389a32cbc022b96fe.tar.gz Sietima-8399a72d9b3561616e79d8d389a32cbc022b96fe.tar.bz2 Sietima-8399a72d9b3561616e79d8d389a32cbc022b96fe.zip |
role: moderate mail from non-subscribers
Diffstat (limited to 't/lib/Test')
-rw-r--r-- | t/lib/Test/Sietima.pm | 3 | ||||
-rw-r--r-- | t/lib/Test/Sietima/MailStore.pm | 56 |
2 files changed, 59 insertions, 0 deletions
diff --git a/t/lib/Test/Sietima.pm b/t/lib/Test/Sietima.pm index 0b80e42..0661786 100644 --- a/t/lib/Test/Sietima.pm +++ b/t/lib/Test/Sietima.pm @@ -16,6 +16,8 @@ sub import { my $target = caller; Test2::Bundle::Extended->import::into($target); Test2::Plugin::DieOnFail->import::into($target); + Data::Printer->import::into($target); + for my $function (qw(transport make_sietima make_mail deliveries_are test_sending)) { no strict 'refs'; @@ -52,6 +54,7 @@ sub make_mail { Email::Stuffer ->from($args{from}||'someone@users.example.com') ->to($args{to}||$return_path) + ->subject($args{subject}||'Test Message') ->text_body($args{body}||'some simple message') ->email; } diff --git a/t/lib/Test/Sietima/MailStore.pm b/t/lib/Test/Sietima/MailStore.pm new file mode 100644 index 0000000..abf4435 --- /dev/null +++ b/t/lib/Test/Sietima/MailStore.pm @@ -0,0 +1,56 @@ +package Test::Sietima::MailStore; +use strict; +use warnings; +use 5.020; +use Moo; +use List::AllUtils qw(all); +use namespace::clean; + +with 'Sietima::MailStore'; + +has _mails => ( + is => 'rw', + default => sub { +[] }, +); + +sub clear { shift->_mails([]) } + +sub store { + my ($self,$mail,@tags) = @_; + + my $id = time(); + push @{$self->_mails}, { + id => $id, + mail => $mail->as_string, + tags => { map {$_ => 1;} @tags, }, + }; + return $id; +} + +sub retrieve_by_tags { + my ($self,@tags) = @_; + + my @ret; + for my $m (@{$self->_mails}) { + next unless all { $m->{tags}{$_} } @tags; + push @ret, { + %{$m}{id}, + mail => Email::MIME->new($m->{mail}) + }; + } + + return \@ret; +} + +sub retrieve_by_id { + my ($self,$id) = @_; + + for my $m (@{$self->_mails}) { + next unless $m->{id} eq $id; + return Email::MIME->new($m->{mail}); + } + + return; +} + +1; |