7 if (eval { require GD }) {
8 RT::Test->import(tests => 15);
11 RT::Test->import(skip_all => 'GD required.');
17 my $root = RT::Test->load_or_create_user( Name => 'root' );
19 my ( $baseurl, $m ) = RT::Test->started_ok;
20 ok( $m->login, 'logged in' );
21 my $ticket = RT::Ticket->new( $RT::SystemUser );
24 Subject => 'test äöü',
26 ok( $ticket->id, 'created ticket' );
28 $m->get_ok(q{/Search/Chart.html?Query=Subject LIKE 'test äöü'});
30 form_name => 'SaveSearch',
32 SavedSearchDescription => 'chart foo',
33 SavedSearchOwner => 'RT::User-' . $root->id,
35 button => 'SavedSearchSave',
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' );
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');
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');
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
67 my @mails = RT::Test->fetch_caught_mails;
68 is @mails, 1, "got a dashboard mail";
70 # can't use parse_mail here is because it deletes all attachments
71 # before we can call bodyhandle :/
73 my $parser = RT::EmailParser->new;
74 my $mail = $parser->ParseMIMEEntityFromScalar( $mails[0] );
76 $mail->head->get('Subject'),
77 qr/Daily Dashboard: dashboard foo/,
81 my ($mail_image) = grep { $_->mime_type eq 'image/png' } $mail->parts;
82 ok( $mail_image, 'mail contains image attachment' );
84 my $handle = $mail_image->bodyhandle;
86 my $mail_image_data = '';
87 if ( my $io = $handle->open('r') ) {
88 while ( defined( $_ = $io->getline ) ) { $mail_image_data .= $_ }
91 is( $mail_image_data, $image, 'image in mail is the same one in web' );