diff --git a/t/Macro.t b/t/Macro.t index 491dc9472..886666c49 100644 --- a/t/Macro.t +++ b/t/Macro.t @@ -8,9 +8,8 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -use strict; - use FindBin; +use strict; use lib "$FindBin::Bin/lib"; use WebGUI::Test; diff --git a/t/POD.t b/t/POD.t index a3a331663..bbf9e6413 100644 --- a/t/POD.t +++ b/t/POD.t @@ -8,20 +8,21 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; +use Test::More; use Pod::Coverage; use File::Find; -# ---- END DO NOT EDIT ---- +use File::Spec; - -use Test::More; +plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD}; my @modules = (); -find(\&countModules, "../lib/WebGUI"); +find(\&countModules, File::Spec->catdir( WebGUI::Test->lib, 'WebGUI' ) ); my $moduleCount = scalar(@modules); diag("Planning on running $moduleCount tests\n"); plan tests => $moduleCount; @@ -37,7 +38,7 @@ sub countModules { return if $filename =~ m/WebGUI\/i18n/; return if $filename =~ m/WebGUI\/Help/; my $package = $filename; - $package =~ s/^\.\.\/lib\/(.*)\.pm$/$1/; + $package =~ s/^.*(WebGUI.*)\.pm$/$1/; $package =~ s/\//::/g; push(@modules,$package); } diff --git a/t/SQL.t b/t/SQL.t index 61baa11c2..8006ddb9d 100644 --- a/t/SQL.t +++ b/t/SQL.t @@ -8,17 +8,17 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; use WebGUI::Session; use Data::Dumper; -# ---- END DO NOT EDIT ---- use Test::More tests => 33; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; # read ok(my $sth = $session->db->read("select * from settings"), "read()"); @@ -145,25 +145,3 @@ is($setRowResult, 47, "setRow() - set data"); my $getRow = $session->db->getRow("incrementer","incrementerId",$setRowId); is($getRow->{nextValue}, 47, "getRow()"); $session->db->write("delete from incrementer where incrementerId=".$session->db->quote($setRowId)); - - -cleanup($session); # this line is required - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} - diff --git a/t/Session/DateTime.t b/t/Session/DateTime.t index 2c6b81b78..7ac1399c4 100644 --- a/t/Session/DateTime.t +++ b/t/Session/DateTime.t @@ -8,15 +8,16 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; use WebGUI::Session; -# ---- END DO NOT EDIT ---- + use Test::More tests => 22; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; my $wgbday = 997966800; ok($session->datetime->addToDate($wgbday,1,2,3) >= $wgbday+1*60*60*24*365+2*60*60*24*28+3*60*60*24, "addToDate()"); @@ -46,20 +47,3 @@ is($session->datetime->secondsToTime(60*60*8),"08:00:00", "secondsToTime()"); is($session->datetime->setToEpoch("2001-08-16 08:00:00"), $wgbday, "setToEpoch()"); ok($session->datetime->time() > $wgbday,"time()"); is($session->datetime->timeToSeconds("08:00:00"), 60*60*8, "timeToSeconds()"); - -cleanup($session); # this line is required - -# ---- DO NOT EDIT BELOW THIS LINE ----- -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} -sub cleanup { - my $session = shift; - $session->close(); -} diff --git a/t/Session/Env.t b/t/Session/Env.t index 56a809b10..98f922852 100644 --- a/t/Session/Env.t +++ b/t/Session/Env.t @@ -8,37 +8,15 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; -use WebGUI::Session; -# ---- END DO NOT EDIT ---- +use lib "$FindBin::Bin/../lib"; +use WebGUI::Test; +use WebGUI::Session; use Test::More tests => 1; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; ok($session->env->get("PATH") ne "", "get()"); - -cleanup($session); # this line is required - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} - diff --git a/t/Session/Id.t b/t/Session/Id.t index 341176f73..6af77e713 100644 --- a/t/Session/Id.t +++ b/t/Session/Id.t @@ -8,18 +8,17 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; -use WebGUI::Session; -# ---- END DO NOT EDIT ---- +use lib "$FindBin::Bin/../lib"; +use WebGUI::Test; +use WebGUI::Session; use Test::More tests => 2; # increment this value for each test you create use WebGUI::Utility; -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; # generate my $generateId = $session->id->generate(); @@ -33,24 +32,3 @@ for (1..2000) { push(@uniqueIds,$id); } ok($isUnique, "generate() - unique"); - -cleanup($session); # this line is required - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} - diff --git a/t/Session/Os.t b/t/Session/Os.t index 5ad42c4a2..d42a63d6d 100644 --- a/t/Session/Os.t +++ b/t/Session/Os.t @@ -8,38 +8,16 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; -use WebGUI::Session; -# ---- END DO NOT EDIT ---- +use lib "$FindBin::Bin/../lib"; +use WebGUI::Test; +use WebGUI::Session; use Test::More tests => 2; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; ok($session->os->get("name") ne "", "get(name)"); ok($session->os->get("type") eq "Windowsish" || $session->os->get("type") eq "Linuxish", "get(type)"); - -cleanup($session); # this line is required - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} - diff --git a/t/Session/Setting.t b/t/Session/Setting.t index 5e64953f4..6d778a2e1 100644 --- a/t/Session/Setting.t +++ b/t/Session/Setting.t @@ -8,15 +8,16 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; use WebGUI::Session; -# ---- END DO NOT EDIT ---- + use Test::More tests => 4; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; $session->setting->add("test","XXX"); my ($value) = $session->db->quickArray("select value from settings where name='test'"); @@ -28,20 +29,3 @@ is($value, 'YYY', "set()"); $session->setting->remove("test"); my ($value) = $session->db->quickArray("select value from settings where name='test'"); is($value, undef, "delete()"); - -cleanup($session); # this line is required - -# ---- DO NOT EDIT BELOW THIS LINE ----- -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} -sub cleanup { - my $session = shift; - $session->close(); -} diff --git a/t/Session/Stow.t b/t/Session/Stow.t index 1e6a13cf2..1b5a5f847 100644 --- a/t/Session/Stow.t +++ b/t/Session/Stow.t @@ -8,15 +8,16 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; use WebGUI::Session; -# ---- END DO NOT EDIT ---- + use Test::More tests => 22; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; # put your tests here @@ -36,20 +37,3 @@ $stow->delete("Test1"); is($stow->get("Test1"), undef, "delete()"); $stow->deleteAll; is($stow->get("Test2"), undef, "deleteAll()"); - -cleanup($session); # this line is required - -# ---- DO NOT EDIT BELOW THIS LINE ----- -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} -sub cleanup { - my $session = shift; - $session->close(); -} diff --git a/t/Session/Var.t b/t/Session/Var.t index c3764dfad..9c2dcea16 100644 --- a/t/Session/Var.t +++ b/t/Session/Var.t @@ -8,15 +8,16 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; use WebGUI::Session; -# ---- END DO NOT EDIT ---- + use Test::More tests => 6; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; ok($session->var->getId ne "", "getId()"); @@ -30,21 +31,3 @@ my $id = $session->var->getId; $session->var->end; my ($count) = $session->db->quickArray("select count(*) from userSession where sessionId=".$session->db->quote($id)); ok($count == 0,"end()"); - - -cleanup($session); # this line is required - -# ---- DO NOT EDIT BELOW THIS LINE ----- -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("../..",$configFile); -} -sub cleanup { - my $session = shift; - $session->close(); -} diff --git a/t/User.t b/t/User.t index f73b8576b..677deb0d0 100644 --- a/t/User.t +++ b/t/User.t @@ -8,17 +8,18 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; use WebGUI::Session; use WebGUI::Utility; -# ---- END DO NOT EDIT ---- + use WebGUI::User; use Test::More tests => 33; # increment this value for each test you create -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; my $user; my $lastUpdate; @@ -148,24 +149,3 @@ SKIP: { skip("uncache() -- Don't know how to test uncache()",1); ok(undef, "uncache"); } - -cleanup($session); # this line is required - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} - diff --git a/t/Utility.t b/t/Utility.t index b1e52e72d..af0b3cc79 100644 --- a/t/Utility.t +++ b/t/Utility.t @@ -9,17 +9,16 @@ #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; use WebGUI::Session; -# ---- END DO NOT EDIT ---- use Test::More tests => 21; # increment this value for each test you create -my $session = initialize(); # this line is required - +my $session = WebGUI::Test->session; # commify is(WebGUI::Utility::commify(10), "10", 'commify() - no comma needed'); @@ -86,25 +85,3 @@ SKIP: { skip("Don't know how to test sortHashDescending.",1); ok(undef, 'sortHashDescending()'); } - - -cleanup($session); # this line is required - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} - diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index 962d1b8cf..ecb7ea132 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -69,6 +69,10 @@ sub config { return $SESSION->config; } +sub lib { + return $WEBGUI_LIB; +} + sub session { return $SESSION; } diff --git a/t/mandatory_template_vars.t b/t/mandatory_template_vars.t index b19c0ba22..608c31c59 100644 --- a/t/mandatory_template_vars.t +++ b/t/mandatory_template_vars.t @@ -8,14 +8,14 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; use WebGUI::Asset; use WebGUI::Session; use File::Find; -# ---- END DO NOT EDIT ---- #The goal of this test is to check that mandatory template #variables exist in their templates. @@ -178,7 +178,7 @@ my @tmplVarTable = ( use Test::More; # increment this value for each test you create my $numTests = 0; -my $session = initialize(); # this line is required +my $session = WebGUI::Test->session; my @varTypes = qw( var loop if ); @@ -213,22 +213,4 @@ foreach my $tmpl ( @tmplVarTable ) { } } -cleanup($session); # this line is required - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} diff --git a/t/syntaxCheck.t b/t/syntaxCheck.t index 4e14a5d55..2e97a8b85 100644 --- a/t/syntaxCheck.t +++ b/t/syntaxCheck.t @@ -8,20 +8,21 @@ # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- -# ---- BEGIN DO NOT EDIT ---- +use FindBin; use strict; -use lib '../lib'; -use Getopt::Long; +use lib "$FindBin::Bin/lib"; + +use WebGUI::Test; use File::Find; use WebGUI::Session; -# ---- END DO NOT EDIT ---- +use Test::More; +plan skip_all => 'set TEST_SYNTAX to enable this test' unless $ENV{TEST_SYNTAX}; -use Test::More; # increment this value for each test you create my @modules; -my $wgLib = "../lib/"; +my $wgLib = WebGUI::Test->lib; diag("Checking modules in $wgLib"); -File::Find::find(\&getWebGUIModules, $wgLib); +File::Find::find( \&getWebGUIModules, $wgLib); my $numTests = scalar @modules; @@ -30,36 +31,11 @@ plan tests => $numTests; diag("Planning on $numTests tests"); foreach my $package (@modules) { - my $returnVal = system("export PERL5LIB=$wgLib; perl -wc $package"); + my $returnVal = system("$^X -I$wgLib -wc $package"); is($returnVal, 0, "syntax check for $package"); } -my $session = initialize(); # this line is required - -# put your tests here - -cleanup($session); # this line is required - #---------------------------------------- sub getWebGUIModules { - push(@modules,$File::Find::name) if /\.pm$/; + push( @modules, $File::Find::name ) if /\.pm$/; } - - -# ---- DO NOT EDIT BELOW THIS LINE ----- - -sub initialize { - $|=1; # disable output buffering - my $configFile; - GetOptions( - 'configFile=s'=>\$configFile - ); - exit 1 unless ($configFile); - my $session = WebGUI::Session->open("..",$configFile); -} - -sub cleanup { - my $session = shift; - $session->close(); -} -