[Jifty-commit] r3756 - in jifty/trunk: t/TestApp-Plugin-Chart/t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Tue Jul 31 23:03:26 EDT 2007
Author: sterling
Date: Tue Jul 31 23:03:26 2007
New Revision: 3756
Added:
jifty/trunk/t/TestApp-Plugin-Chart/t/gd_graph.t
Modified:
jifty/trunk/ (props changed)
jifty/trunk/t/TestApp-Plugin-Chart/t/chart.t
Log:
r8296 at dynpc145: andrew | 2007-07-31 22:03:08 -0500
Made the chart plugin test smarter and added one for the GD::Graph renderer.
Modified: jifty/trunk/t/TestApp-Plugin-Chart/t/chart.t
==============================================================================
--- jifty/trunk/t/TestApp-Plugin-Chart/t/chart.t (original)
+++ jifty/trunk/t/TestApp-Plugin-Chart/t/chart.t Tue Jul 31 23:03:26 2007
@@ -9,9 +9,22 @@
use GD;
use Jifty::SubTest;
-use Jifty::Test tests => 9;
+use Jifty::Test;
use Jifty::Test::WWW::Mechanize;
+eval "use Chart::Pie";
+if ($@) {
+ plan skip_all => 'Chart is not installed.';
+}
+else {
+ plan tests => 9;
+}
+
+use Jifty::Plugin::Chart::Renderer::Chart;
+
+(Jifty->find_plugin('Jifty::Plugin::Chart'))[0]
+ ->renderer('Jifty::Plugin::Chart::Renderer::Chart');
+
my $server = Jifty::Test->make_server;
ok($server, 'got a server');
@@ -20,7 +33,7 @@
my $mech = Jifty::Test::WWW::Mechanize->new;
$mech->get_ok($url . '/graphit', 'try getting /graphit');
-my $img_match = qr{<img src="(/chart/\w+/S\d+)" width="400" height="300"/>};
+my $img_match = qr{<img src="(/chart/chart/S\d+)" width="400" height="300"/>};
$mech->content_like($img_match, 'has an img tag');
my ($chart_path) = $mech->content =~ $img_match;
Added: jifty/trunk/t/TestApp-Plugin-Chart/t/gd_graph.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/TestApp-Plugin-Chart/t/gd_graph.t Tue Jul 31 23:03:26 2007
@@ -0,0 +1,58 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use lib 't/lib';
+
+# XXX FIXME This is here to prevent a segfault on my machine during testing.
+# -- sterling
+use GD;
+
+use Jifty::SubTest;
+use Jifty::Test;
+use Jifty::Test::WWW::Mechanize;
+
+eval "use GD::Graph::pie";
+if ($@) {
+ plan skip_all => 'GD::Graph is not installed.';
+}
+else {
+ plan tests => 9;
+}
+
+use Jifty::Plugin::Chart::Renderer::GD::Graph;
+
+(Jifty->find_plugin('Jifty::Plugin::Chart'))[0]
+ ->renderer('Jifty::Plugin::Chart::Renderer::GD::Graph');
+
+my $server = Jifty::Test->make_server;
+ok($server, 'got a server');
+
+my $url = $server->started_ok;
+
+my $mech = Jifty::Test::WWW::Mechanize->new;
+
+$mech->get_ok($url . '/graphit', 'try getting /graphit');
+my $img_match = qr{<img src="(/chart/gd_graph/S\d+)" width="400" height="300"/>};
+$mech->content_like($img_match, 'has an img tag');
+my ($chart_path) = $mech->content =~ $img_match;
+
+$mech->get_ok($url . $chart_path, 'try getting ' . $chart_path);
+
+my $response = $mech->response;
+is($response->header('Content-type'), 'image/png', 'content type set to png');
+
+SKIP: {
+ eval "use Image::Info qw/ image_info /";
+ skip "Image::Info is not installed", 3 if $@;
+
+ my $imgdata = $mech->content;
+ my $info = image_info(\$imgdata);
+
+ diag($info->{error}) if $info->{error};
+
+ is($info->{file_ext}, 'png', 'it is a png file');
+ is($info->{width}, 400, 'it is 400 pixels wide');
+ is($info->{height}, 300, 'it is 300 pixels tall');
+};
+
More information about the Jifty-commit
mailing list