File: basic.t

package info (click to toggle)
request-tracker4 4.4.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 62,888 kB
  • sloc: javascript: 130,444; perl: 65,442; sh: 1,350; makefile: 480; python: 37; php: 30
file content (83 lines) | stat: -rw-r--r-- 3,281 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;

use RT::Test::ExternalStorage tests => undef;

my $queue = RT::Test->load_or_create_queue(Name => 'General');
ok $queue && $queue->id;

my $message = MIME::Entity->build(
    From    => 'root@localhost',
    Subject => 'test',
    Data    => 'test',
);
$message->attach(
    Type     => 'image/special',
    Filename => 'afile.special',
    Data     => 'boo',
);
$message->attach(
    Type     => 'application/octet-stream',
    Filename => 'otherfile.special',
    Data     => 'thing',
);
my $ticket = RT::Ticket->new( RT->SystemUser );
my ($id) = $ticket->Create(
    Queue => $queue,
    Subject => 'test',
    MIMEObj => $message,
);

ok $id, 'created a ticket';

my @attachs = @{ $ticket->Transactions->First->Attachments->ItemsArrayRef };
is scalar @attachs, 4, "Contains a multipart and two sub-parts";

is $attachs[0]->ContentType, "multipart/mixed", "Found the top multipart";
my ($ok, $msg) = $attachs[0]->ShouldStoreExternally;
ok !$ok, "Shouldn't store multipart part on disk";
like $msg, qr/attachment is multipart/, "Shouldn't store multipart part on disk";

is $attachs[1]->ContentType, "text/plain", "Found the text part";
is $attachs[1]->Content, 'test', "Can get the text part content";
is $attachs[1]->ContentEncoding, "none", "Content is not encoded";
($ok, $msg) = $attachs[1]->ShouldStoreExternally;
ok !$ok, "Won't store text part on disk";
like $msg, qr/text length.*does not exceed/, "Won't store text part on disk";

is $attachs[2]->ContentType, "image/special", "Found the image part";
is $attachs[2]->Content, 'boo',  "Can get the image content";
is $attachs[2]->ContentEncoding, "none", "Content is not encoded";
($ok, $msg) = $attachs[2]->ShouldStoreExternally;
ok !$ok, "Won't store images on disk";
like $msg, qr/image size.*does not exceed/, "Won't store images on disk";

is $attachs[3]->ContentType, "application/octet-stream", "Found the binary part";
is $attachs[3]->Content, 'thing',  "Can get the binary content";
is $attachs[3]->ContentEncoding, "none", "Content is not encoded";
($ok, $msg) = $attachs[3]->ShouldStoreExternally;
ok $ok, "Will store binary data on disk";

my $dir = RT::Test::ExternalStorage->attachments_dir;
ok !<$dir/*>, "Attachments directory is empty";


ok -e 'sbin/rt-externalize-attachments', "Found rt-externalize-attachments script";
ok -x 'sbin/rt-externalize-attachments', "rt-externalize-attachments is executable";
ok( RT::Test->run_singleton_command('sbin/rt-externalize-attachments'), "rt-externalize-attachments ran successfully" );

@attachs = @{ $ticket->Transactions->First->Attachments->ItemsArrayRef };
is $attachs[1]->Content, 'test', "Can still get the text part content";
is $attachs[1]->ContentEncoding, "none", "Content is not encoded";

is $attachs[2]->Content, 'boo',  "Can still get the image content";
is $attachs[2]->ContentEncoding, "none", "Content is not encoded";

is $attachs[3]->ContentType, "application/octet-stream", "Found the binary part";
is $attachs[3]->Content, 'thing',  "Can still get the binary content";
isnt $attachs[3]->__Value('Content'), "thing", "Content in database is not the raw content";
is $attachs[3]->ContentEncoding, "external", "Content encoding is 'external'";

ok <$dir/*>, "Attachments directory contains files";

done_testing();