6 use RT::Test tests => 41;
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' and '0' as values to the CF" if $ENV{'TEST_VERBOSE'};
36 foreach my $value(qw(qwe ASD 0)) {
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 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
49 ok $queue && $queue->id, 'loaded or created queue';
51 diag "apply the CF to General queue" if $ENV{'TEST_VERBOSE'};
53 $m->follow_link( text => 'Queues' );
54 $m->title_is(q/Admin queues/, 'admin-queues screen');
55 $m->follow_link( text => 'General' );
56 $m->title_is(q/Editing Configuration for queue General/, 'admin-queue: general');
57 $m->follow_link( text => 'Ticket Custom Fields' );
58 $m->title_is(q/Edit Custom Fields for General/, 'admin-queue: general cfid');
60 $m->form_name('EditCustomFields');
61 $m->tick( "AddCustomField" => $cfid );
62 $m->click('UpdateCFs');
64 $m->content_like( qr/Object created/, 'TCF added to the queue' );
68 diag "create a ticket using API with 'asd'(not 'ASD') as value of the CF"
69 if $ENV{'TEST_VERBOSE'};
71 my $ticket = RT::Ticket->new( $RT::SystemUser );
73 ($tid, $txnid, $msg) = $ticket->Create(
76 "CustomField-$cfid" => 'asd',
78 ok $tid, "created ticket";
79 diag $msg if $msg && $ENV{'TEST_VERBOSE'};
81 # we use lc as we really don't care about case
82 # so if later we'll add canonicalization of value
84 is lc $ticket->FirstCustomFieldValue( $cf_name ),
85 'asd', 'assigned value of the CF';
88 diag "check that values of the CF are case insensetive(asd vs. ASD)"
89 if $ENV{'TEST_VERBOSE'};
91 ok $m->goto_ticket( $tid ), "opened ticket's page";
92 $m->follow_link( text => 'Custom Fields' );
93 $m->title_like(qr/Modify ticket/i, 'modify ticket');
94 $m->content_like(qr/\Q$cf_name/, 'CF on the page');
96 my $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
97 is lc $value, 'asd', 'correct value is selected';
99 $m->content_unlike(qr/\Q$cf_name\E.*?changed/mi, 'field is not changed');
101 $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
102 is lc $value, 'asd', 'the same value is still selected';
104 my $ticket = RT::Ticket->new( $RT::SystemUser );
105 $ticket->Load( $tid );
106 ok $ticket->id, 'loaded the ticket';
107 is lc $ticket->FirstCustomFieldValue( $cf_name ),
108 'asd', 'value is still the same';
111 diag "check that 0 is ok value of the CF"
112 if $ENV{'TEST_VERBOSE'};
114 ok $m->goto_ticket( $tid ), "opened ticket's page";
115 $m->follow_link( text => 'Custom Fields' );
116 $m->title_like(qr/Modify ticket/i, 'modify ticket');
117 $m->content_like(qr/\Q$cf_name/, 'CF on the page');
119 my $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
120 is lc $value, 'asd', 'correct value is selected';
121 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => 0 );
123 $m->content_like(qr/\Q$cf_name\E.*?changed/mi, 'field is changed');
124 $m->content_unlike(qr/0 is no longer a value for custom field/mi, 'no bad message in results');
126 $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
127 is lc $value, '0', 'new value is selected';
129 my $ticket = RT::Ticket->new( $RT::SystemUser );
130 $ticket->Load( $tid );
131 ok $ticket->id, 'loaded the ticket';
132 is lc $ticket->FirstCustomFieldValue( $cf_name ),
133 '0', 'API returns correct value';
136 diag "check that we can set empty value when the current is 0"
137 if $ENV{'TEST_VERBOSE'};
139 ok $m->goto_ticket( $tid ), "opened ticket's page";
140 $m->follow_link( text => 'Custom Fields' );
141 $m->title_like(qr/Modify ticket/i, 'modify ticket');
142 $m->content_like(qr/\Q$cf_name/, 'CF on the page');
144 my $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
145 is lc $value, '0', 'correct value is selected';
146 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => '' );
148 $m->content_like(qr/0 is no longer a value for custom field/mi, '0 is no longer a value');
150 $value = $m->form_number(3)->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
151 is $value, '', '(no value) is selected';
153 my $ticket = RT::Ticket->new( $RT::SystemUser );
154 $ticket->Load( $tid );
155 ok $ticket->id, 'loaded the ticket';
156 is $ticket->FirstCustomFieldValue( $cf_name ),
157 undef, 'API returns correct value';