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