fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / attachment_truncation.t
1 use warnings;
2 use strict;
3
4 use RT::Test tests => undef;
5 use File::Temp 'tempfile';
6
7 my $content = 'a' x 1000 . 'b' x 10;
8 my ( $fh, $path ) = tempfile( UNLINK => 1, SUFFIX => '.txt' );
9 print $fh $content;
10 close $fh;
11 my $name = ( File::Spec->splitpath($path) )[2];
12
13 RT->Config->Set( 'WebSessionClass', "Apache::Session::File");
14 RT->Config->Set( 'MaxAttachmentSize', 1000 );
15 RT->Config->Set( 'TruncateLongAttachments', '1' );
16
17 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
18 ok( $queue->id, "Loaded General queue" );
19
20 my $cf = RT::CustomField->new( RT->SystemUser );
21 ok(
22     $cf->Create(
23         Name  => 'test truncation',
24         Queue => '0',
25         Type  => 'FreeformSingle',
26     ),
27 );
28 my $cfid = $cf->id;
29
30 my ( $baseurl, $m ) = RT::Test->started_ok;
31 ok $m->login, 'logged in';
32
33 $m->get_ok( $baseurl . '/Ticket/Create.html?Queue=' . $queue->id );
34 $m->content_contains( "Create a new ticket", 'ticket create page' );
35
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 );
42 $m->submit;
43 is( $m->status, 200, "request successful" );
44
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' );
51
52 undef $m;
53 done_testing;