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