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' );
11 my $name = ( File::Spec->splitpath($path) )[2];
13 RT->Config->Set( 'WebSessionClass', "Apache::Session::File");
14 RT->Config->Set( 'MaxAttachmentSize', 1000 );
15 RT->Config->Set( 'TruncateLongAttachments', '1' );
17 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
18 ok( $queue->id, "Loaded General queue" );
20 my $cf = RT::CustomField->new( RT->SystemUser );
23 Name => 'test truncation',
25 Type => 'FreeformSingle',
30 my ( $baseurl, $m ) = RT::Test->started_ok;
31 ok $m->login, 'logged in';
33 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=' . $queue->id );
34 $m->content_contains( "Create a new ticket", 'ticket create page' );
36 $m->form_name('TicketCreate');
37 $m->field( 'Subject', 'Attachments test' );
38 $m->field( 'Attach', $path );
39 $m->field( 'Content', 'Some content' );
40 my $cf_content = 'cf' . 'a' x 998 . 'cfb';
41 $m->field( "Object-RT::Ticket--CustomField-$cfid-Value", $cf_content );
43 is( $m->status, 200, "request successful" );
45 $m->content_contains( "File '$name' truncated because its size (1010 bytes) exceeded configured maximum size setting (1000 bytes).", 'truncated message' );
46 $m->content_contains( 'cf' . 'a' x 998, 'has the first 1000 cf chars' );
47 $m->content_lacks( 'aaacfb', 'lacks cf chars after that' );
48 $m->follow_link_ok( { text => "Download $name" } );
49 $m->content_contains( 'a' x 1000, 'has the first 1000 chars' );
50 $m->content_lacks( 'b', 'lacks chars after that' );