use temp config file for testing
This commit is contained in:
parent
bc5df47fed
commit
6f102973dd
20 changed files with 56 additions and 95 deletions
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ $snippet->update({
|
|||
snippet => q|^SQL(select value from settings where name="<tmpl_var title>");|
|
||||
});
|
||||
|
||||
WebGUI::Test->originalConfig('macros');
|
||||
$session->config->addToHash('macros', 'SQL', 'SQL');
|
||||
|
||||
is($snippet->view(), 'WebGUI', 'Interpolating macros in works with template in the correct order');
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ sub setup_assets {
|
|||
}
|
||||
|
||||
END {
|
||||
$session->config->set('templateParsers', $originalParsers);
|
||||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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" );
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ use WebGUI::Asset::RssAspectDummy;
|
|||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
WebGUI::Test->originalConfig('exportPath');
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -55,6 +55,3 @@ $session->config->set('dbslave2', $slaveHash2);
|
|||
my $slave2 = $session->dbSlave;
|
||||
isa_ok($slave2, 'WebGUI::SQL');
|
||||
|
||||
END {
|
||||
$session->config->delete('dbslave2');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
2
t/User.t
2
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'),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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' );
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue