File: 03_headers.t

package info (click to toggle)
libtest-email-perl 0.07-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 224 kB
  • sloc: perl: 696; makefile: 2
file content (84 lines) | stat: -rwxr-xr-x 1,927 bytes parent folder | download | duplicates (2)
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
79
80
81
82
83
84
#!perl
use strict;
use warnings FATAL => 'all';

use Data::Dumper;
use Mail::Sendmail;
use Test::More tests => 7;
BEGIN { use_ok('Test::POP3') };

#########################

my ($host, $user, $pass, $smtp, $email) = get_info();

# don't surprise/confuse the user
# we expect to fail some of these
$Test::Email::QUIET_DIAG = 1;

SKIP: {
    skip 'No POP3 settings found', 6 unless $host;
    my $pop3 = Test::POP3->new({
        host    =>  $host,
        user    =>  $user,
        pass    =>  $pass,
    });
    
    # no tmpfiles
    my $parser = $pop3->get_parser();
    $parser->output_to_core(1);
    
    # no messages
    $pop3->delete_all();
    my $msg_count = $pop3->get_email_count(1);
    is($msg_count, 0, 'no messages');
    
    # send 3 messages
    sendmail(
        to      =>  $email,
        from    =>  $email,
        subject =>  'test 1',
        message =>  'message 1',
        smtp    =>  $smtp,
    );
    sleep 1;
    sendmail(
        to      =>  $email,
        from    =>  $email,
        subject =>  'test 2',
        message =>  'message 2',
        smtp    =>  $smtp,
    );
    sleep 1;
    sendmail(
        to      =>  $email,
        from    =>  $email,
        subject =>  'test 3',
        message =>  'message 3',
        smtp    =>  $smtp,
    );
    
    # then wait for them
    is($pop3->wait_for_email_count(3), 3, 'found 3 messages');
    
    $pop3->ok({
        subject => qr/ 1$/,
    }, 'subject regexp');
    
    $pop3->ok({
        subject => 'test 2',
    }, 'subject string');
    
    $pop3->ok({
        subject         =>  'test 3',
        'content-type'  =>  qr|text/plain|,
    }, 'subject and content-type');
    
    is($pop3->delete_all(), 0, 'no others to be deleted');
};

sub get_info {
    return map $ENV{"TEST_POP3_$_"}, map uc, qw(host user pass smtp email);
}

__END__