4 use RT::Test tests => undef;
5 use File::Temp 'tempfile';
7 my $content = 'a' x 1000 . 'b' x 10;
8 my ( $fh, $path ) = tempfile( UNLINK => 1, SUFFIX => '.txt' );
12 my $name = ( File::Spec->splitpath($path) )[2];
14 RT->Config->Set( 'WebSessionClass', "Apache::Session::File");
15 RT->Config->Set( 'MaxAttachmentSize', 1000 );
16 RT->Config->Set( 'TruncateLongAttachments', '0' );
17 RT->Config->Set( 'DropLongAttachments', '1' );
19 my $cf = RT::CustomField->new( RT->SystemUser );
22 Name => 'test truncation',
24 Type => 'FreeformSingle',
29 my ( $baseurl, $m ) = RT::Test->started_ok;
30 ok $m->login, 'logged in';
32 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
33 ok( $queue->id, "Loaded General queue" );
34 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=' . $queue->id );
35 $m->content_contains( "Create a new ticket", 'ticket create page' );
37 $m->form_name('TicketCreate');
38 $m->field( 'Subject', 'Attachments dropping test' );
39 $m->field( 'Attach', $path );
40 $m->field( 'Content', 'Some content' );
41 my $cf_content = 'cf' . 'a' x 998 . 'cfb';
42 $m->field( "Object-RT::Ticket--CustomField-$cfid-Value", $cf_content );
44 is( $m->status, 200, "request successful" );
46 $m->content_contains( "File '$name' dropped because its size (1010 bytes) exceeded configured maximum size setting (1000 bytes).", 'dropped message' );
47 $m->content_lacks( 'cfaaaa', 'cf value was dropped' );
48 $m->follow_link_ok( { text => "Download $name" } );
49 is( $m->content, 'Large attachment dropped', 'dropped $name' );