1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
use warnings;
use strict;
use RT::Test tests => undef;
my $ticket = RT::Test->create_ticket( Subject => 'test repeated values', Queue => 'General' );
my ( $ret, $msg );
{
diag "testing freeform single cf";
my $freeform_single = RT::Test->load_or_create_custom_field(
Name => 'freeform single',
Type => 'FreeformSingle',
Queue => 0,
);
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $freeform_single, Value => 'foo' );
ok( $ret, $msg );
is( $ticket->FirstCustomFieldValue($freeform_single), 'foo', 'value is foo' );
my $ocfv = $ticket->CustomFieldValues($freeform_single)->First;
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $freeform_single, Value => 'foo' );
is( $ret, $ocfv->id, "got the same previous object" );
is( $ticket->FirstCustomFieldValue($freeform_single), 'foo', 'value is still foo' );
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $freeform_single, Value => 'FOO' );
ok( $ret, $msg );
isnt( $ret, $ocfv->id, "got a new value" );
is( $ticket->FirstCustomFieldValue($freeform_single), 'FOO', 'value is FOO' );
}
{
diag "testing freeform multiple cf";
my $freeform_multiple = RT::Test->load_or_create_custom_field(
Name => 'freeform multiple',
Type => 'FreeformMultiple',
Queue => 0,
);
($ret, $msg) = $ticket->AddCustomFieldValue( Field => $freeform_multiple, Value => 'foo' );
ok($ret, $msg);
is( $ticket->FirstCustomFieldValue($freeform_multiple), 'foo', 'value is foo' );
my $ocfv = $ticket->CustomFieldValues($freeform_multiple)->First;
($ret, $msg) = $ticket->AddCustomFieldValue( Field => $freeform_multiple, Value => 'foo' );
is($ret, $ocfv->id, "got the same previous object");
is( $ticket->FirstCustomFieldValue($freeform_multiple), 'foo', 'value is still foo' );
($ret, $msg) = $ticket->AddCustomFieldValue( Field => $freeform_multiple, Value => 'bar' );
ok($ret, $msg);
my $ocfvs = $ticket->CustomFieldValues($freeform_multiple)->ItemsArrayRef;
is( scalar @$ocfvs, 2, 'has 2 values');
is( $ocfvs->[0]->Content, 'foo', 'first is foo' );
is( $ocfvs->[1]->Content, 'bar', 'sencond is bar' );
}
{
diag "testing select single cf";
my $select_single = RT::Test->load_or_create_custom_field(
Name => 'select single',
Type => 'SelectSingle',
Queue => 0,
);
for my $value ( qw/foo bar baz/ ) {
$select_single->AddValue( Name => $value );
}
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $select_single, Value => 'foo' );
ok( $ret, $msg );
my $ocfv = $ticket->CustomFieldValues($select_single)->First;
is( $ticket->FirstCustomFieldValue($select_single), 'foo', 'value is foo' );
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $select_single, Value => 'foo' );
is( $ret, $ocfv->id, "got the same previous object" );
is( $ticket->FirstCustomFieldValue($select_single), 'foo', 'value is still foo' );
diag "select values are case insensitive";
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $select_single, Value => 'FOO' );
is( $ret, $ocfv->id, "got the same previous object" );
is( $ticket->FirstCustomFieldValue($select_single), 'foo', 'value is still foo' );
($ret, $msg) = $ticket->AddCustomFieldValue( Field => $select_single, Value => 'bar' );
ok($ret, $msg);
isnt( $ret, $ocfv->id, "got a new value" );
is( $ticket->FirstCustomFieldValue($select_single), 'bar', 'new value is bar' );
}
{
diag "testing binary single cf";
my $binary_single = RT::Test->load_or_create_custom_field(
Name => 'upload single',
Type => 'BinarySingle',
Queue => 0,
);
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo', LargeContent => 'bar' );
ok( $ret, $msg );
my $ocfv = $ticket->CustomFieldValues($binary_single)->First;
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo', LargeContent => 'bar' );
is( $ret, $ocfv->id, "got the same previous object" );
is($ocfv->Content, 'foo', 'name is foo');
is($ocfv->LargeContent, 'bar', 'content is bar');
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo', LargeContent => 'baz' );
ok( $ret, $msg );
isnt( $ret, $ocfv->id, "got a new value" );
$ocfv = $ticket->CustomFieldValues($binary_single)->First;
is($ocfv->Content, 'foo', 'name is foo');
is($ocfv->LargeContent, 'baz', 'content is baz');
( $ret, $msg ) =
$ticket->AddCustomFieldValue( Field => $binary_single, Value => 'foo.2', LargeContent => 'baz' );
ok( $ret, $msg );
isnt( $ret, $ocfv->id, "got a new value" );
$ocfv = $ticket->CustomFieldValues($binary_single)->First;
is($ocfv->Content, 'foo.2', 'name is foo.2');
is($ocfv->LargeContent, 'baz', 'content is baz');
}
done_testing();
|