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