4 use RT::Test tests => 15;
7 my $root = RT::Test->load_or_create_user( Name => 'root' );
9 my ( $baseurl, $m ) = RT::Test->started_ok;
10 ok( $m->login, 'logged in' );
11 my $ticket = RT::Ticket->new( $RT::SystemUser );
14 Subject => 'test äöü',
16 ok( $ticket->id, 'created ticket' );
18 $m->get_ok(q{/Search/Chart.html?Query=Subject LIKE 'test äöü'});
20 form_name => 'SaveSearch',
22 SavedSearchDescription => 'chart foo',
23 SavedSearchOwner => 'RT::User-' . $root->id,
25 button => 'SavedSearchSave',
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' );
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');
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');
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
57 my @mails = RT::Test->fetch_caught_mails;
58 is @mails, 1, "got a dashboard mail";
60 # can't use parse_mail here is because it deletes all attachments
61 # before we can call bodyhandle :/
63 my $parser = RT::EmailParser->new;
64 my $mail = $parser->ParseMIMEEntityFromScalar( $mails[0] );
66 $mail->head->get('Subject'),
67 qr/Daily Dashboard: dashboard foo/,
71 my ($mail_image) = grep { $_->mime_type eq 'image/png' } $mail->parts;
72 ok( $mail_image, 'mail contains image attachment' );
74 my $handle = $mail_image->bodyhandle;
76 my $mail_image_data = '';
77 if ( my $io = $handle->open('r') ) {
78 while ( defined( $_ = $io->getline ) ) { $mail_image_data .= $_ }
81 is( $mail_image_data, $image, 'image in mail is the same one in web' );