import torrus 1.0.9
[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 = sort grep defined,
47         $m->current_form->find_input('AddCustomField')->possible_values;
48     $cf = pop(@names);
49     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
50     $cfid = $1;
51     $m->tick( AddCustomField => $cf => 1 ); # Associate the new CF with this queue
52     $m->tick( AddCustomField => $_  => 0 ) for @names; # ...and not any other. ;-)
53     $m->click('UpdateCFs');
54
55     $m->content_like( qr/Object created/, 'TCF added to the queue' );
56 }
57
58 my $tester = RT::Test->load_or_create_user( Name => 'tester', Password => '123456' );
59 RT::Test->set_rights(
60     { Principal => $tester->PrincipalObj,
61       Right => [qw(SeeQueue ShowTicket CreateTicket)],
62     },
63 );
64 ok $m->login( $tester->Name, 123456), 'logged in';
65
66 diag "check that we have no the CF on the create"
67     ." ticket page when user has no SeeCustomField right"
68         if $ENV{'TEST_VERBOSE'};
69 {
70     $m->submit_form(
71         form_name => "CreateTicketInQueue",
72         fields => { Queue => 'General' },
73     );
74     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
75
76     my $form = $m->form_name("TicketCreate");
77     my $upload_field = "Object-RT::Ticket--CustomField-$cfid-Upload"; 
78     ok !$form->find_input( $upload_field ), 'no form field on the page';
79
80     $m->submit_form(
81         form_name => "TicketCreate",
82         fields => { Subject => 'test' },
83     );
84     $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
85
86     $m->content_unlike(qr/img:/, 'has no img field on the page');
87     $m->follow_link( text => 'Custom Fields');
88     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
89 }
90
91 RT::Test->set_rights(
92     { Principal => $tester->PrincipalObj,
93       Right => [qw(SeeQueue ShowTicket CreateTicket SeeCustomField)],
94     },
95 );
96
97 diag "check that we have no the CF on the create"
98     ." ticket page when user has no ModifyCustomField right"
99         if $ENV{'TEST_VERBOSE'};
100 {
101     $m->submit_form(
102         form_name => "CreateTicketInQueue",
103         fields => { Queue => 'General' },
104     );
105     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
106
107     my $form = $m->form_name("TicketCreate");
108     my $upload_field = "Object-RT::Ticket--CustomField-$cfid-Upload";
109     ok !$form->find_input( $upload_field ), 'no form field on the page';
110
111     $m->submit_form(
112         form_name => "TicketCreate",
113         fields => { Subject => 'test' },
114     );
115     $tid = $1 if $m->content =~ /Ticket (\d+) created/i;
116     ok $tid, "a ticket is created succesfully";
117
118     $m->follow_link( text => 'Custom Fields' );
119     $m->content_unlike(qr/Upload multiple images/, 'has no upload image field');
120     $form = $m->form_number(3);
121     $upload_field = "Object-RT::Ticket-$tid-CustomField-$cfid-Upload";
122     ok !$form->find_input( $upload_field ), 'no form field on the page';
123 }
124
125 RT::Test->set_rights(
126     { Principal => $tester->PrincipalObj,
127       Right => [qw(SeeQueue ShowTicket CreateTicket SeeCustomField ModifyCustomField)],
128     },
129 );
130
131 diag "create a ticket with an image" if $ENV{'TEST_VERBOSE'};
132 {
133     $m->submit_form(
134         form_name => "CreateTicketInQueue",
135         fields => { Queue => 'General' },
136     );
137     $m->content_like(qr/Upload multiple images/, 'has a upload image field');
138
139     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
140     my $upload_field = "Object-RT::Ticket--CustomField-$1-Upload";
141
142     $m->submit_form(
143         form_name => "TicketCreate",
144         fields => {
145             $upload_field => ImageFile,
146             Subject => 'testing img cf creation',
147         },
148     );
149
150     $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
151
152     $tid = $1 if $m->content =~ /Ticket (\d+) created/;
153
154     $m->title_like(qr/testing img cf creation/, "its title is the Subject");
155
156     $m->follow_link( text => 'bplogo.gif' );
157     $m->content_is(ImageFileContent, "it links to the uploaded image");
158 }
159
160 $m->get( $m->rt_base_url );
161 $m->follow_link( text => 'Tickets' );
162 $m->follow_link( text => 'New Query' );
163
164 $m->title_is(q/Query Builder/, 'Query building');
165 $m->submit_form(
166     form_name => "BuildQuery",
167     fields => {
168         idOp => '=',
169         ValueOfid => $tid,
170         ValueOfQueue => 'General',
171     },
172     button => 'AddClause',
173 );
174
175 $m->form_name('BuildQuery');
176
177 my $col = ($m->current_form->find_input('SelectDisplayColumns'))[-1];
178 $col->value( ($col->possible_values)[-1] );
179
180 $m->click('AddCol');
181
182 $m->form_name('BuildQuery');
183 $m->click('DoSearch');
184
185 $m->follow_link( text_regex => qr/bplogo\.gif/ );
186 $m->content_is(ImageFileContent, "it links to the uploaded image");
187
188 __END__
189 [FC] Bulk Update does not have custom fields.