import rt 3.8.9
[freeside.git] / rt / lib / t / regression / 08web_cf_access.t
1 #!/usr/bin/perl -w
2 use strict;
3
4 use Test::More tests => 15;
5 BEGIN {
6     use RT;
7     RT::LoadConfig;
8     RT::Init;
9 }
10 use Test::WWW::Mechanize;
11
12 use constant BaseURL => $RT::WebURL;
13 use constant ImageFile => $RT::MasonComponentRoot .'/NoAuth/images/bplogo.gif';
14 use constant ImageFileContent => do {
15     local $/;
16     open my $fh, '<', ImageFile or die $!;
17     binmode($fh);
18     scalar <$fh>;
19 };
20
21 my $m = Test::WWW::Mechanize->new;
22 isa_ok($m, 'Test::WWW::Mechanize');
23
24 $m->get( BaseURL."?user=root;pass=password" );
25 $m->content_like(qr/Logout/, 'we did log in');
26 $m->follow_link( text => 'Configuration' );
27 $m->title_is(q/RT Administration/, 'admin screen');
28 $m->follow_link( text => 'Custom Fields' );
29 $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
30 $m->follow_link( text => 'New custom field' );
31 $m->submit_form(
32     form_name => "ModifyCustomField",
33     fields => {
34         TypeComposite => 'Image-0',
35         LookupType => 'RT::Queue-RT::Ticket',
36         Name => 'img',
37         Description => 'img',
38     },
39 );
40 $m->title_is(q/Created CustomField img/, 'admin-cf created');
41 $m->follow_link( text => 'Queues' );
42 $m->title_is(q/Admin queues/, 'admin-queues screen');
43 $m->follow_link( text => 'General' );
44 $m->title_is(q/Editing Configuration for queue General/, 'admin-queue: general');
45 $m->follow_link( text => 'Ticket Custom Fields' );
46
47 $m->title_is(q/Edit Custom Fields for General/, 'admin-queue: general tcf');
48 $m->form_name('EditCustomFields');
49
50 # Sort by numeric IDs in names
51 my @names = map  { $_->[1] }
52             sort { $a->[0] <=> $b->[0] }
53             map  { /Object-1-CF-(\d+)/ ? [ $1 => $_ ] : () }
54             map  $_->name, $m->current_form->inputs;
55 my $tcf = pop(@names);
56 $m->field( $tcf => 1 );         # Associate the new CF with this queue
57 $m->field( $_ => undef ) for @names;    # ...and not any other. ;-)
58 $m->submit;
59
60 $m->content_like( qr/Object created/, 'TCF added to the queue' );
61
62 $m->submit_form(
63     form_name => "CreateTicketInQueue",
64     fields => { Queue => 'General' },
65 );
66
67 $m->content_like(qr/Upload multiple images/, 'has a upload image field');
68
69 $tcf =~ /(\d+)$/ or die "Hey this is impossible dude";
70 my $upload_field = "Object-RT::Ticket--CustomField-$1-Upload";
71
72 $m->submit_form(
73     form_name => "TicketCreate",
74     fields => {
75         $upload_field => ImageFile,
76         Subject => 'testing img cf creation',
77     },
78 );
79
80 $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
81
82 my $id = $1 if $m->content =~ /Ticket (\d+) created/;
83
84 $m->title_like(qr/testing img cf creation/, "its title is the Subject");
85
86 $m->follow_link( text => 'bplogo.gif' );
87 $m->content_is(ImageFileContent, "it links to the uploaded image");
88
89 $m->get( BaseURL );
90
91 $m->follow_link( text => 'Tickets' );
92 $m->follow_link( text => 'New Query' );
93
94 $m->title_is(q/Query Builder/, 'Query building');
95 $m->submit_form(
96     form_name => "BuildQuery",
97     fields => {
98         idOp => '=',
99         ValueOfid => $id,
100         ValueOfQueue => 'General',
101     },
102     button => 'AddClause',
103 );
104
105 $m->form_name('BuildQuery');
106
107 my $col = ($m->current_form->find_input('SelectDisplayColumns'))[-1];
108 $col->value( ($col->possible_values)[-1] );
109
110 $m->click('AddCol');
111
112 $m->form_name('BuildQuery');
113 $m->click('DoSearch');
114
115 $m->follow_link( text_regex => qr/bplogo\.gif/ );
116 $m->content_is(ImageFileContent, "it links to the uploaded image");
117
118 __END__
119 [FC] Bulk Update does not have custom fields.