import rt 3.8.8
[freeside.git] / rt / lib / t / regression / 23-batch-upload-csv.t
1 #!/usr/bin/perl -w
2 use strict; use warnings;
3
4 use Test::More qw/no_plan/;
5 use_ok('RT');
6 RT::LoadConfig();
7 RT::Init();
8 use_ok('RT::Action::CreateTickets');
9
10 my $QUEUE = 'uploadtest-'.$$;
11
12 my $queue_obj = RT::Queue->new($RT::SystemUser);
13 $queue_obj->Create(Name => $QUEUE);
14
15 my $cf = RT::CustomField->new($RT::SystemUser);
16 my ($val,$msg)  = $cf->Create(Name => 'Work Package-'.$$, Type => 'Freeform', LookupType => RT::Ticket->CustomFieldLookupType, MaxValues => 1);
17 ok($cf->id);
18 ok($val,$msg);
19 ($val, $msg) = $cf->AddToObject($queue_obj);
20 ok($val,$msg);
21 ok($queue_obj->TicketCustomFields()->Count, "We have a custom field, at least");
22
23
24 my $data = <<EOF;
25 id,Queue,Subject,Status,Requestor,@{[$cf->Name]}
26 create-1,$QUEUE,hi,new,root,2.0
27 create-2,$QUEUE,hello,new,root,3.0
28 EOF
29
30 my $action = RT::Action::CreateTickets->new(CurrentUser => RT::CurrentUser->new('root'));
31 ok ($action->CurrentUser->id , "WE have a current user");
32  
33 $action->Parse(Content => $data);
34 my @results = $action->CreateByTemplate();
35
36 my $tix = RT::Tickets->new($RT::SystemUser);
37 $tix->FromSQL ("Queue = '". $QUEUE."'");
38 $tix->OrderBy( FIELD => 'id', ORDER => 'ASC' );
39 ok($tix->Count);
40 my $first = $tix->First();
41 is($first->Subject(), 'hi'); 
42 is($first->FirstCustomFieldValue($cf->id), '2.0');
43
44 my $second = $tix->Next;
45 is($second->Subject(), 'hello'); 
46 is($second->FirstCustomFieldValue($cf->id), '3.0');
47 1;