diff --git a/t/Account.t b/t/Account.t index 22d38d3ad..8d95473d6 100644 --- a/t/Account.t +++ b/t/Account.t @@ -1,76 +1,6 @@ -# vim:syntax=perl -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2009 Plain Black Corporation. -#------------------------------------------------------------------- -# Please read the legal notices (docs/legal.txt) and the license -# (docs/license.txt) that came with this distribution before using -# this software. -#------------------------------------------------------------------ -# http://www.plainblack.com info@plainblack.com -#------------------------------------------------------------------ - -# This tests the operation of WebGUI::Account modules. You can use -# as a base to test your own modules. - use FindBin; -use strict; use lib "$FindBin::Bin/lib"; -use Test::More; -use WebGUI::Test; # Must use this before any other WebGUI modules -use WebGUI::Session; +use Test::WebGUI::Account; +use Test::WebGUI::Account::Friends; -#---------------------------------------------------------------------------- -# Init -my $session = WebGUI::Test->session; - - -#---------------------------------------------------------------------------- -# Tests - -plan tests => 7; # Increment this number for each test you create - -#---------------------------------------------------------------------------- -# Test the creation of WebGUI::Account - -# Can we load WebGUI::Account? -use_ok( "WebGUI::Account" ); - -SKIP: { # Not everyone has Test::Exception yet - eval { require Test::Exception; import Test::Exception }; - # Skip 1 test if Test::Exception couldn't be loaded - skip 1, 'Test::Exception not found' if $@; - throws_ok( sub { WebGUI::Account->new }, 'WebGUI::Error::InvalidObject', - 'new() throws exception without session object' - ); -}; - -my $account; -# ok() tests booleans. assignment evaluates to the value assigned (it's how '$a = $b = 4' works) -ok( $account = WebGUI::Account->new( $session ), - "WebGUI::Account object created successfully" -); - -# Test $account->isa -isa_ok( $account, "WebGUI::Account", 'Blessed into the right class' ); - -#---------------------------------------------------------------------------- -# Test getUrl - -is( $account->getUrl, $session->url->page('op=account;module=;do='.$account->method), - 'getUrl adds op, module, and do since no method has been set' -); - -is( $account->getUrl( 'foo=bar' ), $session->url->page( 'op=account;foo=bar' ), - 'getUrl adds op if passed other parameters' -); - -is( $account->getUrl( 'op=account' ), $session->url->page( 'op=account' ), - 'getUrl doesnt add op=account if already exists' -); - -#---------------------------------------------------------------------------- -# Cleanup -END { - -} -#vim:ft=perl +Test::Class->runtests; diff --git a/t/Account/Friends.t b/t/Account/Friends.t new file mode 100644 index 000000000..169092acd --- /dev/null +++ b/t/Account/Friends.t @@ -0,0 +1,76 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# This tests the operation of WebGUI::Account modules. You can use +# as a base to test your own modules. + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; +use Test::More; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +#---------------------------------------------------------------------------- +# Init +my $session = WebGUI::Test->session; + + +#---------------------------------------------------------------------------- +# Tests + +plan tests => 7; # Increment this number for each test you create + +#---------------------------------------------------------------------------- +# Test the creation of WebGUI::Account::Friends + +# Can we load it? +use_ok( "WebGUI::Account::Friends" ); + +SKIP: { # Not everyone has Test::Exception yet + eval { require Test::Exception; import Test::Exception }; + # Skip 1 test if Test::Exception couldn't be loaded + skip 1, 'Test::Exception not found' if $@; + throws_ok( sub { WebGUI::Account::Friends->new }, 'WebGUI::Error::InvalidObject', + 'new() throws exception without session object' + ); +}; + +my $friends; +# ok() tests booleans. assignment evaluates to the value assigned (it's how '$a = $b = 4' works) +ok( $account = WebGUI::Account->new( $session ), + "WebGUI::Account object created successfully" +); + +# Test $account->isa +isa_ok( $account, "WebGUI::Account", 'Blessed into the right class' ); + +#---------------------------------------------------------------------------- +# Test getUrl + +is( $account->getUrl, $session->url->page('op=account;module=;do='.$account->method), + 'getUrl adds op, module, and do since no method has been set' +); + +is( $account->getUrl( 'foo=bar' ), $session->url->page( 'op=account;foo=bar' ), + 'getUrl adds op if passed other parameters' +); + +is( $account->getUrl( 'op=account' ), $session->url->page( 'op=account' ), + 'getUrl doesnt add op=account if already exists' +); + +#---------------------------------------------------------------------------- +# Cleanup +END { + +} +#vim:ft=perl diff --git a/t/lib/Test/WebGUI/Account.pm b/t/lib/Test/WebGUI/Account.pm new file mode 100644 index 000000000..de097d229 --- /dev/null +++ b/t/lib/Test/WebGUI/Account.pm @@ -0,0 +1,75 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# This tests the operation of WebGUI::Account modules. You can use +# as a base to test your own modules. + +package Test::WebGUI::Account; + +use FindBin; +use strict; +use lib "$FindBin::Bin/lib"; +use base 'Test::Class'; +use Test::More; +use Test::Exception; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +sub class { + return 'WebGUI::Account'; +} + +sub __useItFirst : Test(startup) { + my $test = shift; + my $class = $test->class; + eval "use $class"; + die $@ if $@; + my $session = WebGUI::Test->session; + $test->{_session} = $session; +} + +sub _new : Test(3) { + my $test = shift; + my $session = $test->{_session}; + my $class = $test->class; + throws_ok( + sub { $class->new }, 'WebGUI::Error::InvalidObject', + 'new() throws exception without session object' + ); + my $account; + ok( $account = $class->new( $session ), + "$class object created successfully" + ); + isa_ok( $account, $class, 'Blessed into the right class' ); +} + +sub getUrl : Test(3) { + my $test = shift; + my $session = $test->{_session}; + my $class = $test->class; + my $account = $class->new($session); + is( $account->getUrl, $session->url->page('op=account;module=;do='.$account->method), + 'getUrl adds op, module, and do since no method has been set' + ); + + is( $account->getUrl( 'foo=bar' ), $session->url->page( 'op=account;foo=bar' ), + 'getUrl adds op if passed other parameters' + ); + + is( $account->getUrl( 'op=account' ), $session->url->page( 'op=account' ), + 'getUrl doesnt add op=account if already exists' + ); + +} + +1; + +#vim:ft=perl diff --git a/t/lib/Test/WebGUI/Account/Friends.pm b/t/lib/Test/WebGUI/Account/Friends.pm new file mode 100644 index 000000000..3d939fb5f --- /dev/null +++ b/t/lib/Test/WebGUI/Account/Friends.pm @@ -0,0 +1,32 @@ +# vim:syntax=perl +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2009 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------ +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------ + +# This tests the operation of WebGUI::Account modules. You can use +# as a base to test your own modules. + +package Test::WebGUI::Account::Friends; + +use FindBin; +use strict; +use lib "$FindBin::Bin/lib"; +use base 'Test::WebGUI::Account'; +use Test::More; +use Test::Exception; +use WebGUI::Test; # Must use this before any other WebGUI modules +use WebGUI::Session; + +sub class { + return 'WebGUI::Account::Friends'; +} + +1; + +#vim:ft=perl