[Bps-public-commit] r11235 - WebChart/t

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Mar 27 11:20:47 EDT 2008


Author: sunnavy
Date: Thu Mar 27 11:20:46 2008
New Revision: 11235

Modified:
   WebChart/t/chart.t

Log:
added tests for GD::Graph renderer

Modified: WebChart/t/chart.t
==============================================================================
--- WebChart/t/chart.t	(original)
+++ WebChart/t/chart.t	Thu Mar 27 11:20:46 2008
@@ -2,79 +2,95 @@
 use warnings;
 
 use lib 't/lib';
-use Test::More qw/no_plan/;
+use Test::More tests => 18;
 use WebChart::Test qw/is_file/;
 use WebChart::Renderer::Chart;
+use WebChart::Renderer::GD::Graph;
 
-my $renderer = WebChart::Renderer::Chart->new();
-isa_ok( $renderer, 'WebChart::Renderer::Chart' );
-
-my $data = [
-    [ '2004', '2005', '2006', '2007' ],    # labels
-    [ 14,     15,     17,     22 ],        # first data set
-    [ 22,     25,     20,     21 ],        # second data set
-];
-
-my ( $seg, $file ) = $renderer->render(
-    type    => 'bars',
-    data    => $data,
-);
-
-is_file(
-    $file,
-    't/data/chart_bars_400x300.png',
-    'default width is 400, heigth is 300'
-);
-
-like( $seg, qr{<img src="/charts/.*png" />}, 'default web_img_dir is /charts' );
-
-( $seg, $file ) = $renderer->render(
-    type        => 'bars',
-    data        => $data,
-    width       => 800,
-    height      => 600,
-    web_img_dir => '/pictures',
-);
-
-is_file(
-    $file,
-    't/data/chart_bars_800x600.png',
-    'width and height args work',
-);
-like( $seg, qr{<img src="/pictures/.*png" />}, 'web_img_dir arg works' );
-
-$seg = $renderer->render(
-    type      => 'bars',
-    data      => $data,
-    css_class => 'foo bar',
-);
-
-like(
-    $seg,
-    qr{<img src="/charts/.*png" class="foo bar" />},
-    'render bars with css class works'
-);
-
-$seg = $renderer->render(
-    type      => 'bars',
-    data      => $data,
-    css_class => ' ',
-);
-
-like(
-    $seg,
-    qr{<img src="/charts/.*png" />},
-    'html segment will not contail class=.. if css_class is just blank',
-);
-
-# Pie
-
-( $seg, $file ) = $renderer->render(
-    type   => 'pie',
-    data   => $data,
-);
-
-like( $seg, qr{<img src="/charts/.*png" />}, 'render pie works' );
-
-is_file( $file, 't/data/chart_pie_400x300.png', 'generated pie is right' );
+my %map = (
+    'WebChart::Renderer::Chart'     => 'chart',
+    'WebChart::Renderer::GD::Graph' => 'gd_graph',
+);
+
+for my $module ( keys %map ) {
+    my $renderer = $module->new();
+    isa_ok( $renderer, $module );
+
+    my $data = [
+        [ '2004', '2005', '2006', '2007' ],    # labels
+        [ 14,     15,     17,     22 ],        # first data set
+        [ 22,     25,     20,     21 ],        # second data set
+    ];
+
+    my ( $seg, $file ) = $renderer->render(
+        type => 'bars',
+        data => $data,
+    );
+
+    is_file(
+        $file,
+        "t/data/$map{$module}_bars_400x300.png",
+        'default width is 400, heigth is 300'
+    );
+
+    like(
+        $seg,
+        qr{<img src="/charts/.*png" />},
+        'default web_img_dir is /charts'
+    );
+
+    ( $seg, $file ) = $renderer->render(
+        type        => 'bars',
+        data        => $data,
+        width       => 800,
+        height      => 600,
+        web_img_dir => '/pictures',
+    );
+
+    is_file(
+        $file,
+        "t/data/$map{$module}_bars_800x600.png",
+        'width and height args work',
+    );
+    like( $seg, qr{<img src="/pictures/.*png" />}, 'web_img_dir arg works' );
+
+    $seg = $renderer->render(
+        type      => 'bars',
+        data      => $data,
+        css_class => 'foo bar',
+    );
+
+    like(
+        $seg,
+        qr{<img src="/charts/.*png" class="foo bar" />},
+        'render bars with css class works'
+    );
+
+    $seg = $renderer->render(
+        type      => 'bars',
+        data      => $data,
+        css_class => ' ',
+    );
+
+    like(
+        $seg,
+        qr{<img src="/charts/.*png" />},
+        'html segment will not contail class=.. if css_class is just blank',
+    );
+
+    # Pie
+
+    ( $seg, $file ) = $renderer->render(
+        type => 'pie',
+        data => $data,
+    );
+
+    like( $seg, qr{<img src="/charts/.*png" />}, 'render pie works' );
+
+    is_file(
+        $file,
+        "t/data/$map{$module}_pie_400x300.png",
+        'generated pie is right'
+    );
 
+}



More information about the Bps-public-commit mailing list