rt 4.2.14 (#13852)
[freeside.git] / rt / t / web / cf_textarea.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => 'no_declare';
5
6 my $content = join ' ', ('The quick brown fox jumps over the lazy dog.') x 5;
7 $content = join "\n\n", $content, $content, $content;
8
9 my ($base, $m) = RT::Test->started_ok;
10
11 $m->login;
12
13 my $ticket = RT::Test->create_ticket(
14     Queue   => 1,
15     Subject => 'a test ticket',
16 );
17 ok $ticket && $ticket->id, "Created ticket";
18
19 my $EditUrl = "/Ticket/Modify.html?id=" . $ticket->id;
20
21 my $cfs = {
22     area => {
23         type => 'Text',
24         name => 'TheTextarea',
25     },
26     text => {
27         type => 'FreeformSingle',
28         name => 'TheControlField',
29     },
30     zero => {
31         type => 'FreeformSingle',
32         name => 'Zero',
33     },
34 };
35
36 while ( my( $label, $data ) = each %$cfs ) {
37     my $cf = $data->{obj} = RT::Test->load_or_create_custom_field(
38         Name        => $data->{name},
39         Type        => $data->{type},
40         Queue       => 0,
41         LookupType  => 'RT::Queue-RT::Ticket',
42     );
43     ok $cf && $cf->id, "Created $data->{type} CF";
44
45     # get cf input field name
46     $data->{input} = RT::Interface::Web::GetCustomFieldInputName(
47         Object      => $ticket,
48         CustomField => $cf,
49     );
50 }
51
52 # open ticket "Basics" page
53 $m->get_ok($EditUrl, "Fetched $EditUrl");
54 $m->content_contains($_->{name} . ':') for ( values %$cfs );
55
56 $m->submit_form_ok({
57     with_fields => {
58         $cfs->{area}{input}            => $content,
59         $cfs->{area}{input} . '-Magic' => "1",
60         $cfs->{text}{input}            => 'value a',
61         $cfs->{text}{input} . '-Magic' => "1",
62         $cfs->{zero}{input}            => '0',
63         $cfs->{zero}{input} . '-Magic' => "1",
64     },
65 }, 'submitted form to initially set CFs');
66 $m->content_contains('<li>TheControlField value a added</li>');
67 $m->content_contains("<li>TheTextarea $content added</li>", 'content found');
68 $m->content_contains("<li>Zero 0 added</li>", 'zero field found');
69
70 # http://issues.bestpractical.com/Ticket/Display.html?id=30378
71 # #30378: RT 4.2.6 - Very long text fields get updated even when they haven't changed
72 $m->submit_form_ok({
73     with_fields => {
74         $cfs->{text}{input}            => 'value b',
75         $cfs->{text}{input} . '-Magic' => "1",
76     },
77 }, 'submitted form to initially set CFs');
78 $m->content_contains('<li>TheControlField value a changed to value b</li>');
79 $m->content_lacks("<li>TheTextarea $content changed to $content</li>", 'textarea wasnt updated');
80
81 # http://issues.bestpractical.com/Ticket/Display.html?id=32440
82 # #32440: Spurious "CF changed from 0 to 0"
83 $m->content_lacks("<li>Zero 0 changed to 0</li>", "Zero wasn't updated");
84
85 undef $m;
86 done_testing;