[Bps-public-commit] r11191 - in WebChart/t: .

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Mar 25 23:50:03 EDT 2008


Author: sunnavy
Date: Tue Mar 25 23:50:03 2008
New Revision: 11191

Added:
   WebChart/t/chart.t
   WebChart/t/data/
   WebChart/t/data/chart_bars_400x300.png   (contents, props changed)
   WebChart/t/data/chart_bars_800x600.png   (contents, props changed)
   WebChart/t/data/chart_pie_400x300.png   (contents, props changed)

Log:
added tests for Chart renderer

Added: WebChart/t/chart.t
==============================================================================
--- (empty file)
+++ WebChart/t/chart.t	Tue Mar 25 23:50:03 2008
@@ -0,0 +1,97 @@
+use strict;
+use warnings;
+
+use Test::More qw/no_plan/;
+
+use WebChart;
+
+# default renderer is Chart
+my $wc = WebChart->new( renderer => 'Chart' );
+isa_ok( $wc, 'WebChart' );
+isa_ok( $wc->renderer, 'WebChart::Renderer::Chart' );
+
+$wc = WebChart->new();
+isa_ok( $wc->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 ) = $wc->render(
+    type => 'bars',
+    data => $data,
+);
+
+my ( $x, $y );                             # for file content compare
+
+{
+    local $/;
+    my $fh;
+    open $fh, '<', $file;
+    $x = <$fh>;
+    open $fh, '<', 't/data/chart_bars_400x300.png';
+    $y = <$fh>;
+}
+
+is( $x, $y, 'generated bars is right' );
+
+like( $seg, qr{<img src="/charts/.*png" />}, 'render bars works' );
+
+( $seg, $file ) = $wc->render(
+    type   => 'bars',
+    width  => 800,
+    height => 600,
+    data   => $data,
+);
+
+{
+    local $/;
+    my $fh;
+    open $fh, '<', $file;
+    $x = <$fh>;
+    open $fh, '<', 't/data/chart_bars_800x600.png';
+    $y = <$fh>;
+}
+
+is( $x, $y, 'width and height args works' );
+
+$seg = $wc->render(
+    type        => 'bars',
+    data        => $data,
+    css_classes => [ 'foo', 'bar' ],
+);
+
+like(
+    $seg,
+    qr{<img src="/charts/.*png" class="foo bar" />},
+    'render bars with classes works'
+);
+
+# Pie
+
+($seg, $file) = $wc->render(
+    type        => 'pie',
+    data        => $data,
+);
+
+like(
+    $seg,
+    qr{<img src="/charts/.*png"/>},
+    'render bars with classes works'
+);
+
+{
+    local $/;
+    my $fh;
+    open $fh, '<', $file;
+    $x = <$fh>;
+    open $fh, '<', 't/data/chart_pie_400x300.png';
+    $y = <$fh>;
+}
+
+is( $x, $y, 'generated pie is right' );
+
+like( $seg, qr{<img src="/charts/.*png" />}, 'render pie works' );
+

Added: WebChart/t/data/chart_bars_400x300.png
==============================================================================
Binary file. No diff available.

Added: WebChart/t/data/chart_bars_800x600.png
==============================================================================
Binary file. No diff available.

Added: WebChart/t/data/chart_pie_400x300.png
==============================================================================
Binary file. No diff available.



More information about the Bps-public-commit mailing list