first pass RT4 merge, RT#13852
[freeside.git] / rt / t / articles / upload-customfields.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 20;
7
8 use RT;
9 my $logo;
10 BEGIN {
11     $logo =
12       -e $RT::MasonComponentRoot . '/NoAuth/images/bpslogo.png'
13       ? 'bpslogo.png'
14       : 'bplogo.gif';
15 }
16
17 use constant ImageFile => $RT::MasonComponentRoot . "/NoAuth/images/$logo";
18
19 use constant ImageFileContent => do {
20     local $/;
21     open my $fh, '<', ImageFile or die ImageFile.$!;
22     binmode($fh);
23     scalar <$fh>;
24 };
25
26 use RT::Class;
27 my $class = RT::Class->new($RT::SystemUser);
28 my ($ret, $msg) = $class->Create('Name' => 'tlaTestClass-'.$$,
29                               'Description' => 'A general-purpose test class');
30 ok($ret, "Test class created");
31
32
33 my ($url, $m) = RT::Test->started_ok;
34 isa_ok($m, 'Test::WWW::Mechanize');
35 ok($m->login, 'logged in');
36 $m->follow_link_ok( { text => 'Configuration' } );
37 $m->title_is(q/RT Administration/, 'admin screen');
38 $m->follow_link_ok( { text => 'Custom Fields' } );
39 $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
40 $m->follow_link_ok( { text => 'Create', url_regex => qr{^/Admin/CustomFields/} } );
41 $m->submit_form(
42     form_name => "ModifyCustomField",
43     fields => {
44         TypeComposite => 'Image-0',
45         LookupType => 'RT::Class-RT::Article',
46         Name => 'img'.$$,
47         Description => 'img',
48     },
49 );
50 $m->title_is(qq/Editing CustomField img$$/, 'admin-cf created');
51 $m->follow_link( text => 'Applies to' );
52 $m->title_is(qq/Modify associated objects for img$$/, 'pick cf screenadmin screen');
53 $m->form_number(3);
54
55 my $tcf = (grep { /AddCustomField-/ } map { $_->name } $m->current_form->inputs )[0];
56 $m->tick( $tcf, 0 );         # Associate the new CF with this queue
57 $m->click('UpdateObjs');
58 $m->content_like( qr/Object created/, 'TCF added to the queue' );
59
60 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
61     'UI -> Articles' );
62 $m->follow_link( text => 'New Article');
63
64 $m->follow_link( url_regex => qr/Edit.html\?Class=1/ );
65 $m->title_is(qq/Create a new article/);
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::Article--CustomField-$1-Upload";
71
72 diag("Uploading an image to $upload_field") if $ENV{TEST_VERBOSE};
73
74 $m->submit_form(
75     form_name => "EditArticle",
76     fields => {
77         $upload_field => ImageFile,
78         Name => 'Image Test '.$$,
79         Summary => 'testing img cf creation',
80     },
81 );
82
83 $m->content_like(qr/Article \d+ created/, "an article was created succesfully");
84
85 my $id = $1 if $m->content =~ /Article (\d+) created/;
86
87 $m->title_like(qr/Modify article #$id/, "Editing article $id");
88
89 $m->follow_link( text => $logo );
90 $m->content_is(ImageFileContent, "it links to the uploaded image");