Debian Codegraph @

t/.svn/text-base/04_body.t.svn-base

raw
1 #!perl
2 use strict;
3 use warnings FATAL => 'all';
4
5 use Data::Dumper;
6 use Mail::Sendmail;
7 use Test::More tests => 9;
8 BEGIN { use_ok('Test::POP3') };
9
10 #########################
11
12 my $pc = 1;
13 my ($host, $user, $pass, $smtp, $email) = get_info();
14
15 # don't surprise/confuse the user
16 # we expect to fail some of these
17 $Test::Email::QUIET_DIAG = 1;
18
19 SKIP: {
20 skip 'No POP3 settings found', 9 unless $host;
21 my $test = Test::POP3->new({
22 host => $host,
23 user => $user,
24 pass => $pass,
25 });
26
27 # no tmpfiles
28 my $parser = $test->get_parser();
29 $parser->output_to_core(1);
30
31 # no messages
32 $test->delete_all();
33 my $msg_count = $test->get_email_count(1);
34 is($msg_count, 0, 'no messages');
35
36 # send 3 messages
37 sendmail(
38 to => $email,
39 from => $email,
40 subject => 'test 1',
41 message => 'message 1',
42 smtp => $smtp,
43 );
44 sleep 1;
45 sendmail(
46 to => $email,
47 from => $email,
48 subject => 'test 2',
49 message => 'message 2',
50 smtp => $smtp,
51 );
52 sleep 1;
53 sendmail(
54 to => $email,
55 from => $email,
56 subject => 'test 3',
57 message => 'message 3',
58 smtp => $smtp,
59 );
60
61 # then wait for them
62 is($test->wait_for_email_count(3), 3, 'found 3 messages');
63
64 # fail a single test
65 ok(!$test->_run_tests({
66 body => qr/4/,
67 }, 'should not see this'), 'one wrong arg fails');
68
69 # fail part of a multiple test
70 ok(!$test->_run_tests({
71 body => qr/5/,
72 subject => 'test 1',
73 }, 'should not see this'), 'some wrong args fail');
74
75 $test->ok({
76 body => qr/2/,
77 }, 'body regexp');
78
79 $test->ok({
80 body => 'message 3',
81 }, 'body string');
82
83 $test->ok({
84 body => qr/1/,
85 subject => 'test 1',
86 }, 'body and subject');
87
88 is($test->delete_all(), 0, 'no others to be deleted');
89 };
90
91 sub get_info {
92 return map $ENV{"TEST_POP3_$_"}, map uc, qw(host user pass smtp email);
93 }
94
95 __END__
96