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