Courriel

 view release on metacpan or  search on metacpan

t/Builder.t  view on Meta::CPAN

use strict;
use warnings;

use Test::Differences;
use Test::Fatal;
use Test::More 0.88;
use Test::Warnings;

use Courriel::Builder;
use Courriel::Helpers;
use Email::Address::XS;
use List::AllUtils qw( all );
use Sys::Hostname qw( hostname );

{
    my $email = build_email(
        subject('Test Subject'),
        from('autarch@urth.org'),
        to(
            'autarch@urth.org', Email::Address::XS->parse('bob@example.com')
        ),
        cc(
            'jane@example.com', Email::Address::XS->parse('joe@example.com')
        ),
        header( 'X-Foo' => 42 ),
        header( 'X-Bar' => 84 ),
        plain_body('The body of the message')
    );

    isa_ok( $email, 'Courriel' );

    my %expect = (
        Subject        => 'Test Subject',
        From           => 'autarch@urth.org',
        To             => 'autarch@urth.org, bob@example.com',
        Cc             => 'jane@example.com, joe@example.com',
        'X-Foo'        => '42',
        'X-Bar'        => 84,
        'Content-Type' => 'text/plain; charset=UTF-8',
        'MIME-Version' => '1.0',
    );

    for my $key ( sort keys %expect ) {
        is_deeply(
            [ map { $_->value } $email->headers->get($key) ],
            [ $expect{$key} ],
            "got expected value for $key header"
        );
    }

    my @date = $email->headers->get('Date');
    is( scalar @date, 1, 'found one Date header' );
    like(
        $date[0]->value,
        qr/\w\w\w, +\d{1,2} \w\w\w \d\d\d\d \d\d:\d\d:\d\d [-+]\d\d\d\d/,
        'Date header looks like a proper date'
    );

    my @id = $email->headers->get('Message-Id');
    is( scalar @id, 1, 'found one Message-Id header' );
    like(
        $id[0]->value,
        qr/<[^>]+>/,
        'Message-Id is in brackets'



( run in 0.727 second using v1.01-cache-2.11-cpan-6aa56a78535 )