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
|
use strict;
use warnings;
use RT::Test tests => 'no_declare';
my $content = join ' ', ('The quick brown fox jumps over the lazy dog.') x 5;
$content = join "\n\n", $content, $content, $content;
my ($base, $m) = RT::Test->started_ok;
$m->login;
my $ticket = RT::Test->create_ticket(
Queue => 1,
Subject => 'a test ticket',
);
ok $ticket && $ticket->id, "Created ticket";
my $EditUrl = "/Ticket/Modify.html?id=" . $ticket->id;
my $cfs = {
area => {
type => 'Text',
name => 'TheTextarea',
},
text => {
type => 'FreeformSingle',
name => 'TheControlField',
},
zero => {
type => 'FreeformSingle',
name => 'Zero',
},
};
while ( my( $label, $data ) = each %$cfs ) {
my $cf = $data->{obj} = RT::Test->load_or_create_custom_field(
Name => $data->{name},
Type => $data->{type},
Queue => 0,
LookupType => 'RT::Queue-RT::Ticket',
);
ok $cf && $cf->id, "Created $data->{type} CF";
# get cf input field name
$data->{input} = RT::Interface::Web::GetCustomFieldInputName(
Object => $ticket,
CustomField => $cf,
);
}
# open ticket "Basics" page
$m->get_ok($EditUrl, "Fetched $EditUrl");
$m->content_contains($_->{name} . ':') for ( values %$cfs );
$m->submit_form_ok({
with_fields => {
$cfs->{area}{input} => $content,
$cfs->{area}{input} . '-Magic' => "1",
$cfs->{text}{input} => 'value a',
$cfs->{text}{input} . '-Magic' => "1",
$cfs->{zero}{input} => '0',
$cfs->{zero}{input} . '-Magic' => "1",
},
}, 'submitted form to initially set CFs');
$m->content_contains('<li>TheControlField value a added</li>');
$m->content_contains("<li>TheTextarea $content added</li>", 'content found');
$m->content_contains("<li>Zero 0 added</li>", 'zero field found');
# http://issues.bestpractical.com/Ticket/Display.html?id=30378
# #30378: RT 4.2.6 - Very long text fields get updated even when they haven't changed
$m->submit_form_ok({
with_fields => {
$cfs->{text}{input} => 'value b',
$cfs->{text}{input} . '-Magic' => "1",
},
}, 'submitted form to initially set CFs');
$m->content_contains('<li>TheControlField value a changed to value b</li>');
$m->content_lacks("<li>TheTextarea $content changed to $content</li>", 'textarea wasnt updated');
# http://issues.bestpractical.com/Ticket/Display.html?id=32440
# #32440: Spurious "CF changed from 0 to 0"
$m->content_lacks("<li>Zero 0 changed to 0</li>", "Zero wasn't updated");
my $new_content = 'The quick brown fox jumps over the lazy dog.';
$m->submit_form_ok({
with_fields => {
$cfs->{area}{input} => $new_content,
$cfs->{area}{input} . '-Magic' => "1",
},
}, 'submitted form to update textarea CF');
$m->content_contains( "<li>TheTextarea $content changed to $new_content</li>", 'textarea was updated' );
my $newer_content = 'The quick yellow fox jumps over the lazy dog.';
$m->submit_form_ok({
with_fields => {
$cfs->{area}{input} => $newer_content,
$cfs->{area}{input} . '-Magic' => "1",
},
}, 'submitted form to update textarea CF');
$m->content_contains( "<li>TheTextarea $new_content changed to $newer_content</li>", 'textarea was updated' );
my $txn = $ticket->Transactions->Last;
$m->get_ok( '/Helpers/TextDiff?TransactionId=' . $txn->id );
$m->content_like( qr{<del>brown\s*</del><ins>yellow\s*</ins>}, 'text diff has the brown => yellow change' );
$m->back;
$m->submit_form_ok({
with_fields => {
$cfs->{area}{input} => '',
$cfs->{area}{input} . '-Magic' => "1",
},
}, 'submitted form to update textarea CF');
$m->content_contains( "<li>$newer_content is no longer a value for custom field TheTextarea</li>",
'textarea was deleted' );
$m->follow_link_ok( { text => 'Display' } );
$content =~ s!\n+!!g;
$m->text_like(
qr/TheTextarea\sadded.+\Q$content\E.+
TheTextarea\schanged.+From:\Q$content\E\s*To:\Q$new_content\E.+
TheTextarea\schanged.+From:\Q$new_content\E\s*To:\Q$newer_content\E.+
TheTextarea\sdeleted.+\Q$newer_content\E/xs,
'textarea change details'
);
$m->back;
$m->submit_form_ok(
{
with_fields => {
$cfs->{area}{input} => '<div class="form-row">test</div>',
$cfs->{area}{input} . '-Magic' => "1",
},
},
'submitted form to update textarea CF'
);
$m->text_contains('TheTextarea scrubbed');
$m->text_contains( "TheTextarea <div>test</div> added", 'textarea was updated' );
RT::Test->stop_server;
RT->Config->Set( ScrubCustomFieldOnSave => Default => 1, 'RT::Ticket' => 0 );
( $base, $m ) = RT::Test->started_ok;
$m->login;
$m->get_ok( $EditUrl, "Fetched $EditUrl" );
$m->submit_form_ok(
{
with_fields => {
$cfs->{area}{input} => '<div class="form-row">test2</div>',
$cfs->{area}{input} . '-Magic' => "1",
},
},
'submitted form to update textarea CF'
);
$m->text_lacks('TheTextarea scrubbed');
$m->text_contains( qq{TheTextarea <div>test</div> changed to <div class="form-row">test2</div>},
'textarea was updated without scrubbing' );
$m->follow_link_ok( { text => 'Display' } );
$m->content_contains( '<div>test2</div>', 'Content is scrubbed on display' );
done_testing;
|