6 use RT::Test tests => 45;
8 my ($baseurl, $m) = RT::Test->started_ok;
9 ok $m->login, 'logged in as root';
11 my $cf_name = 'test select one value';
16 $m->follow_link( id => 'tools-config-custom-fields-create');
18 form_name => "ModifyCustomField",
21 TypeComposite => 'Select-1',
22 LookupType => 'RT::Queue-RT::Ticket',
25 $m->content_contains('Object created', 'created CF sucessfully' );
26 $cfid = $m->form_name('ModifyCustomField')->value('id');
27 ok $cfid, "found id of the CF in the form, it's #$cfid";
30 diag "add 'qwe', 'ASD', '0' and ' foo ' as values to the CF";
32 foreach my $value(qw(qwe ASD 0), 'foo ') {
34 form_name => "ModifyCustomField",
36 "CustomField-". $cfid ."-Value-new-Name" => $value,
40 $m->content_contains('Object created', 'added a value to the CF' ); # or diag $m->content;
44 $m->content_contains("value=\"$v\"", 'the added value is right' );
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";
53 $m->follow_link( id => 'tools-config-queues');
54 $m->follow_link( text => 'General' );
55 $m->title_is(q/Configuration for queue General/, 'admin-queue: general');
56 $m->follow_link( id => 'page-ticket-custom-fields');
57 $m->title_is(q/Custom Fields for queue General/, 'admin-queue: general cfid');
59 $m->form_name('EditCustomFields');
60 $m->tick( "AddCustomField" => $cfid );
61 $m->click('UpdateCFs');
63 $m->content_contains('Object created', 'TCF added to the queue' );
67 diag "create a ticket using API with 'asd'(not 'ASD') as value of the CF";
69 my $ticket = RT::Ticket->new( RT->SystemUser );
71 ($tid, $txnid, $msg) = $ticket->Create(
74 "CustomField-$cfid" => 'asd',
76 ok $tid, "created ticket";
79 # we use lc as we really don't care about case
80 # so if later we'll add canonicalization of value
82 is lc $ticket->FirstCustomFieldValue( $cf_name ),
83 'asd', 'assigned value of the CF';
86 diag "check that values of the CF are case insensetive(asd vs. ASD)";
88 ok $m->goto_ticket( $tid ), "opened ticket's page";
89 $m->follow_link( id => 'page-basics');
90 $m->title_like(qr/Modify ticket/i, 'modify ticket');
91 $m->content_contains($cf_name, 'CF on the page');
93 my $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
94 is lc $value, 'asd', 'correct value is selected';
96 $m->content_unlike(qr/\Q$cf_name\E.*?changed/mi, 'field is not changed');
98 $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
99 is lc $value, 'asd', 'the same value is still selected';
101 my $ticket = RT::Ticket->new( RT->SystemUser );
102 $ticket->Load( $tid );
103 ok $ticket->id, 'loaded the ticket';
104 is lc $ticket->FirstCustomFieldValue( $cf_name ),
105 'asd', 'value is still the same';
108 diag "check that 0 is ok value of the CF";
110 ok $m->goto_ticket( $tid ), "opened ticket's page";
111 $m->follow_link( id => 'page-basics');
112 $m->title_like(qr/Modify ticket/i, 'modify ticket');
113 $m->content_contains($cf_name, 'CF on the page');
115 my $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
116 is lc $value, 'asd', 'correct value is selected';
117 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => 0 );
119 $m->content_like(qr/\Q$cf_name\E.*?changed/mi, 'field is changed');
120 $m->content_lacks('0 is no longer a value for custom field', 'no bad message in results');
122 $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
123 is lc $value, '0', 'new value is selected';
125 my $ticket = RT::Ticket->new( RT->SystemUser );
126 $ticket->Load( $tid );
127 ok $ticket->id, 'loaded the ticket';
128 is lc $ticket->FirstCustomFieldValue( $cf_name ),
129 '0', 'API returns correct value';
132 diag "check that we can set empty value when the current is 0";
134 ok $m->goto_ticket( $tid ), "opened ticket's page";
135 $m->follow_link( id => 'page-basics');
136 $m->title_like(qr/Modify ticket/i, 'modify ticket');
137 $m->content_contains($cf_name, 'CF on the page');
139 my $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
140 is lc $value, '0', 'correct value is selected';
141 $m->select("Object-RT::Ticket-$tid-CustomField-$cfid-Values" => '' );
143 $m->content_contains('0 is no longer a value for custom field', '0 is no longer a value');
145 $value = $m->form_name('TicketModify')->value("Object-RT::Ticket-$tid-CustomField-$cfid-Values");
146 is $value, '', '(no value) is selected';
148 my $ticket = RT::Ticket->new( RT->SystemUser );
149 $ticket->Load( $tid );
150 ok $ticket->id, 'loaded the ticket';
151 is $ticket->FirstCustomFieldValue( $cf_name ),
152 undef, 'API returns correct value';