4 use RT::Test tests => undef;
7 my $ticket = RT::Test->create_ticket( Subject => 'test repeated values', Queue => 'General' );
11 diag "testing freeform single cf";
12 my $freeform_single = RT::Test->load_or_create_custom_field(
13 Name => 'freeform single',
14 Type => 'FreeformSingle',
19 $ticket->AddCustomFieldValue( Field => $freeform_single, Value => 'foo' );
21 is( $ticket->FirstCustomFieldValue($freeform_single), 'foo', 'value is foo' );
23 my $ocfv = $ticket->CustomFieldValues($freeform_single)->First;
25 $ticket->AddCustomFieldValue( Field => $freeform_single, Value => 'foo' );
26 is( $ret, $ocfv->id, "got the same previous object" );
27 is( $ticket->FirstCustomFieldValue($freeform_single), 'foo', 'value is still foo' );
30 $ticket->AddCustomFieldValue( Field => $freeform_single, Value => 'FOO' );
32 isnt( $ret, $ocfv->id, "got a new value" );
33 is( $ticket->FirstCustomFieldValue($freeform_single), 'FOO', 'value is FOO' );
37 diag "testing freeform multiple cf";
38 my $freeform_multiple = RT::Test->load_or_create_custom_field(
39 Name => 'freeform multiple',
40 Type => 'FreeformMultiple',
44 ($ret, $msg) = $ticket->AddCustomFieldValue( Field => $freeform_multiple, Value => 'foo' );
46 is( $ticket->FirstCustomFieldValue($freeform_multiple), 'foo', 'value is foo' );
48 my $ocfv = $ticket->CustomFieldValues($freeform_multiple)->First;
49 ($ret, $msg) = $ticket->AddCustomFieldValue( Field => $freeform_multiple, Value => 'foo' );
50 is($ret, $ocfv->id, "got the same previous object");
51 is( $ticket->FirstCustomFieldValue($freeform_multiple), 'foo', 'value is still foo' );
53 ($ret, $msg) = $ticket->AddCustomFieldValue( Field => $freeform_multiple, Value => 'bar' );
56 my $ocfvs = $ticket->CustomFieldValues($freeform_multiple)->ItemsArrayRef;
57 is( scalar @$ocfvs, 2, 'has 2 values');
58 is( $ocfvs->[0]->Content, 'foo', 'first is foo' );
59 is( $ocfvs->[1]->Content, 'bar', 'sencond is bar' );
63 diag "testing select single cf";
65 my $select_single = RT::Test->load_or_create_custom_field(
66 Name => 'select single',
67 Type => 'SelectSingle',
71 for my $value ( qw/foo bar baz/ ) {
72 $select_single->AddValue( Name => $value );
76 $ticket->AddCustomFieldValue( Field => $select_single, Value => 'foo' );
78 my $ocfv = $ticket->CustomFieldValues($select_single)->First;
79 is( $ticket->FirstCustomFieldValue($select_single), 'foo', 'value is foo' );
81 $ticket->AddCustomFieldValue( Field => $select_single, Value => 'foo' );
82 is( $ret, $ocfv->id, "got the same previous object" );
83 is( $ticket->FirstCustomFieldValue($select_single), 'foo', 'value is still foo' );
85 diag "select values are case insensitive";
88 $ticket->AddCustomFieldValue( Field => $select_single, Value => 'FOO' );
89 is( $ret, $ocfv->id, "got the same previous object" );
90 is( $ticket->FirstCustomFieldValue($select_single), 'foo', 'value is still foo' );
92 ($ret, $msg) = $ticket->AddCustomFieldValue( Field => $select_single, Value => 'bar' );
94 isnt( $ret, $ocfv->id, "got a new value" );
95 is( $ticket->FirstCustomFieldValue($select_single), 'bar', 'new value is bar' );
99 diag "testing binary single cf";
101 my $binary_single = RT::Test->load_or_create_custom_field(
102 Name => 'upload single',
103 Type => 'BinarySingle',
108 $ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo', LargeContent => 'bar' );
110 my $ocfv = $ticket->CustomFieldValues($binary_single)->First;
112 $ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo', LargeContent => 'bar' );
113 is( $ret, $ocfv->id, "got the same previous object" );
114 is($ocfv->Content, 'foo', 'name is foo');
115 is($ocfv->LargeContent, 'bar', 'content is bar');
118 $ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo', LargeContent => 'baz' );
120 isnt( $ret, $ocfv->id, "got a new value" );
121 $ocfv = $ticket->CustomFieldValues($binary_single)->First;
122 is($ocfv->Content, 'foo', 'name is foo');
123 is($ocfv->LargeContent, 'baz', 'content is baz');
126 $ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo.2', LargeContent => 'baz' );
128 isnt( $ret, $ocfv->id, "got a new value" );
129 $ocfv = $ticket->CustomFieldValues($binary_single)->First;
130 is($ocfv->Content, 'foo.2', 'name is foo.2');
131 is($ocfv->LargeContent, 'baz', 'content is baz');