1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
|
use strict;
use warnings;
use RT::Test tests => undef;
my @groupings = qw/Basics Dates People Links More/;
RT->Config->Set( 'CustomFieldGroupings',
'RT::Ticket' => {
map { +($_ => ["Test$_"]) } @groupings,
},
);
RT->Config->PostLoadCheck;
my %CF;
for my $grouping (@groupings) {
my $name = "Test$grouping";
my $cf = RT::CustomField->new( RT->SystemUser );
my ($id, $msg) = $cf->Create(
Name => $name,
Queue => '0',
Description => 'A Testing custom field',
Type => 'FreeformSingle',
Pattern => '^(?!bad value).*$',
);
ok $id, "custom field '$name' correctly created";
$CF{$grouping} = $id;
}
my $queue = RT::Test->load_or_create_queue( Name => 'General' );
my ( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';
my %location = (
Basics => ".ticket-info-basics",
Dates => ".ticket-info-dates",
People => "#ticket-create-message",
Links => ".ticket-info-links",
More => ".ticket-info-cfs",
);
{
note "testing Create";
$m->goto_create_ticket($queue);
my $prefix = 'Object-RT::Ticket--CustomField:';
my $dom = $m->dom;
$m->form_name('TicketCreate');
$m->field("Subject", "CF grouping test");
for my $grouping (@groupings) {
my $input_name = $prefix . "$grouping-$CF{$grouping}-Value";
is $dom->find(qq{input[name="$input_name"]})->size, 1, "only one CF input on the page";
ok $dom->at(qq{$location{$grouping} input[name="$input_name"]}), "CF is in the right place";
$m->field( $input_name, "Test" . $grouping . "Value" );
}
$m->click('SubmitTicket');
}
my $id = $m->get_ticket_id;
{
note "testing Display";
ok $id, "created a ticket";
my $dom = $m->dom;
$location{People} = ".ticket-info-people";
foreach my $grouping (@groupings) {
my $row_id = "CF-$CF{$grouping}-ShowRow";
is $dom->find(qq{#$row_id})->size, 1, "CF on the page";
like $dom->at(qq{#$row_id})->all_text, qr/Test$grouping:\s*Test${grouping}Value/, "value is set";
ok $dom->at(qq{$location{$grouping} #$row_id}), "CF is in the right place";
}
}
{
note "testing Basics/People/Dates/Links pages";
my $prefix = 'Object-RT::Ticket-'. $id .'-CustomField:';
{ # Basics and More both show up on "Basics"
for my $name (qw/Basics More/) {
$m->follow_link_ok({id => 'page-basics'}, 'Ticket -> Basics');
is $m->dom->find(qq{input[name^="$prefix"][name\$="-Value"]})->size, 2,
"two CF inputs on the page";
my $input_name = "$prefix$name-$CF{$name}-Value";
ok $m->dom->at(qq{$location{$name} input[name="$input_name"]}),
"CF is in the right place";
$m->submit_form_ok({
with_fields => { $input_name => "Test${name}Changed" },
button => 'SubmitTicket',
});
$m->content_like(qr{to Test${name}Changed});
$m->submit_form_ok({
with_fields => { $input_name => "bad value" },
button => 'SubmitTicket',
});
$m->content_like(qr{Test\Q$name\E: Input must match});
}
}
# Everything else gets its own page
foreach my $name ( qw(People Dates Links) ) {
$m->follow_link_ok({id => "page-\L$name"}, "Ticket's $name page");
is $m->dom->find(qq{input[name^="$prefix"][name\$="-Value"]})->size, 1,
"only one CF input on the page";
my $input_name = "$prefix$name-$CF{$name}-Value";
$m->submit_form_ok({
with_fields => { $input_name => "Test${name}Changed" },
button => 'SubmitTicket',
});
$m->content_like(qr{to Test${name}Changed});
$m->submit_form_ok({
with_fields => { $input_name => "bad value" },
button => 'SubmitTicket',
});
$m->text_like(qr{Could not add a new value to custom field 'Test$name': Input must match \Q^(?!bad value).*\E\$});
}
}
{
note "testing Jumbo";
my $prefix = 'Object-RT::Ticket-'. $id .'-CustomField:';
$m->follow_link_ok({id => "page-jumbo"}, "Ticket's Jumbo page");
my $dom = $m->dom;
$m->form_name("TicketModifyAll");
foreach my $name ( qw(Basics People Dates Links More) ) {
my $input_name = "$prefix$name-$CF{$name}-Value";
is $dom->find(qq{input[name="$input_name"]})->size, 1,
"only one CF input on the page";
$m->field( $input_name, "Test${name}Again" );
}
$m->click('SubmitTicket');
foreach my $name ( qw(Basics People Dates Links More) ) {
$m->content_like(qr{to Test${name}Again});
}
}
{
note "Reconfigure to place one CF in multiple boxes";
$m->no_warnings_ok;
RT::Test->stop_server;
RT->Config->Set( 'CustomFieldGroupings',
'RT::Ticket' => {
Basics => [ 'TestMore' ],
More => [ 'TestMore' ],
},
);
RT->Config->PostLoadCheck;
( $baseurl, $m ) = RT::Test->started_ok;
ok $m->login, 'logged in as root';
}
{
note "Testing one CF in multiple boxes";
$m->goto_create_ticket($queue);
my $prefix = 'Object-RT::Ticket--CustomField:';
my $dom = $m->dom;
$m->form_name('TicketCreate');
my $cf = $CF{More};
is $m->dom->find(qq{input[name^="$prefix"][name\$="-$cf-Value"]})->size, 2,
"Two 'More' CF inputs on the page";
for my $grouping (qw/Basics More/) {
my $input_name = $prefix . "$grouping-$cf-Value";
is $dom->find(qq{input[name="$input_name"]})->size, 1, "Found the $grouping grouping";
ok $dom->at(qq{$location{$grouping} input[name="$input_name"]}), "CF is in the right place";
$m->field( $input_name, "TestMoreValue" );
}
$m->click('SubmitTicket');
$m->no_warnings_ok( "Submitting CF with two (identical) values had no warnings" );
}
$id = $m->get_ticket_id;
my $ticket = RT::Ticket->new ( RT->SystemUser );
$ticket->Load( $id );
is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "TestMoreValue",
"Value submitted twice is set correctly (and only once)";
my $cf = $CF{More};
my $prefix = 'Object-RT::Ticket-'. $id .'-CustomField:';
{
note "Updating with multiple appearances of a CF";
$m->follow_link_ok({id => 'page-basics'}, 'Ticket -> Basics');
is $m->dom->find(qq{input[name^="$prefix"][name\$="-$cf-Value"]})->size, 2,
"Two 'More' CF inputs on the page";
my @inputs;
for my $grouping (qw/Basics More/) {
my $input_name = "$prefix$grouping-$cf-Value";
push @inputs, $input_name;
ok $m->dom->at(qq{$location{$grouping} input[name="$input_name"]}),
"CF is in the right place";
}
$m->submit_form_ok({
with_fields => {
map {+($_ => "TestMoreChanged")} @inputs,
},
button => 'SubmitTicket',
});
$m->no_warnings_ok;
$m->content_like(qr{to TestMoreChanged});
$ticket->Load( $id );
is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "TestMoreChanged",
"Updated value submitted twice is set correctly (and only once)";
}
{
note "Updating with _differing_ values in multiple appearances of a CF";
my %inputs = map {+($_ => "$prefix$_-$cf-Value")} qw/Basics More/;
$m->submit_form_ok({
with_fields => {
$inputs{Basics} => "BasicsValue",
$inputs{More} => "MoreValue",
},
button => 'SubmitTicket',
});
$m->warning_like(qr{CF $cf submitted with multiple differing values});
$m->content_like(qr{to BasicsValue}, "Arbitrarily chose first value");
$ticket->Load( $id );
is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "BasicsValue",
"Conflicting value submitted twice is set correctly (and only once)";
}
{
note "Configuring CF to be a select-multiple";
my $custom_field = RT::CustomField->new( RT->SystemUser );
$custom_field->Load( $cf );
$custom_field->SetType( "Select" );
$custom_field->SetMaxValues( 0 );
$custom_field->AddValue( Name => $_ ) for 1..9;
}
{
note "Select multiples do not interfere with each other when appearing multiple times";
$m->follow_link_ok({id => 'page-basics'}, 'Ticket -> Basics');
$m->form_name('TicketModify');
my %inputs = map {+($_ => "$prefix$_-$cf-Values")} qw/Basics More/;
ok $m->dom->at(qq{select[name="$inputs{Basics}"]}), "Found 'More' CF in Basics box";
ok $m->dom->at(qq{select[name="$inputs{More}"]}), "Found 'More' CF in More box";
$m->select( $inputs{Basics} => [1, 3, 9] );
$m->select( $inputs{More} => [1, 3, 9] );
$m->click( 'SubmitTicket' );
$m->no_warnings_ok;
$m->content_like(qr{$_ added as a value for TestMore}) for 1, 3, 9;
$m->content_like(qr{BasicsValue is no longer a value for custom field TestMore});
$ticket->Load( $id );
is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "1|3|9",
"Multi-select values submitted correctly";
}
{
note "Submit multiples correctly choose one set of values when conflicting information is submitted";
$m->form_name('TicketModify');
my %inputs = map {+($_ => "$prefix$_-$cf-Values")} qw/Basics More/;
$m->select( $inputs{Basics} => [2, 3, 4] );
$m->select( $inputs{More} => [8, 9] );
$m->click( 'SubmitTicket' );
$m->warning_like(qr{CF $cf submitted with multiple differing values});
$m->content_like(qr{$_ added as a value for TestMore}) for 2, 4;
$m->content_unlike(qr{$_ added as a value for TestMore}) for 8;
$m->content_like(qr{$_ is no longer a value for custom field TestMore}) for 1, 9;
$ticket->Load( $id );
is $ticket->CustomFieldValuesAsString( "TestMore", Separator => "|" ), "3|2|4",
"Multi-select values submitted correctly";
}
done_testing;
|