import rt 3.8.8
[freeside.git] / rt / lib / t / regression / 16-transaction_cf_tests.t
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use Data::Dumper;
6 use Test::More qw/no_plan/;
7
8 use_ok('RT');
9 use_ok('RT::Transactions');
10 RT::LoadConfig();
11 RT::Init();
12
13 my $q = RT::Queue->new($RT::SystemUser);
14 my ($id,$msg) = $q->Create( Name => 'TxnCFTest'.$$);
15 ok($id,$msg);
16
17 my $cf = RT::CustomField->new($RT::SystemUser);
18 ($id,$msg) = $cf->Create(Name => 'Txnfreeform-'.$$, Type => 'Freeform', MaxValues => '0', LookupType => RT::Transaction->CustomFieldLookupType );
19
20 ok($id,$msg);
21
22 ($id,$msg) = $cf->AddToObject($q);
23
24 ok($id,$msg);
25
26
27 my $ticket = RT::Ticket->new($RT::SystemUser);
28
29 my $transid;
30 ($id,$transid, $msg) = $ticket->Create(Queue => $q->id,
31                 Subject => 'TxnCF test',
32             );
33 ok($id,$msg);
34
35 my $trans = RT::Transaction->new($RT::SystemUser);
36 $trans->Load($transid);
37
38 is($trans->ObjectId,$id);
39 is ($trans->ObjectType, 'RT::Ticket');
40 is ($trans->Type, 'Create');
41 my $txncfs = $trans->CustomFields;
42 is ($txncfs->Count, 1, "We have one custom field");
43 my $txn_cf = $txncfs->First;
44 is ($txn_cf->id, $cf->id, "It's the right custom field");
45 my $values = $trans->CustomFieldValues($txn_cf->id);
46 is ($values->Count, 0, "It has no values");
47
48 # Old API
49 my %cf_updates = ( 'CustomField-'.$cf->id => 'Testing');
50 $trans->UpdateCustomFields( ARGSRef => \%cf_updates);
51
52  $values = $trans->CustomFieldValues($txn_cf->id);
53 is ($values->Count, 1, "It has one value");
54
55 # New API
56
57 $trans->UpdateCustomFields( 'CustomField-'.$cf->id => 'Test two');
58  $values = $trans->CustomFieldValues($txn_cf->id);
59 is ($values->Count, 2, "it has two values");
60
61 # TODO ok(0, "Should updating custom field values remove old values?");