5 use RT::Test tests => 45;
7 my ($baseurl, $m) = RT::Test->started_ok;
8 ok $m->login, 'logged in as root';
10 my $cf_name = 'test select one value';
15 $m->follow_link( id => 'tools-config-custom-fields-create');
17 form_name => "ModifyCustomField",
20 TypeComposite => 'Select-1',
21 LookupType => 'RT::Queue-RT::Ticket',
24 $m->content_contains('Object created', 'created CF sucessfully' );
25 $cfid = $m->form_name('ModifyCustomField')->value('id');
26 ok $cfid, "found id of the CF in the form, it's #$cfid";
29 diag "add 'qwe', 'ASD', '0' and ' foo ' as values to the CF";
31 foreach my $value(qw(qwe ASD 0), 'foo ') {
33 form_name => "ModifyCustomField",
35 "CustomField-". $cfid ."-Value-new-Name" => $value,
39 $m->content_contains('Object created', 'added a value to the CF' ); # or diag $m->content;
43 $m->content_contains("value=\"$v\"", 'the added value is right' );
47 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
48 ok $queue && $queue->id, 'loaded or created queue';
50 diag "apply the CF to General queue";
52 $m->follow_link( id => 'tools-config-queues');
53 $m->follow_link( text => 'General' );
54 $m->title_is(q/Configuration for queue General/, 'admin-queue: general');
55 $m->follow_link( id => 'page-ticket-custom-fields');
56 $m->title_is(q/Custom Fields for queue General/, 'admin-queue: general cfid');
58 $m->form_name('EditCustomFields');
59 $m->tick( "AddCustomField" => $cfid );
60 $m->click('UpdateCFs');
62 $m->content_contains('Object created', 'TCF added to the queue' );
66 diag "create a ticket using API with 'asd'(not 'ASD') as value of the CF";
68 my $ticket = RT::Ticket->new( RT->SystemUser );
70 ($tid, $txnid, $msg) = $ticket->Create(
73 "CustomField-$cfid" => 'asd',
75 ok $tid, "created ticket";
78 # we use lc as we really don't care about case
79 # so if later we'll add canonicalization of value
81 is lc $ticket->FirstCustomFieldValue( $cf_name ),
82 'asd', 'assigned value of the CF';
85 diag "check that values of the CF are case insensetive(asd vs. ASD)";
87 ok $m->goto_ticket( $tid ), "opened ticket's page";
88 $m->follow_link( id => 'page-basics');
89 $m->title_like(qr/Modify ticket/i, 'modify ticket');
90 $m->content_contains($cf_name, 'CF on the page');
92 my $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
93 is lc $value, 'asd', 'correct value is selected';
95 $m->content_unlike(qr/\Q$cf_name\E.*?changed/mi, 'field is not changed');
97 $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
98 is lc $value, 'asd', 'the same value is still selected';
100 my $ticket = RT::Ticket->new( RT->SystemUser );
101 $ticket->Load( $tid );
102 ok $ticket->id, 'loaded the ticket';
103 is lc $ticket->FirstCustomFieldValue( $cf_name ),
104 'asd', 'value is still the same';
107 diag "check that 0 is ok value of the CF";
109 ok $m->goto_ticket( $tid ), "opened ticket's page";
110 $m->follow_link( id => 'page-basics');
111 $m->title_like(qr/Modify ticket/i, 'modify ticket');
112 $m->content_contains($cf_name, 'CF on the page');
114 my $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
115 is lc $value, 'asd', 'correct value is selected';
116 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => 0 );
118 $m->content_like(qr/\Q$cf_name\E.*?changed/mi, 'field is changed');
119 $m->content_lacks('0 is no longer a value for custom field', 'no bad message in results');
121 $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
122 is lc $value, '0', 'new value is selected';
124 my $ticket = RT::Ticket->new( RT->SystemUser );
125 $ticket->Load( $tid );
126 ok $ticket->id, 'loaded the ticket';
127 is lc $ticket->FirstCustomFieldValue( $cf_name ),
128 '0', 'API returns correct value';
131 diag "check that we can set empty value when the current is 0";
133 ok $m->goto_ticket( $tid ), "opened ticket's page";
134 $m->follow_link( id => 'page-basics');
135 $m->title_like(qr/Modify ticket/i, 'modify ticket');
136 $m->content_contains($cf_name, 'CF on the page');
138 my $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
139 is lc $value, '0', 'correct value is selected';
140 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => '' );
142 $m->content_contains('0 is no longer a value for custom field', '0 is no longer a value');
144 $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
145 is $value, '', '(no value) is selected';
147 my $ticket = RT::Ticket->new( RT->SystemUser );
148 $ticket->Load( $tid );
149 ok $ticket->id, 'loaded the ticket';
150 is $ticket->FirstCustomFieldValue( $cf_name ),
151 undef, 'API returns correct value';