diff --git a/t/AdSpace.t b/t/AdSpace.t index a15488659..d92c109d2 100644 --- a/t/AdSpace.t +++ b/t/AdSpace.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::AdSpace::Ad; +use WebGUI::AdSpace; use Test::More; use Test::Deep; @@ -30,20 +31,13 @@ my $newAdSpaceSettings = { my $numTests = 35; # increment this value for each test you create $numTests += 2 * scalar keys %{ $newAdSpaceSettings }; -++$numTests; ##For conditional testing on module load plan tests => $numTests; -my $loaded = use_ok('WebGUI::AdSpace'); - my $session = WebGUI::Test->session; my ($adSpace, $alfred, $alfred2, $bruce, $catWoman, $villianClone, $defaultAdSpace ); my ($jokerAd, $penguinAd, $twoFaceAd); -SKIP: { - - skip "Unable to load WebGUI::AdSpace", $numTests-1 unless $loaded; - local $ENV{REMOTE_ADDR} = '10.0.0.1'; local $ENV{HTTP_USER_AGENT} = 'Mozilla/5.0'; @@ -223,7 +217,6 @@ SKIP: { $bruce->displayImpression(); ($jokerActive) = $session->db->quickArray('select isActive from advertisement where adId=?',[$jokerAd->getId]); is($jokerActive, 0, 'displayImpression deactivated jokerAd after two impressions'); -} END { foreach my $ad_space ($adSpace, $bruce, $alfred, $alfred2, $catWoman, $defaultAdSpace ) { diff --git a/t/AdSpace/Ad.t b/t/AdSpace/Ad.t index a34d3df48..c11daa9ac 100644 --- a/t/AdSpace/Ad.t +++ b/t/AdSpace/Ad.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::AdSpace; +use WebGUI::AdSpace::Ad; use Test::More; use Test::Deep; @@ -38,12 +39,9 @@ my $newAdSettings = { my $numTests = 33; # increment this value for each test you create $numTests += scalar keys %{ $newAdSettings }; -++$numTests; ##For conditional testing on module load plan tests => $numTests; -my $loaded = use_ok('WebGUI::AdSpace::Ad'); - my $session = WebGUI::Test->session; my $ad; my ($richAd, $textAd, $imageAd, $nonAd, $setAd); @@ -52,10 +50,6 @@ my $imageStorage = WebGUI::Storage->create($session); WebGUI::Test->addToCleanup($imageStorage); $imageStorage->addFileFromScalar('foo.bmp', 'This is not really an image'); -SKIP: { - - skip "Unable to load WebGUI::AdSpace::Ad", $numTests-1 unless $loaded; - local $ENV{REMOTE_ADDR} = '10.0.0.1'; local $ENV{HTTP_USER_AGENT} = 'Mozilla/5.0'; @@ -209,8 +203,6 @@ SKIP: { is($setAd->get('url'), '', 'set: clearing url'); is($setAd->get('adText'), '', 'set: clearing adText'); -} - END { foreach my $advertisement ($ad, $richAd, $textAd, $imageAd, $nonAd, $setAd) { if (defined $advertisement and ref $advertisement eq 'WebGUI::AdSpace::Ad') { diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index f88a910ca..3b231884b 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -308,10 +308,6 @@ $session->setting->set('urlExtension', undef); is($importNode->fixUrl('1234'.'-'x235 . 'abcdefghij'), '1234'.'-'x235 . 'abcdefghij', 'fixUrl leaves long URLs under 250 characters alone'); is($importNode->fixUrl('1234'.'-'x250 . 'abcdefghij'), '1234'.'-'x216, 'fixUrl truncates long URLs over 250 characters to 220 characters'); -WebGUI::Test->originalConfig('extrasURL'); -WebGUI::Test->originalConfig('uploadsURL'); -WebGUI::Test->originalConfig('assets'); - $session->config->set('extrasURL', '/extras'); $session->config->set('uploadsURL', '/uploads'); diff --git a/t/Asset/AssetExportHtml.t b/t/Asset/AssetExportHtml.t index 5d891fea0..0afff3008 100644 --- a/t/Asset/AssetExportHtml.t +++ b/t/Asset/AssetExportHtml.t @@ -17,7 +17,6 @@ use strict; use lib "$FindBin::Bin/../lib"; use Test::More; use WebGUI::Test; # Must use this before any other WebGUI modules -use WebGUI::PseudoRequest; use WebGUI::Session; use WebGUI::Asset; @@ -37,8 +36,6 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -WebGUI::Test->originalConfig('exportPath'); - my $testRan = 1; plan tests => 126; # Increment this number for each test you create diff --git a/t/Asset/Snippet.t b/t/Asset/Snippet.t index fcfd363d5..9071bbe4c 100644 --- a/t/Asset/Snippet.t +++ b/t/Asset/Snippet.t @@ -79,7 +79,6 @@ $snippet->update({ snippet => q|^SQL(select value from settings where name="");| }); -WebGUI::Test->originalConfig('macros'); $session->config->addToHash('macros', 'SQL', 'SQL'); is($snippet->view(), 'WebGUI', 'Interpolating macros in works with template in the correct order'); diff --git a/t/Asset/Template/HTMLTemplateExpr.t b/t/Asset/Template/HTMLTemplateExpr.t index ad5c9ddd8..ffba0fc83 100644 --- a/t/Asset/Template/HTMLTemplateExpr.t +++ b/t/Asset/Template/HTMLTemplateExpr.t @@ -69,7 +69,6 @@ sub setup_assets { } END { - $session->config->set('templateParsers', $originalParsers); if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { $versionTag->rollback; } diff --git a/t/Asset/Wobject/Survey/ExpressionEngine.t b/t/Asset/Wobject/Survey/ExpressionEngine.t index 0d1edcecd..a901adf64 100644 --- a/t/Asset/Wobject/Survey/ExpressionEngine.t +++ b/t/Asset/Wobject/Survey/ExpressionEngine.t @@ -36,7 +36,6 @@ SKIP: { my $e = "WebGUI::Asset::Wobject::Survey::ExpressionEngine"; - WebGUI::Test->originalConfig('enableSurveyExpressionEngine'); $session->config->set( 'enableSurveyExpressionEngine', 0 ); is( $e->run( $session, 'jump { 1 } target' ), undef, "Nothing happens unless we turn on enableSurveyExpressionEngine in config" ); diff --git a/t/Asset/Wobject/Survey/ResponseJSON.t b/t/Asset/Wobject/Survey/ResponseJSON.t index 3b31bccc2..1b40ea0df 100644 --- a/t/Asset/Wobject/Survey/ResponseJSON.t +++ b/t/Asset/Wobject/Survey/ResponseJSON.t @@ -336,7 +336,6 @@ cmp_deeply($rJSON->responseScores(indexBy => 'variable'), { s1q0 => 100, s1q1 => # #################################################### # Turn on the survey Expression Engine -WebGUI::Test->originalConfig('enableSurveyExpressionEngine'); $session->config->set('enableSurveyExpressionEngine', 1); $rJSON->survey->section([0])->{variable} = 's0'; $rJSON->survey->question([0,0])->{variable} = 's0q0'; # surveyOrder index = 0 diff --git a/t/Asset/Wobject/Survey/Test.t b/t/Asset/Wobject/Survey/Test.t index d4eb6d5ee..dfdb1919d 100644 --- a/t/Asset/Wobject/Survey/Test.t +++ b/t/Asset/Wobject/Survey/Test.t @@ -40,7 +40,6 @@ my $user = WebGUI::User->new( $session, 'new' ); WebGUI::Test->addToCleanup($user); my $import_node = WebGUI::Asset->getImportNode($session); -WebGUI::Test->originalConfig('enableSurveyExpressionEngine'); $session->config->set('enableSurveyExpressionEngine', 1); # Create a Survey diff --git a/t/AssetAspect/RssFeed.t b/t/AssetAspect/RssFeed.t index 5489e1b45..b869e8446 100644 --- a/t/AssetAspect/RssFeed.t +++ b/t/AssetAspect/RssFeed.t @@ -31,8 +31,6 @@ use WebGUI::Asset::RssAspectDummy; # Init my $session = WebGUI::Test->session; -WebGUI::Test->originalConfig('exportPath'); - #---------------------------------------------------------------------------- # Tests diff --git a/t/Config.t b/t/Config.t index f2d175716..a99c8eb58 100644 --- a/t/Config.t +++ b/t/Config.t @@ -85,6 +85,3 @@ if ($cookieName eq "") { $config->set('privateArray', ['a', 'b', 'c']); cmp_bag($config->get('privateArray'), ['a', 'b', 'c'], 'set: array, not scalar'); -END { - $config->delete('privateArray'); -} diff --git a/t/Group/resetGroupFields.t b/t/Group/resetGroupFields.t index cd5c333fb..0b91d2123 100644 --- a/t/Group/resetGroupFields.t +++ b/t/Group/resetGroupFields.t @@ -91,7 +91,6 @@ my $workflow = WebGUI::Workflow->create($session, ); WebGUI::Test->addToCleanup($workflow); -WebGUI::Test->originalConfig('workflowActivities'); $session->config->addToArray('workflowActivities/User', 'WebGUI::Workflow::Activity::AddUserToGroup'); my $userActivity = $workflow->addActivity('WebGUI::Workflow::Activity::AddUserToGroup'); diff --git a/t/Macro.t b/t/Macro.t index d0aecdec2..230d083c5 100644 --- a/t/Macro.t +++ b/t/Macro.t @@ -34,7 +34,6 @@ $registeredUser->username('TimBob'); WebGUI::Test->addToCleanup($registeredUser); $session->user({user => $registeredUser}); -WebGUI::Test->originalConfig('macros'); ##Overwrite any local configuration so that we know how to call it. foreach my $macro (qw/ GroupText LoginToggle PageTitle MacroStart MacroEnd MacroNest diff --git a/t/Operation/User/service.t b/t/Operation/User/service.t index 23494198c..632e72931 100644 --- a/t/Operation/User/service.t +++ b/t/Operation/User/service.t @@ -29,7 +29,6 @@ use Data::Dumper; #---------------------------------------------------------------------------- # Init my $session = WebGUI::Test->session; -WebGUI::Test->originalConfig( "serviceSubnets" ); $session->config->delete('serviceSubnets'); my ( $response, $responseObj, $auth, $userAndy, $userRed ); diff --git a/t/Session.t b/t/Session.t index b8e347083..2ae6121d5 100644 --- a/t/Session.t +++ b/t/Session.t @@ -55,6 +55,3 @@ $session->config->set('dbslave2', $slaveHash2); my $slave2 = $session->dbSlave; isa_ok($slave2, 'WebGUI::SQL'); -END { - $session->config->delete('dbslave2'); -} diff --git a/t/Session/Url.t b/t/Session/Url.t index d44eb9a0d..406651aaf 100644 --- a/t/Session/Url.t +++ b/t/Session/Url.t @@ -493,21 +493,4 @@ $session->config->set('sslEnabled', $origSSLEnabled); END { ##Always clean-up $session->asset($sessionAsset); $versionTag->rollback if defined $versionTag; - - $session->config->set('sitename', \@config_sitename); - $session->config->set('gateway', $gateway); - $session->config->set('extrasURL', $origExtras); - $session->config->set('sslEnabled', $origSSLEnabled) if defined $origSSLEnabled; - - if ($config_port) { - $session->config->set($config_port); - } - else { - $session->config->delete('webServerPort'); - } - if ($savecdn) { - $session->config->set('cdn', $savecdn); - } else { - $session->config->delete('cdn'); - } } diff --git a/t/Storage.t b/t/Storage.t index 7f6647766..cfdf26d07 100644 --- a/t/Storage.t +++ b/t/Storage.t @@ -91,7 +91,6 @@ is($guidStorage->getDirectoryId, $newGuid, '... getDirectoryId'); # #################################################### -WebGUI::Test->originalConfig('cdn'); $session->config->delete('cdn'); # Note: the CDN configuration will be reverted after CDN tests below diff --git a/t/User.t b/t/User.t index 2934e4f40..57386ce77 100644 --- a/t/User.t +++ b/t/User.t @@ -481,7 +481,6 @@ $dude->deleteFromGroups([12]); my $origEnvHash = $session->env->{_env}; my %newEnv = ( REMOTE_ADDR => '194.168.0.2' ); $session->env->{_env} = \%newEnv; -WebGUI::Test->originalConfig('adminModeSubnets'); $session->config->set('adminModeSubnets', ['194.168.0.0/24']); ok(!$dude->isInGroup(12), 'user is not in group 12'); @@ -833,7 +832,6 @@ isa_ok( $newCreateUser, 'WebGUI::User', 'create() returns a WebGUI::User' ); ################################################################ $session->setting->set('preventProxyCache', 0); -WebGUI::Test->originalConfig('profileModuleIdentifier'); my $profileModuleId = $session->config->get('profileModuleIdentifier'); is( $newFish->getProfileUrl('cellblock'), diff --git a/t/i18n/template.t b/t/i18n/template.t index 9c01299bb..e8b82bdb6 100644 --- a/t/i18n/template.t +++ b/t/i18n/template.t @@ -84,8 +84,3 @@ foreach my $label ( @questionableTemplates ) { sprintf "Empty template: %s, id: %s, url: %s", @{ $label }{qw/title id url/} ); } - -END { - defined $session && - $session->config->set('macros', $originalMacros); -} diff --git a/t/lib/WebGUI/Test.pm b/t/lib/WebGUI/Test.pm index e4fff6cef..6be047e74 100644 --- a/t/lib/WebGUI/Test.pm +++ b/t/lib/WebGUI/Test.pm @@ -30,48 +30,56 @@ use Test::MockObject; use Test::MockObject::Extends; use Log::Log4perl; # load early to ensure proper order of END blocks use Clone qw(clone); -use IO::Handle (); -use File::Spec (); -use IO::Select (); -use Cwd (); +use File::Basename qw(dirname fileparse); +use File::Spec::Functions qw(abs2rel rel2abs catdir catfile updir); use Scalar::Util qw( blessed ); -use List::MoreUtils qw( any ); use Carp qw( carp croak ); -use JSON qw( from_json to_json ); +use List::MoreUtils qw(any); +use File::Copy (); +use File::Temp (); +use Try::Tiny; +use Plack::Test; use Scope::Guard; use Try::Tiny; use WebGUI::Paths -inc; +use namespace::clean; -our $WEBGUI_TEST_ROOT = File::Spec->catdir( - File::Spec->catpath((File::Spec->splitpath(__FILE__))[0,1], ''), - (File::Spec->updir) x 2 -); -our $WEBGUI_TEST_COLLATERAL = File::Spec->catdir( +our $WEBGUI_TEST_ROOT = rel2abs( catdir( dirname( __FILE__ ), (updir) x 2 ) ); + +our $WEBGUI_TEST_COLLATERAL = catdir( $WEBGUI_TEST_ROOT, 'supporting_collateral' ); -use WebGUI::PseudoRequest; - our @EXPORT = qw(cleanupGuard addToCleanup); our @EXPORT_OK = qw(session config collateral); my $CLASS = __PACKAGE__; +my $original_config_file; sub import { - our $CONFIG_FILE = $ENV{ WEBGUI_CONFIG }; + if ( ! $original_config_file ) { + my $config = $ENV{WEBGUI_CONFIG}; + die "Enviroment variable WEBGUI_CONFIG must be set to the full path to a WebGUI config file.\n" + unless $config; - die "Enviroment variable WEBGUI_CONFIG must be set to the full path to a WebGUI config file.\n" - unless $CONFIG_FILE; - die "WEBGUI_CONFIG path '$CONFIG_FILE' does not exist.\n" - unless -e $CONFIG_FILE; - die "WEBGUI_CONFIG path '$CONFIG_FILE' is not a file.\n" - unless -f _; - die "WEBGUI_CONFIG path '$CONFIG_FILE' is not readable by effective uid '$>'.\n" - unless -r _; - - $CONFIG_FILE = File::Spec->abs2rel($CONFIG_FILE, WebGUI::Paths->configBase); + for my $tryPath ( + rel2abs( $config ), + rel2abs( $config, WebGUI::Paths->configBase ) + ) { + if ( -e $tryPath ) { + $config = $tryPath; + } + } + die "WEBGUI_CONFIG path '$config' does not exist.\n" + unless -e $config; + die "WEBGUI_CONFIG path '$config' is not a file.\n" + unless -f _; + die "WEBGUI_CONFIG path '$config' is not readable by effective uid '$>'.\n" + unless -r _; + $original_config_file = $config; + } goto &{ $_[0]->can('SUPER::import') }; } @@ -323,7 +331,7 @@ sub config { return $config if $config; require WebGUI::Config; - $config = WebGUI::Config->new(our $CONFIG_FILE); + $config = WebGUI::Config->new($CLASS->file, 1); return $config; } @@ -335,8 +343,26 @@ Returns the name of the WebGUI config file used for this test. =cut +my $config_copy; sub file { - return our $CONFIG_FILE; + return $config_copy + if $config_copy; + my $config_base = fileparse( $original_config_file, '.conf' ); + (undef, $config_copy) = File::Temp::tempfile( + "$config_base-XXXX", + SUFFIX => '.conf', + UNLINK => 0, + OPEN => 0, + TMPDIR => 1, + ); + File::Copy::copy($original_config_file, $config_copy) + or die "Error creating temp config file: $!"; + $CLASS->addToCleanup(sub { + unlink $config_copy; + undef $config_copy; + undef $config; + }); + return $config_copy; } #---------------------------------------------------------------------------- @@ -424,7 +450,7 @@ Optionally adds a filename to the end. sub getTestCollateralPath { my $class = shift; my @path = @_; - return File::Spec->catfile(our $WEBGUI_TEST_COLLATERAL, @path); + return catfile(our $WEBGUI_TEST_COLLATERAL, @path); } sub collateral { @@ -439,10 +465,8 @@ Returns the full path to the WebGUI lib directory, usually /data/WebGUI/lib. =cut -our $WEBGUI_LIB = File::Spec->catdir( $WEBGUI_TEST_ROOT, File::Spec->updir, 'lib' ); - sub lib { - return our $WEBGUI_LIB; + return catdir( $WEBGUI_TEST_ROOT, updir, 'lib' ); } #----------------------------------------------------------------------------