first pass RT4 merge, RT#13852
[freeside.git] / rt / t / api / customfield.t
1
2 use strict;
3 use warnings;
4 use RT;
5 use RT::Test nodata => 1, tests => 29;
6 use Test::Warn;
7
8
9 {
10
11 use_ok('RT::CustomField');
12 ok(my $cf = RT::CustomField->new(RT->SystemUser));
13 ok(my ($id, $msg)=  $cf->Create( Name => 'TestingCF',
14                                  Queue => '0',
15                                  SortOrder => '1',
16                                  Description => 'A Testing custom field',
17                                  Type=> 'SelectSingle'), 'Created a global CustomField');
18 isnt($id , 0, 'Global custom field correctly created');
19 ok ($cf->SingleValue);
20 is($cf->Type, 'Select');
21 is($cf->MaxValues, 1);
22
23 (my $val, $msg) = $cf->SetMaxValues('0');
24 ok($val, $msg);
25 is($cf->Type, 'Select');
26 is($cf->MaxValues, 0);
27 ok(!$cf->SingleValue );
28 ok(my ($bogus_val, $bogus_msg) = $cf->SetType('BogusType') , "Trying to set a custom field's type to a bogus type");
29 is($bogus_val , 0, "Unable to set a custom field's type to a bogus type");
30
31 ok(my $bad_cf = RT::CustomField->new(RT->SystemUser));
32 ok(my ($bad_id, $bad_msg)=  $cf->Create( Name => 'TestingCF-bad',
33                                  Queue => '0',
34                                  SortOrder => '1',
35                                  Description => 'A Testing custom field with a bogus Type',
36                                  Type=> 'SelectSingleton'), 'Created a global CustomField with a bogus type');
37 is($bad_id , 0, 'Global custom field correctly decided to not create a cf with a bogus type ');
38
39
40 }
41
42 {
43
44 ok(my $cf = RT::CustomField->new(RT->SystemUser));
45 $cf->Load(1);
46 is($cf->Id , 1);
47 ok(my ($val,$msg)  = $cf->AddValue(Name => 'foo' , Description => 'TestCFValue', SortOrder => '6'));
48 isnt($val , 0);
49 ok (my ($delval, $delmsg) = $cf->DeleteValue($val));
50 ok ($delval,"Deleting a cf value: $delmsg");
51
52
53 }
54
55 {
56
57 ok(my $cf = RT::CustomField->new(RT->SystemUser));
58
59 warning_like {
60 ok($cf->ValidateType('SelectSingle'));
61 } qr/deprecated/;
62
63 warning_like {
64 ok($cf->ValidateType('SelectMultiple'));
65 } qr/deprecated/;
66
67 warning_like {
68 ok(!$cf->ValidateType('SelectFooMultiple'));
69 } qr/deprecated/;
70
71
72 }
73