import rt 3.8.7
[freeside.git] / rt / t / web / cf_access.t
1 #!/usr/bin/perl -w
2 use strict;
3
4 use RT::Test tests => 26;
5 $RT::Test::SKIP_REQUEST_WORK_AROUND = 1;
6
7 my ($baseurl, $m) = RT::Test->started_ok;
8
9 use constant ImageFile => $RT::MasonComponentRoot .'/NoAuth/images/bplogo.gif';
10 use constant ImageFileContent => RT::Test->file_content(ImageFile);
11
12 ok $m->login, 'logged in';
13
14 diag "Create a CF" if $ENV{'TEST_VERBOSE'};
15 {
16     $m->follow_link( text => 'Configuration' );
17     $m->title_is(q/RT Administration/, 'admin screen');
18     $m->follow_link( text => 'Custom Fields' );
19     $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
20     $m->follow_link( text => 'Create' );
21     $m->submit_form(
22         form_name => "ModifyCustomField",
23         fields => {
24             TypeComposite => 'Image-0',
25             LookupType => 'RT::Queue-RT::Ticket',
26             Name => 'img',
27             Description => 'img',
28         },
29     );
30 }
31
32 diag "apply the CF to General queue" if $ENV{'TEST_VERBOSE'};
33 my ( $cf, $cfid, $tid );
34 {
35     $m->title_is(q/Created CustomField img/, 'admin-cf created');
36     $m->follow_link( text => 'Queues' );
37     $m->title_is(q/Admin queues/, 'admin-queues screen');
38     $m->follow_link( text => 'General' );
39     $m->title_is(q/Editing Configuration for queue General/, 'admin-queue: general');
40     $m->follow_link( text => 'Ticket Custom Fields' );
41
42     $m->title_is(q/Edit Custom Fields for General/, 'admin-queue: general cfid');
43     $m->form_name('EditCustomFields');
44
45     # Sort by numeric IDs in names
46     my @names = map  { $_->[1] }
47                 sort { $a->[0] <=> $b->[0] }
48                 map  { /Object-1-CF-(\d+)/ ? [ $1 => $_ ] : () }
49                 grep defined, map $_->name, $m->current_form->inputs;
50     $cf = pop(@names);
51     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
52     $cfid = $1;
53     $m->field( $cf => 1 );         # Associate the new CF with this queue
54     $m->field( $_ => undef ) for @names;    # ...and not any other. ;-)
55     $m->submit;
56
57     $m->content_like( qr/Object created/, 'TCF added to the queue' );
58 }
59
60 my $tester = RT::Test->load_or_create_user( Name => 'tester', Password => '123456' );
61 RT::Test->set_rights(
62     { Principal => $tester->PrincipalObj,
63       Right => [qw(SeeQueue ShowTicket CreateTicket)],
64     },
65 );
66 ok $m->login( $tester->Name, 123456), 'logged in';
67
68 diag "check that we have no the CF on the create"
69     ." ticket page when user has no SeeCustomField right"
70         if $ENV{'TEST_VERBOSE'};
71 {
72     $m->submit_form(
73         form_name => "CreateTicketInQueue",
74         fields => { Queue => 'General' },
75     );
76     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
77
78     my $form = $m->form_name("TicketCreate");
79     my $upload_field = "Object-RT::Ticket--CustomField-$cfid-Upload"; 
80     ok !$form->find_input( $upload_field ), 'no form field on the page';
81
82     $m->submit_form(
83         form_name => "TicketCreate",
84         fields => { Subject => 'test' },
85     );
86     $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
87
88     $m->content_unlike(qr/img:/, 'has no img field on the page');
89     $m->follow_link( text => 'Custom Fields');
90     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
91 }
92
93 RT::Test->set_rights(
94     { Principal => $tester->PrincipalObj,
95       Right => [qw(SeeQueue ShowTicket CreateTicket SeeCustomField)],
96     },
97 );
98
99 diag "check that we have no the CF on the create"
100     ." ticket page when user has no ModifyCustomField right"
101         if $ENV{'TEST_VERBOSE'};
102 {
103     $m->submit_form(
104         form_name => "CreateTicketInQueue",
105         fields => { Queue => 'General' },
106     );
107     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
108
109     my $form = $m->form_name("TicketCreate");
110     my $upload_field = "Object-RT::Ticket--CustomField-$cfid-Upload";
111     ok !$form->find_input( $upload_field ), 'no form field on the page';
112
113     $m->submit_form(
114         form_name => "TicketCreate",
115         fields => { Subject => 'test' },
116     );
117     $tid = $1 if $m->content =~ /Ticket (\d+) created/i;
118     ok $tid, "a ticket is created succesfully";
119
120     $m->follow_link( text => 'Custom Fields' );
121     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
122     $form = $m->form_number(3);
123     $upload_field = "Object-RT::Ticket-$tid-CustomField-$cfid-Upload";
124     ok !$form->find_input( $upload_field ), 'no form field on the page';
125 }
126
127 RT::Test->set_rights(
128     { Principal => $tester->PrincipalObj,
129       Right => [qw(SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField)],
130     },
131 );
132
133 diag "create a ticket with an image" if $ENV{'TEST_VERBOSE'};
134 {
135     $m->submit_form(
136         form_name => "CreateTicketInQueue",
137         fields => { Queue => 'General' },
138     );
139     $m->content_like(qr/Upload multiple images/, 'has a upload image field');
140
141     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
142     my $upload_field = "Object-RT::Ticket--CustomField-$1-Upload";
143
144     $m->submit_form(
145         form_name => "TicketCreate",
146         fields => {
147             $upload_field => ImageFile,
148             Subject => 'testing img cf creation',
149         },
150     );
151
152     $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
153
154     $tid = $1 if $m->content =~ /Ticket (\d+) created/;
155
156     $m->title_like(qr/testing img cf creation/, "its title is the Subject");
157
158     $m->follow_link( text => 'bplogo.gif' );
159     $m->content_is(ImageFileContent, "it links to the uploaded image");
160 }
161
162 $m->get( $m->rt_base_url );
163 $m->follow_link( text => 'Tickets' );
164 $m->follow_link( text => 'New Query' );
165
166 $m->title_is(q/Query Builder/, 'Query building');
167 $m->submit_form(
168     form_name => "BuildQuery",
169     fields => {
170         idOp => '=',
171         ValueOfid => $tid,
172         ValueOfQueue => 'General',
173     },
174     button => 'AddClause',
175 );
176
177 $m->form_name('BuildQuery');
178
179 my $col = ($m->current_form->find_input('SelectDisplayColumns'))[-1];
180 $col->value( ($col->possible_values)[-1] );
181
182 $m->click('AddCol');
183
184 $m->form_name('BuildQuery');
185 $m->click('DoSearch');
186
187 $m->follow_link( text_regex => qr/bplogo\.gif/ );
188 $m->content_is(ImageFileContent, "it links to the uploaded image");
189
190 __END__
191 [FC] Bulk Update does not have custom fields.