From 78c33c54ff5d35bb8dc33b6bc3fde59a86fb683f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 30 Jul 2006 07:39:49 +0000 Subject: [PATCH] Added corner tests for empty string and undef. Converted tests to handle skipping if the macro can't be loaded. --- t/Macro/FetchMimeType.t | 25 +++++++++++++++++++++++-- t/Macro/FileUrl.t | 19 ++++++++++++++++--- t/Macro/FormParam.t | 22 ++++++++++++++++++++-- t/Macro/GroupAdd.t | 13 +++++++++++-- t/Macro/GroupDelete.t | 12 +++++++++++- 5 files changed, 81 insertions(+), 10 deletions(-) diff --git a/t/Macro/FetchMimeType.t b/t/Macro/FetchMimeType.t index c88436ef5..ef0b9dc13 100644 --- a/t/Macro/FetchMimeType.t +++ b/t/Macro/FetchMimeType.t @@ -13,7 +13,6 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; -use WebGUI::Macro::FetchMimeType; use WebGUI::Session; use Test::More; # increment this value for each test you create @@ -41,15 +40,37 @@ my @testSets = ( output => 'application/octet-stream', comment => q|octet-stream for unknown type|, }, + { + input => '', + output => 'application/octet-stream', + comment => q|Null path returns application/octet-stream|, + }, + { + input => undef, + output => undef, + comment => q|Undef path returns undef|, + }, ); my $numTests = scalar @testSets; +$numTests += 1; #For the use_ok + plan tests => $numTests; +my $macro = 'WebGUI::Macro::FetchMimeType'; +my $loaded = use_ok($macro); + +SKIP: { + +skip "Unable to load $macro", $numTests-1 unless $loaded; + foreach my $testSet (@testSets) { - my $file = join '/', WebGUI::Test->root, 'www/extras', $testSet->{input}; + my $file = $testSet->{input} + ? join '/', WebGUI::Test->root, 'www/extras', $testSet->{input} + : $testSet->{input}; my $output = WebGUI::Macro::FetchMimeType::process($session, $file); is($output, $testSet->{output}, $testSet->{comment} ); } +} diff --git a/t/Macro/FileUrl.t b/t/Macro/FileUrl.t index ce24ced0b..215a08453 100644 --- a/t/Macro/FileUrl.t +++ b/t/Macro/FileUrl.t @@ -13,7 +13,6 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; -use WebGUI::Macro::FileUrl; use WebGUI::Session; use WebGUI::Storage; use Data::Dumper; @@ -85,10 +84,22 @@ my @testSets = ( ); -plan tests => scalar(@testSets) + 1; +my $numTests = scalar(@testSets); +$numTests += 1; #For the use_ok +$numTests += 1; #non-existant URL + +plan tests => $numTests; + +my $macro = 'WebGUI::Macro::FileUrl'; +my $loaded = use_ok($macro); + +my $versionTag; + +SKIP: { + +skip "Unable to load $macro", $numTests-1 unless $loaded; my $homeAsset = WebGUI::Asset->getDefault($session); -my $versionTag; ($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets); @@ -105,6 +116,8 @@ foreach my $testSet (@testSets) { my $output = WebGUI::Macro::FileUrl::process($session, "non-existant-url"); is($output, $i18n->get('invalid url'), "Non-existant url returns error message"); +} + sub setupTest { my ($session, $homeAsset, @testSets) = @_; my $versionTag = WebGUI::VersionTag->getWorking($session); diff --git a/t/Macro/FormParam.t b/t/Macro/FormParam.t index c099ab995..9b1923309 100644 --- a/t/Macro/FormParam.t +++ b/t/Macro/FormParam.t @@ -53,12 +53,30 @@ my @testSets = ( my $numTests = scalar @testSets; -plan tests => $numTests + 2; +$numTests += 1; ##use_ok +$numTests += 1; ##testBlock has no name collisions +$numTests += 3; ##TODO block -use_ok('WebGUI::Macro::FormParam'); +plan tests => $numTests; + +my $macro = 'WebGUI::Macro::FormParam'; +my $loaded = use_ok($macro); + +SKIP: { + +skip "Unable to load $macro", $numTests-1 unless $loaded; auto_check($session, \@testSets); +} + +TODO: { + local $TODO = "Tests to write later"; + ok(0, "What will this do with a non-existant form param?"); + ok(0, "Also try null"); + ok(0, "Also try undef"); +} + sub auto_check { my ($session, $testBlock) = @_; my $origSessionRequest = $session->{_request}; diff --git a/t/Macro/GroupAdd.t b/t/Macro/GroupAdd.t index 317fd3868..8e4e86a27 100644 --- a/t/Macro/GroupAdd.t +++ b/t/Macro/GroupAdd.t @@ -13,7 +13,6 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; -use WebGUI::Macro::GroupAdd; use WebGUI::Session; use Data::Dumper; @@ -115,13 +114,21 @@ my @testSets = ( ); my $numTests = 0; - foreach my $testSet (@testSets) { $numTests += 1 + ($testSet->{empty} == 0); } +$numTests += 1; #For the use_ok + plan tests => $numTests; +my $macro = 'WebGUI::Macro::GroupAdd'; +my $loaded = use_ok($macro); + +SKIP: { + +skip "Unable to load $macro", $numTests-1 unless $loaded; + foreach my $testSet (@testSets) { $session->user({ userId => $testSet->{userId} }); my $output = WebGUI::Macro::GroupAdd::process($session, @@ -137,6 +144,8 @@ foreach my $testSet (@testSets) { } } +} + sub setupTest { my ($session, $defaultNode) = @_; my @groups; diff --git a/t/Macro/GroupDelete.t b/t/Macro/GroupDelete.t index c4e6d4e76..0c9d94efd 100644 --- a/t/Macro/GroupDelete.t +++ b/t/Macro/GroupDelete.t @@ -13,7 +13,6 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; -use WebGUI::Macro::GroupDelete; use WebGUI::Session; use Data::Dumper; @@ -119,8 +118,17 @@ foreach my $testSet (@testSets) { $numTests += 1 + ($testSet->{empty} == 0); } +$numTests += 1; #For the use_ok + plan tests => $numTests; +my $macro = 'WebGUI::Macro::GroupDelete'; +my $loaded = use_ok($macro); + +SKIP: { + +skip "Unable to load $macro", $numTests-1 unless $loaded; + foreach my $testSet (@testSets) { $session->user({ userId => $testSet->{userId} }); my $output = WebGUI::Macro::GroupDelete::process($session, @@ -136,6 +144,8 @@ foreach my $testSet (@testSets) { } } +} + sub setupTest { my ($session, $defaultNode) = @_; my @groups;