rt 4.2.14 (#13852)
[freeside.git] / rt / t / mail / dashboard-chart-with-utf8.t
1 use strict;
2 use warnings;
3
4 use RT::Test tests => undef;
5
6 plan skip_all => 'GD required'
7     unless GD->require;
8
9 my $root = RT::Test->load_or_create_user( Name => 'root' );
10
11 my ( $baseurl, $m ) = RT::Test->started_ok;
12 ok( $m->login, 'logged in' );
13 my $ticket = RT::Ticket->new( $RT::SystemUser );
14 $ticket->Create(
15     Queue   => 'General',
16     Subject => Encode::decode("UTF-8",'test äöü'),
17 );
18 ok( $ticket->id, 'created ticket' );
19
20 $m->get_ok(Encode::decode("UTF-8", q{/Search/Chart.html?Query=Subject LIKE 'test äöü'}));
21 $m->submit_form(
22     form_name => 'SaveSearch',
23     fields    => {
24         SavedSearchDescription => 'chart foo',
25         SavedSearchOwner       => 'RT::User-' . $root->id,
26         ChartStyle             => 'bar',
27     },
28     button => 'SavedSearchSave',
29 );
30
31 # first, create and populate a dashboard
32 $m->get_ok('/Dashboards/Modify.html?Create=1');
33 $m->form_name('ModifyDashboard');
34 $m->field( 'Name' => 'dashboard foo' );
35 $m->click_button( value => 'Create' );
36
37 $m->follow_link_ok( { text => 'Content' } );
38 my $form  = $m->form_name('Dashboard-Searches-body');
39 my @input = $form->find_input('Searches-body-Available');
40 my ($dashboards_component) =
41   map { ( $_->possible_values )[1] }
42   grep { ( $_->value_names )[1] =~ /^Chart/ } @input;
43 $form->value( 'Searches-body-Available' => $dashboards_component );
44 $m->click_button( name => 'add' );
45 $m->content_contains('Dashboard updated');
46
47 $m->follow_link_ok( { text => 'Subscription' } );
48 $m->form_name('SubscribeDashboard');
49 $m->field( 'Frequency' => 'daily' );
50 $m->field( 'Hour'      => '06:00' );
51 $m->click_button( name => 'Save' );
52 $m->content_contains('Subscribed to dashboard dashboard foo');
53
54 my $c     = $m->get(Encode::decode("UTF-8",q{/Search/Chart?Query=Subject LIKE 'test äöü'}));
55 my $image = $c->content;
56 RT::Test->run_and_capture(
57     command => $RT::SbinPath . '/rt-email-dashboards', all => 1
58 );
59
60 my @mails = RT::Test->fetch_caught_mails;
61 is @mails, 1, "got a dashboard mail";
62
63 # can't use parse_mail here is because it deletes all attachments
64 # before we can call bodyhandle :/
65 use RT::EmailParser;
66 my $parser = RT::EmailParser->new;
67 my $mail = $parser->ParseMIMEEntityFromScalar( $mails[0] );
68 like(
69     $mail->head->get('Subject'),
70     qr/Daily Dashboard: dashboard foo/,
71     'mail subject'
72 );
73
74 my ($mail_image) = grep { $_->mime_type eq 'image/png' } $mail->parts;
75 ok( $mail_image, 'mail contains image attachment' );
76
77 my $handle = $mail_image->bodyhandle;
78
79 my $mail_image_data = '';
80 if ( my $io = $handle->open('r') ) {
81     while ( defined( $_ = $io->getline ) ) { $mail_image_data .= $_ }
82     $io->close;
83 }
84 is( $mail_image_data, $image, 'image in mail is the same one in web' );
85
86 undef $m;
87 done_testing;