fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / attachment_dropping.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
12 my $name = ( File::Spec->splitpath($path) )[2];
13
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' );
18
19 my $cf = RT::CustomField->new( RT->SystemUser );
20 ok(
21     $cf->Create(
22         Name  => 'test truncation',
23         Queue => '0',
24         Type  => 'FreeformSingle',
25     ),
26 );
27 my $cfid = $cf->id;
28
29 my ( $baseurl, $m ) = RT::Test->started_ok;
30 ok $m->login, 'logged in';
31
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' );
36
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 );
43 $m->submit;
44 is( $m->status, 200, "request successful" );
45
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' );
50
51 undef $m;
52 done_testing;