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

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Mar 27 06:31:02 EDT 2008


Author: sunnavy
Date: Thu Mar 27 06:30:45 2008
New Revision: 11229

Added:
   WebChart/t/webchart.t

Log:
added webchart.t

Added: WebChart/t/webchart.t
==============================================================================
--- (empty file)
+++ WebChart/t/webchart.t	Thu Mar 27 06:30:45 2008
@@ -0,0 +1,88 @@
+use strict;
+use warnings;
+
+use lib 't/lib';
+use WebChart;
+use WebChart::Test qw/is_file/;
+use File::Spec;
+
+use Test::More tests => 24;
+
+my $wc      = WebChart->new;
+my %default = (
+    img_dir     => File::Spec->tmpdir,
+    web_img_dir => '/charts',
+    width       => 400,
+    height      => 300,
+    css_class   => undef,
+);
+
+for ( keys %default ) {
+    is( $wc->$_, $default{$_},
+        "default $_ is " . ( defined $default{$_} ? $default{$_} : 'undef' ) );
+}
+
+my %args = (
+    img_dir     => '/tmp',
+    web_img_dir => '/pictures',
+    width       => 800,
+    height      => 600,
+    css_class   => 'foo bar',
+);
+
+$wc = WebChart->new(%args);
+
+for ( keys %args ) {
+    is( $wc->$_, $args{$_}, "$_ arg works" );
+    $wc->$_( $args{$_} . 00 );
+    is( $wc->$_, $args{$_} . 00, "set $_ works" );
+}
+
+# more css_class tests
+$wc = WebChart->new;
+eval { $wc->css_classes };
+ok( $@, 'css_classes is renamed to css_class' );
+ok( ref $wc->css_class ne 'ARRAY', 'css_class is string, not array any more' );
+
+$wc = WebChart->new( renderer => 'Chart' );
+isa_ok( $wc, 'WebChart' );
+isa_ok( $wc->renderer, 'WebChart::Renderer::Chart' );
+
+# default renderer is Chart
+$wc = WebChart->new();
+isa_ok( $wc->renderer, 'WebChart::Renderer::Chart' );
+$wc = WebChart->new( renderer => 'Fake' );
+isa_ok( $wc->renderer, 'WebChart::Renderer::Fake' );
+$wc = WebChart->new( renderer => 'WebChart::Renderer::Fake' );
+isa_ok( $wc->renderer, 'WebChart::Renderer::Fake' );
+
+my $data = [
+    [ '2004', '2005', '2006', '2007' ],    # labels
+    [ 14,     15,     17,     22 ],        # first data set
+    [ 22,     25,     20,     21 ],        # second data set
+];
+
+%args = ( data => $data );
+
+my %return = $wc->render(%args);
+is_deeply(
+    \%return,
+    { %default, %args },
+    "render sub has WebChart object's default value for args"
+);
+
+%args = (
+    data        => $data,
+    width       => 800,
+    height      => 600,
+    css_class   => 'foo bar',
+    img_dir     => '/howdy',
+    web_img_dir => '/world'
+);
+%return = $wc->render(%args);
+is_deeply(
+    \%return,
+    { %default, %args },
+"args can be supplied that overwrides the WebChart object's default value"
+);
+



More information about the Bps-public-commit mailing list