first pass RT4 merge, RT#13852
[freeside.git] / rt / t / web / cf_access.t
1 #!/usr/bin/perl -w
2 use strict;
3
4 use RT::Test tests => 32;
5
6 my ($baseurl, $m) = RT::Test->started_ok;
7
8 use constant ImageFile => $RT::MasonComponentRoot .'/NoAuth/images/bpslogo.png';
9 use constant ImageFileContent => RT::Test->file_content(ImageFile);
10
11 ok $m->login, 'logged in';
12
13 diag "Create a CF";
14 {
15     $m->follow_link( id => 'tools-config-custom-fields-create');
16
17     # Test form validation
18     $m->submit_form(
19         form_name => "ModifyCustomField",
20         fields => {
21             TypeComposite => 'Image-0',
22             LookupType => 'RT::Queue-RT::Ticket',
23             Name => '',
24             Description => 'img',
25         },
26     );
27     $m->text_contains('Invalid value for Name');
28
29     $m->submit_form(
30         form_name => "ModifyCustomField",
31         fields => {
32             TypeComposite => 'Image-0',
33             LookupType => 'RT::Queue-RT::Ticket',
34             Name => '0',
35             Description => 'img',
36         },
37     );
38     $m->text_contains('Invalid value for Name');
39
40     $m->submit_form(
41         form_name => "ModifyCustomField",
42         fields => {
43             TypeComposite => 'Image-0',
44             LookupType => 'RT::Queue-RT::Ticket',
45             Name => '1',
46             Description => 'img',
47         },
48     );
49     $m->text_contains('Invalid value for Name');
50
51     # The real submission
52     $m->submit_form(
53         form_name => "ModifyCustomField",
54         fields => {
55             TypeComposite => 'Image-0',
56             LookupType => 'RT::Queue-RT::Ticket',
57             Name => 'img',
58             Description => 'img',
59         },
60     );
61     $m->text_contains('Object created');
62
63     # Validation on update
64     $m->form_name("ModifyCustomField");
65     $m->set_fields(
66         TypeComposite => 'Image-0',
67         LookupType => 'RT::Queue-RT::Ticket',
68         Name => '',
69         Description => 'img',
70     );
71     $m->click('Update');
72     $m->text_contains('Illegal value for Name');
73     $m->form_name("ModifyCustomField");
74     $m->set_fields(
75         TypeComposite => 'Image-0',
76         LookupType => 'RT::Queue-RT::Ticket',
77         Name => '0',
78         Description => 'img',
79     );
80     $m->click('Update');
81     $m->text_contains('Illegal value for Name');
82     $m->form_name("ModifyCustomField");
83     $m->set_fields(
84         TypeComposite => 'Image-0',
85         LookupType => 'RT::Queue-RT::Ticket',
86         Name => '1',
87         Description => 'img',
88     );
89     $m->click('Update');
90     $m->text_contains('Illegal value for Name');
91 }
92
93 diag "apply the CF to General queue";
94 my ( $cf, $cfid, $tid );
95 {
96     $m->title_is(q/Editing CustomField img/, 'admin-cf created');
97     $m->follow_link( id => 'tools-config-queues');
98     $m->follow_link( text => 'General' );
99     $m->title_is(q/Configuration for queue General/, 'admin-queue: general');
100     $m->follow_link( id => 'page-ticket-custom-fields');
101     $m->title_is(q/Custom Fields for queue General/, 'admin-queue: general cfid');
102     $m->form_name('EditCustomFields');
103
104     # Sort by numeric IDs in names
105     my @names = sort grep defined,
106         $m->current_form->find_input('AddCustomField')->possible_values;
107     $cf = pop(@names);
108     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
109     $cfid = $1;
110     $m->tick( AddCustomField => $cf => 1 ); # Associate the new CF with this queue
111     $m->tick( AddCustomField => $_  => 0 ) for @names; # ...and not any other. ;-)
112     $m->click('UpdateCFs');
113
114     $m->content_contains('Object created', 'TCF added to the queue' );
115 }
116
117 my $tester = RT::Test->load_or_create_user( Name => 'tester', Password => '123456' );
118 RT::Test->set_rights(
119     { Principal => $tester->PrincipalObj,
120       Right => [qw(SeeQueue ShowTicket CreateTicket)],
121     },
122 );
123 ok $m->login( $tester->Name, 123456, logout => 1), 'logged in';
124
125 diag "check that we have no the CF on the create"
126     ." ticket page when user has no SeeCustomField right";
127 {
128     $m->submit_form(
129         form_name => "CreateTicketInQueue",
130         fields => { Queue => 'General' },
131     );
132     $m->content_lacks('Upload multiple images', 'has no upload image field');
133
134     my $form = $m->form_name("TicketCreate");
135     my $upload_field = "Object-RT::Ticket--CustomField-$cfid-Upload"; 
136     ok !$form->find_input( $upload_field ), 'no form field on the page';
137
138     $m->submit_form(
139         form_name => "TicketCreate",
140         fields => { Subject => 'test' },
141     );
142     $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
143
144     $m->content_lacks('img:', 'has no img field on the page');
145     $m->follow_link( text => 'Custom Fields');
146     $m->content_lacks('Upload multiple images', 'has no upload image field');
147 }
148
149 RT::Test->set_rights(
150     { Principal => $tester->PrincipalObj,
151       Right => [qw(SeeQueue ShowTicket CreateTicket SeeCustomField)],
152     },
153 );
154
155 diag "check that we have no the CF on the create"
156     ." ticket page when user has no ModifyCustomField right";
157 {
158     $m->submit_form(
159         form_name => "CreateTicketInQueue",
160         fields => { Queue => 'General' },
161     );
162     $m->content_lacks('Upload multiple images', 'has no upload image field');
163
164     my $form = $m->form_name("TicketCreate");
165     my $upload_field = "Object-RT::Ticket--CustomField-$cfid-Upload";
166     ok !$form->find_input( $upload_field ), 'no form field on the page';
167
168     $m->submit_form(
169         form_name => "TicketCreate",
170         fields => { Subject => 'test' },
171     );
172     $tid = $1 if $m->content =~ /Ticket (\d+) created/i;
173     ok $tid, "a ticket is created succesfully";
174
175     $m->follow_link( id => 'page-basics');
176     $m->content_lacks('Upload multiple images', 'has no upload image field');
177     $form = $m->form_name('TicketModify');
178     $upload_field = "Object-RT::Ticket-$tid-CustomField-$cfid-Upload";
179     ok !$form->find_input( $upload_field ), 'no form field on the page';
180 }
181
182 RT::Test->set_rights(
183     { Principal => $tester->PrincipalObj,
184       Right => [qw(SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField)],
185     },
186 );
187
188 diag "create a ticket with an image";
189 {
190     $m->submit_form(
191         form_name => "CreateTicketInQueue",
192         fields => { Queue => 'General' },
193     );
194     $m->content_contains('Upload multiple images', 'has a upload image field');
195
196     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
197     my $upload_field = "Object-RT::Ticket--CustomField-$1-Upload";
198
199     $m->submit_form(
200         form_name => "TicketCreate",
201         fields => {
202             $upload_field => ImageFile,
203             Subject => 'testing img cf creation',
204         },
205     );
206
207     $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
208
209     $tid = $1 if $m->content =~ /Ticket (\d+) created/;
210
211     $m->title_like(qr/testing img cf creation/, "its title is the Subject");
212
213     $m->follow_link( text => 'bpslogo.png' );
214     $m->content_is(ImageFileContent, "it links to the uploaded image");
215 }
216
217 $m->get( $m->rt_base_url );
218 $m->follow_link( id => 'search-new');
219 $m->title_is(q/Query Builder/, 'Query building');
220 $m->submit_form(
221     form_name => "BuildQuery",
222     fields => {
223         idOp => '=',
224         ValueOfid => $tid,
225         ValueOfQueue => 'General',
226     },
227     button => 'AddClause',
228 );
229
230 $m->form_name('BuildQuery');
231
232 my $col = ($m->current_form->find_input('SelectDisplayColumns'))[-1];
233 $col->value( ($col->possible_values)[-1] );
234
235 $m->click('AddCol');
236
237 $m->form_name('BuildQuery');
238 $m->click('DoSearch');
239
240 $m->follow_link( text_regex => qr/bpslogo\.png/ );
241 $m->content_is(ImageFileContent, "it links to the uploaded image");
242
243 __END__
244 [FC] Bulk Update does not have custom fields.