6 use RT::Test tests => 46;
8 my ($baseurl, $m) = RT::Test->started_ok;
9 ok $m->login, 'logged in as root';
11 my $cf_name = 'test select one value';
14 diag "Create a CF" if $ENV{'TEST_VERBOSE'};
16 $m->follow_link( text => 'Configuration' );
17 $m->title_is(q/RT Administration/, 'admin screen');
18 $m->follow_link( text => 'Custom Fields' );
19 $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
20 $m->follow_link( text => 'Create' );
22 form_name => "ModifyCustomField",
25 TypeComposite => 'Select-1',
26 LookupType => 'RT::Queue-RT::Ticket',
29 $m->content_like( qr/Object created/, 'created CF sucessfully' );
30 $cfid = $m->form_name('ModifyCustomField')->value('id');
31 ok $cfid, "found id of the CF in the form, it's #$cfid";
34 diag "add 'qwe', 'ASD', '0' and ' foo ' as values to the CF" if $ENV{'TEST_VERBOSE'};
36 foreach my $value(qw(qwe ASD 0), 'foo ') {
38 form_name => "ModifyCustomField",
40 "CustomField-". $cfid ."-Value-new-Name" => $value,
44 $m->content_like( qr/Object created/, 'added a value to the CF' ); # or diag $m->content;
48 $m->content_like( qr/value="$v"/, 'the added value is right' );
52 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
53 ok $queue && $queue->id, 'loaded or created queue';
55 diag "apply the CF to General queue" if $ENV{'TEST_VERBOSE'};
57 $m->follow_link( text => 'Queues' );
58 $m->title_is(q/Admin queues/, 'admin-queues screen');
59 $m->follow_link( text => 'General' );
60 $m->title_is(q/Editing Configuration for queue General/, 'admin-queue: general');
61 $m->follow_link( text => 'Ticket Custom Fields' );
62 $m->title_is(q/Edit Custom Fields for General/, 'admin-queue: general cfid');
64 $m->form_name('EditCustomFields');
65 $m->tick( "AddCustomField" => $cfid );
66 $m->click('UpdateCFs');
68 $m->content_like( qr/Object created/, 'TCF added to the queue' );
72 diag "create a ticket using API with 'asd'(not 'ASD') as value of the CF"
73 if $ENV{'TEST_VERBOSE'};
75 my $ticket = RT::Ticket->new( $RT::SystemUser );
77 ($tid, $txnid, $msg) = $ticket->Create(
80 "CustomField-$cfid" => 'asd',
82 ok $tid, "created ticket";
83 diag $msg if $msg && $ENV{'TEST_VERBOSE'};
85 # we use lc as we really don't care about case
86 # so if later we'll add canonicalization of value
88 is lc $ticket->FirstCustomFieldValue( $cf_name ),
89 'asd', 'assigned value of the CF';
92 diag "check that values of the CF are case insensetive(asd vs. ASD)"
93 if $ENV{'TEST_VERBOSE'};
95 ok $m->goto_ticket( $tid ), "opened ticket's page";
96 $m->follow_link( text => 'Custom Fields' );
97 $m->title_like(qr/Modify ticket/i, 'modify ticket');
98 $m->content_like(qr/\Q$cf_name/, 'CF on the page');
100 my $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
101 is lc $value, 'asd', 'correct value is selected';
103 $m->content_unlike(qr/\Q$cf_name\E.*?changed/mi, 'field is not changed');
105 $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
106 is lc $value, 'asd', 'the same value is still selected';
108 my $ticket = RT::Ticket->new( $RT::SystemUser );
109 $ticket->Load( $tid );
110 ok $ticket->id, 'loaded the ticket';
111 is lc $ticket->FirstCustomFieldValue( $cf_name ),
112 'asd', 'value is still the same';
115 diag "check that 0 is ok value of the CF"
116 if $ENV{'TEST_VERBOSE'};
118 ok $m->goto_ticket( $tid ), "opened ticket's page";
119 $m->follow_link( text => 'Custom Fields' );
120 $m->title_like(qr/Modify ticket/i, 'modify ticket');
121 $m->content_like(qr/\Q$cf_name/, 'CF on the page');
123 my $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
124 is lc $value, 'asd', 'correct value is selected';
125 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => 0 );
127 $m->content_like(qr/\Q$cf_name\E.*?changed/mi, 'field is changed');
128 $m->content_unlike(qr/0 is no longer a value for custom field/mi, 'no bad message in results');
130 $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
131 is lc $value, '0', 'new value is selected';
133 my $ticket = RT::Ticket->new( $RT::SystemUser );
134 $ticket->Load( $tid );
135 ok $ticket->id, 'loaded the ticket';
136 is lc $ticket->FirstCustomFieldValue( $cf_name ),
137 '0', 'API returns correct value';
140 diag "check that we can set empty value when the current is 0"
141 if $ENV{'TEST_VERBOSE'};
143 ok $m->goto_ticket( $tid ), "opened ticket's page";
144 $m->follow_link( text => 'Custom Fields' );
145 $m->title_like(qr/Modify ticket/i, 'modify ticket');
146 $m->content_like(qr/\Q$cf_name/, 'CF on the page');
148 my $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
149 is lc $value, '0', 'correct value is selected';
150 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => '' );
152 $m->content_like(qr/0 is no longer a value for custom field/mi, '0 is no longer a value');
154 $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
155 is $value, '', '(no value) is selected';
157 my $ticket = RT::Ticket->new( $RT::SystemUser );
158 $ticket->Load( $tid );
159 ok $ticket->id, 'loaded the ticket';
160 is $ticket->FirstCustomFieldValue( $cf_name ),
161 undef, 'API returns correct value';