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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
use strict;
use warnings;
use RT;
use RT::Test tests => undef;
use Test::Warn;
use_ok ('RT::Transaction');
{
my $u = RT::User->new(RT->SystemUser);
$u->Load("root");
ok ($u->Id, "Found the root user");
ok(my $t = RT::Ticket->new(RT->SystemUser));
my ($id, $msg) = $t->Create( Queue => 'General',
Subject => 'Testing',
Owner => $u->Id
);
ok($id, "Create new ticket $id");
isnt($id , 0);
my $txn = RT::Transaction->new(RT->SystemUser);
my ($txn_id, $txn_msg) = $txn->Create(
Type => 'AddLink',
Field => 'RefersTo',
Ticket => $id,
NewValue => 'ticket 42', );
ok( $txn_id, "Created transaction $txn_id: $txn_msg");
my $brief;
warning_like { $brief = $txn->BriefDescription }
qr/Could not determine a URI scheme/,
"Caught URI warning";
is( $brief, 'Reference to ticket 42 added', "Got string description: $brief");
$txn = RT::Transaction->new(RT->SystemUser);
($txn_id, $txn_msg) = $txn->Create(
Type => 'DeleteLink',
Field => 'RefersTo',
Ticket => $id,
OldValue => 'ticket 42', );
ok( $txn_id, "Created transaction $txn_id: $txn_msg");
warning_like { $brief = $txn->BriefDescription }
qr/Could not determine a URI scheme/,
"Caught URI warning";
is( $brief, 'Reference to ticket 42 deleted', "Got string description: $brief");
}
diag 'Test Content';
{
require MIME::Entity;
my $plain_file = File::Spec->catfile( RT::Test->temp_directory, 'attachment.txt' );
open my $plain_fh, '>', $plain_file or die $!;
print $plain_fh 'this is attachment';
close $plain_fh;
my @mime;
my $mime = MIME::Entity->build( Data => [ 'main body' ] );
push @mime, { object => $mime, expected => 'main body', description => 'no attachment' };
$mime = MIME::Entity->build( Type => 'multipart/mixed' );
$mime->attach(
Type => 'text/plain',
Data => [ 'main body' ],
);
$mime->attach(
Path => $plain_file,
Type => 'text/plain',
);
push @mime, { object => $mime, expected => 'main body', description => 'has an attachment' };
$mime = MIME::Entity->build( Type => 'multipart/mixed' );
$mime->attach(
Path => $plain_file,
Type => 'text/plain',
);
$mime->attach(
Type => 'text/plain',
Data => [ 'main body' ],
);
push @mime, { object => $mime, expected => 'main body', description => 'has an attachment as the first part' };
$mime = MIME::Entity->build( Type => 'multipart/mixed' );
$mime->attach(
Path => $plain_file,
Type => 'text/plain',
);
push @mime,
{ object => $mime, expected => 'This transaction appears to have no content', description => 'has an attachment but no main part' };
my $parser = MIME::Parser->new();
$parser->output_to_core(1);
$mime = $parser->parse_data( <<EOF );
Content-Type: multipart/mixed; boundary="=-=-="
--=-=-=
Content-Type: message/rfc822
Content-Disposition: inline
Content-Type: text/plain
Subject: test
main body
--=-=-=
EOF
push @mime, { object => $mime, expected => "main body", description => 'has an rfc822 message' };
$mime = $parser->parse_data( <<EOF );
Content-Type: multipart/mixed; boundary="=-=-="
--=-=-=
Content-Type: message/rfc822
Content-Disposition: attachment
Content-Type: text/plain
Subject: test
inner body of rfc822
--=-=-=
Content-Type: text/plain
Subject: test
main body
--=-=-=
EOF
push @mime,
{ object => $mime, expected => 'main body', description => 'has an attachment of rfc822 message and main part' };
for my $mime ( @mime ) {
my $ticket = RT::Ticket->new( RT->SystemUser );
my ( $id, $txn_id ) = $ticket->Create(
Queue => 'General',
Subject => 'Testing content',
MIMEObj => $mime->{object},
);
ok( $id, 'Created ticket' );
ok( $txn_id, 'Created transaction' );
my $txn = RT::Transaction->new( RT->SystemUser );
$txn->Load( $txn_id );
is( $txn->Content, $mime->{expected}, "Got expected content for MIME: $mime->{description}" );
}
}
done_testing;
|