File: simple-simple.t

package info (click to toggle)
libemail-sender-perl 2.601-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: perl: 2,276; makefile: 2
file content (78 lines) | stat: -rw-r--r-- 1,684 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!perl
use strict;
use warnings;
use Test::More 'no_plan';

$ENV{EMAIL_SENDER_TRANSPORT} = 'Test';
use Email::Sender::Simple qw(sendmail);

my $email = <<'.';
From: V <number.5@gov.uk>
To: II <number.2@green.dome.il>
Subject: jolly good show

Wot, wot!

-- 
v
.

my $result = Email::Sender::Simple->send($email);

isa_ok($result, 'Email::Sender::Success');

my $env_transport = Email::Sender::Simple->default_transport;
my @deliveries = $env_transport->deliveries;

is(@deliveries, 1, "we sent one message");

is_deeply(
  $deliveries[0]->{envelope},
  {
    to   => [ 'number.2@green.dome.il' ],
    from => 'number.5@gov.uk',
  },
  "correct envelope deduced from message",
);

{
  my $new_test = Email::Sender::Transport::Test->new;
  my $result   = Email::Sender::Simple->send(
    $email,
    {
      to   => 'devnull@example.com',
      transport => $new_test
    },
  );

  is(
    $env_transport->delivery_count,
    2,
    "we ignore the passed transport when we're using transport-from-env",
  );

  is_deeply(
    ($env_transport->deliveries)[1]->{envelope},
    {
      to   => [ 'devnull@example.com' ],
      from => 'number.5@gov.uk',
    },
    "we stored the right message for the second delivery",
  );
}

{
  my $email = Email::Simple->new("Subject: foo\n\nbar\n");

  {
    my $result = eval { Email::Sender::Simple->send($email); };
    isa_ok($@, 'Email::Sender::Failure', "we throw on failure, obj");
    is($result, undef, "...meaning there is no return value");
  }

  {
    my $result = eval { Email::Sender::Simple->try_to_send($email) };
    ok(! $@, "no exception when we try_to_send and fail");
    ok(! $result, "...but we do get a false value");
  }
}