4 use RT::Test tests => undef;
6 my @groupings = qw/Basics Dates People Links More/;
7 RT->Config->Set( 'CustomFieldGroupings',
9 map { +($_ => ["Test$_"]) } @groupings,
14 for my $grouping (@groupings) {
15 my $name = "Test$grouping";
16 my $cf = RT::CustomField->new( RT->SystemUser );
17 my ($id, $msg) = $cf->Create(
20 Description => 'A Testing custom field',
21 Type => 'FreeformSingle',
22 Pattern => '^(?!bad value).*$',
24 ok $id, "custom field '$name' correctly created";
28 my $queue = RT::Test->load_or_create_queue( Name => 'General' );
30 my ( $baseurl, $m ) = RT::Test->started_ok;
31 ok $m->login, 'logged in as root';
34 Basics => ".ticket-info-basics",
35 Dates => ".ticket-info-dates",
36 People => "#ticket-create-message",
37 Links => ".ticket-info-links",
38 More => ".ticket-info-cfs",
41 note "testing Create";
42 $m->goto_create_ticket($queue);
44 my $prefix = 'Object-RT::Ticket--CustomField:';
46 $m->form_name('TicketCreate');
47 $m->field("Subject", "CF grouping test");
49 for my $grouping (@groupings) {
50 my $input_name = $prefix . "$grouping-$CF{$grouping}-Value";
51 is $dom->find(qq{input[name="$input_name"]})->size, 1, "only one CF input on the page";
52 ok $dom->at(qq{$location{$grouping} input[name="$input_name"]}), "CF is in the right place";
53 $m->field( $input_name, "Test" . $grouping . "Value" );
58 my $id = $m->get_ticket_id;
60 note "testing Display";
61 ok $id, "created a ticket";
64 $location{People} = ".ticket-info-people";
65 foreach my $grouping (@groupings) {
66 my $row_id = "CF-$CF{$grouping}-ShowRow";
67 is $dom->find(qq{#$row_id})->size, 1, "CF on the page";
68 like $dom->at(qq{#$row_id})->all_text, qr/Test$grouping:\s*Test${grouping}Value/, "value is set";
69 ok $dom->at(qq{$location{$grouping} #$row_id}), "CF is in the right place";
74 note "testing Basics/People/Dates/Links pages";
75 my $prefix = 'Object-RT::Ticket-'. $id .'-CustomField:';
76 { # Basics and More both show up on "Basics"
77 for my $name (qw/Basics More/) {
78 $m->follow_link_ok({id => 'page-basics'}, 'Ticket -> Basics');
79 is $m->dom->find(qq{input[name^="$prefix"][name\$="-Value"]})->size, 2,
80 "two CF inputs on the page";
82 my $input_name = "$prefix$name-$CF{$name}-Value";
83 ok $m->dom->at(qq{$location{$name} input[name="$input_name"]}),
84 "CF is in the right place";
86 with_fields => { $input_name => "Test${name}Changed" },
87 button => 'SubmitTicket',
89 $m->content_like(qr{to Test${name}Changed});
92 with_fields => { $input_name => "bad value" },
93 button => 'SubmitTicket',
95 $m->content_like(qr{Test\Q$name\E: Input must match});
99 # Everything else gets its own page
100 foreach my $name ( qw(People Dates Links) ) {
101 $m->follow_link_ok({id => "page-\L$name"}, "Ticket's $name page");
102 is $m->dom->find(qq{input[name^="$prefix"][name\$="-Value"]})->size, 1,
103 "only one CF input on the page";
104 my $input_name = "$prefix$name-$CF{$name}-Value";
106 with_fields => { $input_name => "Test${name}Changed" },
107 button => 'SubmitTicket',
109 $m->content_like(qr{to Test${name}Changed});
112 with_fields => { $input_name => "bad value" },
113 button => 'SubmitTicket',
115 $m->content_like(qr{Could not add new custom field value: Input must match});
120 note "testing Jumbo";
121 my $prefix = 'Object-RT::Ticket-'. $id .'-CustomField:';
122 $m->follow_link_ok({id => "page-jumbo"}, "Ticket's Jumbo page");
124 $m->form_name("TicketModifyAll");
126 foreach my $name ( qw(Basics People Dates Links More) ) {
127 my $input_name = "$prefix$name-$CF{$name}-Value";
128 is $dom->find(qq{input[name="$input_name"]})->size, 1,
129 "only one CF input on the page";
130 $m->field( $input_name, "Test${name}Again" );
132 $m->click('SubmitTicket');
133 foreach my $name ( qw(Basics People Dates Links More) ) {
134 $m->content_like(qr{to Test${name}Again});
139 note "Reconfigure to place one CF in multiple boxes";
141 RT::Test->stop_server;
143 RT->Config->Set( 'CustomFieldGroupings',
145 Basics => [ 'TestMore' ],
146 More => [ 'TestMore' ],
150 ( $baseurl, $m ) = RT::Test->started_ok;
151 ok $m->login, 'logged in as root';
155 note "Testing one CF in multiple boxes";
156 $m->goto_create_ticket($queue);
158 my $prefix = 'Object-RT::Ticket--CustomField:';
160 $m->form_name('TicketCreate');
163 is $m->dom->find(qq{input[name^="$prefix"][name\$="-$cf-Value"]})->size, 2,
164 "Two 'More' CF inputs on the page";
165 for my $grouping (qw/Basics More/) {
166 my $input_name = $prefix . "$grouping-$cf-Value";
167 is $dom->find(qq{input[name="$input_name"]})->size, 1, "Found the $grouping grouping";
168 ok $dom->at(qq{$location{$grouping} input[name="$input_name"]}), "CF is in the right place";
169 $m->field( $input_name, "TestMoreValue" );
172 $m->no_warnings_ok( "Submitting CF with two (identical) values had no warnings" );
175 $id = $m->get_ticket_id;
176 my $ticket = RT::Ticket->new ( RT->SystemUser );
177 $ticket->Load( $id );
178 is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "TestMoreValue",
179 "Value submitted twice is set correctly (and only once)";
182 my $prefix = 'Object-RT::Ticket-'. $id .'-CustomField:';
184 note "Updating with multiple appearances of a CF";
185 $m->follow_link_ok({id => 'page-basics'}, 'Ticket -> Basics');
187 is $m->dom->find(qq{input[name^="$prefix"][name\$="-$cf-Value"]})->size, 2,
188 "Two 'More' CF inputs on the page";
190 for my $grouping (qw/Basics More/) {
191 my $input_name = "$prefix$grouping-$cf-Value";
192 push @inputs, $input_name;
193 ok $m->dom->at(qq{$location{$grouping} input[name="$input_name"]}),
194 "CF is in the right place";
198 map {+($_ => "TestMoreChanged")} @inputs,
200 button => 'SubmitTicket',
203 $m->content_like(qr{to TestMoreChanged});
205 $ticket->Load( $id );
206 is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "TestMoreChanged",
207 "Updated value submitted twice is set correctly (and only once)";
211 note "Updating with _differing_ values in multiple appearances of a CF";
213 my %inputs = map {+($_ => "$prefix$_-$cf-Value")} qw/Basics More/;
216 $inputs{Basics} => "BasicsValue",
217 $inputs{More} => "MoreValue",
219 button => 'SubmitTicket',
221 $m->warning_like(qr{CF $cf submitted with multiple differing values});
222 $m->content_like(qr{to BasicsValue}, "Arbitrarily chose first value");
224 $ticket->Load( $id );
225 is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "BasicsValue",
226 "Conflicting value submitted twice is set correctly (and only once)";
230 note "Configuring CF to be a select-multiple";
231 my $custom_field = RT::CustomField->new( RT->SystemUser );
232 $custom_field->Load( $cf );
233 $custom_field->SetType( "Select" );
234 $custom_field->SetMaxValues( 0 );
235 $custom_field->AddValue( Name => $_ ) for 1..9;
239 note "Select multiples do not interfere with each other when appearing multiple times";
240 $m->follow_link_ok({id => 'page-basics'}, 'Ticket -> Basics');
242 $m->form_name('TicketModify');
243 my %inputs = map {+($_ => "$prefix$_-$cf-Values")} qw/Basics More/;
244 ok $m->dom->at(qq{select[name="$inputs{Basics}"]}), "Found 'More' CF in Basics box";
245 ok $m->dom->at(qq{select[name="$inputs{More}"]}), "Found 'More' CF in More box";
247 $m->select( $inputs{Basics} => [1, 3, 9] );
248 $m->select( $inputs{More} => [1, 3, 9] );
249 $m->click( 'SubmitTicket' );
251 $m->content_like(qr{$_ added as a value for TestMore}) for 1, 3, 9;
252 $m->content_like(qr{BasicsValue is no longer a value for custom field TestMore});
254 $ticket->Load( $id );
255 is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "1|3|9",
256 "Multi-select values submitted correctly";
260 note "Submit multiples correctly choose one set of values when conflicting information is submitted";
261 $m->form_name('TicketModify');
262 my %inputs = map {+($_ => "$prefix$_-$cf-Values")} qw/Basics More/;
263 $m->select( $inputs{Basics} => [2, 3, 4] );
264 $m->select( $inputs{More} => [8, 9] );
265 $m->click( 'SubmitTicket' );
266 $m->warning_like(qr{CF $cf submitted with multiple differing values});
267 $m->content_like(qr{$_ added as a value for TestMore}) for 2, 4;
268 $m->content_unlike(qr{$_ added as a value for TestMore}) for 8;
269 $m->content_like(qr{$_ is no longer a value for custom field TestMore}) for 1, 9;
271 $ticket->Load( $id );
272 is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "3|2|4",
273 "Multi-select values submitted correctly";