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