1Test::Email(3) User Contributed Perl Documentation Test::Email(3)
2
3
4
6 Test::Email - Test Email Contents
7
9 use Test::Email;
10
11 # is-a MIME::Entity
12 my $email = Test::Email->new(\@lines);
13
14 # all-in-one test
15 $email->ok({
16 # optional search parameters
17 from => ($is or qr/$regex/),
18 subject => ($is or qr/$regex/),
19 body => ($is or qr/$regex/),
20 headername => ($is or qr/$regex/),
21 }, "passed tests");
22
23 # single-test header methods
24 $email->header_is($header_name, $value, "$header_name matches");
25 $email->header_ok($header_name, $value, "$header_name matches");
26 $email->header_like($header_name, qr/regex/, "$header_name matches");
27
28 # single-test body methods
29 $email->body_is($header_name, $value, "$header_name matches");
30 $email->body_ok($header_name, $value, "$header_name matches");
31 $email->body_like($header_name, qr/regex/, "$header_name matches");
32
33 # how many MIME parts does the messages contain?
34 $email->parts_ok($parts_count, "there were $parts_count parts found");
35
36 # what is the MIME type of the firs part
37 my @parts = $email->parts(); # see MIME::Entity
38 $parts[0]->mime_type_ok('test/html', 'the first part is type text/html');
39
41 Please note that this is ALPHA CODE. As such, the interface is likely
42 to change.
43
44 Test::Email is a subclass of MIME::Entity, with the above methods. If
45 you want the messages fetched from a POP3 account, use Test::POP3.
46
47 Tests for equality remove trailing newlines from strings before
48 testing. This is because some mail messages have newlines appended to
49 them during the mailing process, which could cause unnecessary
50 confusion.
51
52 This module should be 100% self-explanatory. If not, then please look
53 at Test::Simple and Test::More for clarification.
54
56 "my $email = Test::Email->new($lines_aref);"
57 This is identical to "MIME::Entity->new()". See there for details.
58
59 "$email->ok($test_href, $description);"
60 Using this method, you can test multiple qualities of an email
61 message with one test. This will execute the tests as expected and
62 will produce output just like "Test::Simple::ok" and
63 "Test::More::ok". Keys for $test_href are either "body", or they
64 are considered to be the name of a header, case-insensitive.
65
66 single-test methods
67 The single-test methods in the synopsis above are very similar to
68 their counterparts in Test::Simple and Test::More. Please consult
69 those modules for documentation.
70
71 Please note that tests for equality remove newlines from their
72 operands before testing. This is because some email messages have
73 newlines appended to them during mailing.
74
75 "my $ok = $email-"parts_ok($parts_count, $description);>
76 Check to see how many MIME parts this email contains. Each part is
77 also a Test::Email object.
78
79 "my $ok = $email-"mime_type_ok($expected_mime_type, $description);>
80 Check the MIME type of an email or an email part.
81
83 None.
84
86 Test::Builder, Test::Simple, Test::More, Test::POP3
87
89 I am open to suggestions.
90
92 James Tolley, <james@cpan.org>
93
95 Copyright (C) 2007-2008 by James Tolley
96
97 This library is free software; you can redistribute it and/or modify it
98 under the same terms as Perl itself, either Perl version 5.8.8 or, at
99 your option, any later version of Perl 5 you may have available.
100
101
102
103perl v5.36.0 2022-07-22 Test::Email(3)