Revert "use temp config file for testing"

This reverts commit 9b725c6d42.
This commit is contained in:
Colin Kuskie 2010-06-14 15:19:54 -07:00
parent ce6f70ca94
commit 6c3369d0cb
22 changed files with 94 additions and 57 deletions

View file

@ -17,6 +17,7 @@ package WebGUI::Config;
use strict;
use Class::InsideOut qw(readonly id register);
use Cwd ();
use File::Spec;
use base 'Config::JSON';
my %config = ();
@ -169,8 +170,10 @@ sub new {
my $class = shift;
my $webguiPath = Cwd::realpath(shift);
my $filename = shift;
my $noCache = shift;
my $fullPath = Cwd::realpath($webguiPath.'/etc/'.$filename);
my $noCache = shift;
my $fullPath = File::Spec->file_name_is_absolute($filename)
? $filename
: Cwd::realpath($webguiPath.'/etc/'.$filename);
if ($config{$fullPath}) {
return $config{$fullPath};
} else {

View file

@ -87,7 +87,7 @@ sub execute {
$self->session->errorHandler->warn("More than 1 old userLoginLog rows found, removing offending rows");
$self->session->db->write("delete from userLoginLog where lastPageViewed = timeStamp and sessionId = ? ", [$sessionId] );
}
my $session = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilename, undef, undef, $sessionId, 1);
my $session = WebGUI::Session->open($self->session->config->getWebguiRoot, $self->session->config->getFilePath, undef, undef, $sessionId, 1);
if (defined $session) {
$session->var->end;
$session->close;

View file

@ -14,7 +14,6 @@ use lib "$FindBin::Bin/lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::AdSpace::Ad;
use WebGUI::AdSpace;
use Test::More;
use Test::Deep;
@ -31,9 +30,12 @@ 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, );
my ($jokerAd, $penguinAd, $twoFaceAd);

View file

@ -372,6 +372,10 @@ is($importNode->fixUrl('1234'.'_'x235 . 'abcdefghij'), '1234'.'_'x235 . 'abcdefg
is($importNode->fixUrl('1234'.'_'x250 . 'abcdefghij'), '1234'.'_'x216, 'fixUrl truncates long URLs over 250 characters to 220 characters');
is $importNode->fixUrl('---'), '-', '... 3 dashes are collapsed down to a single dash';
WebGUI::Test->originalConfig('extrasURL');
WebGUI::Test->originalConfig('uploadsURL');
WebGUI::Test->originalConfig('assets');
$session->config->set('extrasURL', '/extras');
$session->config->set('uploadsURL', '/uploads');

View file

@ -17,6 +17,7 @@ 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;
@ -36,6 +37,8 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
WebGUI::Test->originalConfig('exportPath');
my $testRan = 1;
plan tests => 126; # Increment this number for each test you create

View file

@ -79,6 +79,7 @@ $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');

View file

@ -27,6 +27,7 @@ plan tests => 2 + $num_tests;
my $session = WebGUI::Test->session;
# put your tests here
WebGUI::Test->originalConfig('templateParsers');
my $module = use_ok('HTML::Template::Expr');
my $plugin = use_ok('WebGUI::Asset::Template::HTMLTemplateExpr');

View file

@ -36,6 +36,7 @@ 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" );

View file

@ -336,6 +336,7 @@ 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

View file

@ -40,6 +40,7 @@ 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

View file

@ -31,6 +31,8 @@ use WebGUI::Asset::RssAspectDummy;
# Init
my $session = WebGUI::Test->session;
WebGUI::Test->originalConfig('exportPath');
#----------------------------------------------------------------------------
# Tests

View file

@ -34,6 +34,8 @@ plan tests => 3; # Increment this number for each test you create
# put your tests here
use_ok( 'WebGUI::Cache::CHI' );
WebGUI::Test->originalConfig('cacheType');
WebGUI::Test->originalConfig('cache');
$session->config->set('cacheType', 'WebGUI::Cache::CHI');
$session->config->set('cache', { driver => 'FastMmap', });

View file

@ -36,7 +36,7 @@ use_ok('WebGUI::Serialize');
WebGUI::Serialize->crud_createTable($session);
WebGUI::Test->addToCleanup(sub {
WebGUI::Serialize->crud_dropTable($session);
})
});
my $cereal = WebGUI::Serialize->create($session);
isa_ok($cereal, 'WebGUI::Serialize');

View file

@ -91,6 +91,7 @@ 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');

View file

@ -34,6 +34,7 @@ $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

View file

@ -29,6 +29,7 @@ use Data::Dumper;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
WebGUI::Test->originalConfig( "serviceSubnets" );
$session->config->delete('serviceSubnets');
my ( $response, $responseObj, $auth, $userAndy, $userRed );

View file

@ -85,6 +85,7 @@ is( $url2, $url.'?a=b;c=d', 'append second pair');
#
#######################################
WebGUI::Test->originalConfig('gateway');
$session->config->set('gateway', '/');
is( $session->config->get('gateway'), '/', 'Set gateway for downstream tests');
@ -130,6 +131,7 @@ my $setting_hostToUse = $session->setting->get('hostToUse');
$session->setting->set('hostToUse', 'HTTP_HOST');
my $sitename = $session->config->get('sitename')->[0];
is( $session->url->getSiteURL, 'http://'.$sitename, 'getSiteURL from config as http_host');
WebGUI::Test->originalConfig('webServerPort');
$session->url->setSiteURL('http://webgui.org');
is( $session->url->getSiteURL, 'http://webgui.org', 'override config setting with setSiteURL');
@ -149,6 +151,7 @@ $mockEnv{HTTP_HOST} = "devsite.com";
$session->url->setSiteURL(undef);
is( $session->url->getSiteURL, 'http://'.$sitename, 'getSiteURL where requested host is not a configured site');
WebGUI::Test->originalConfig('sitename');
$session->config->addToArray('sitename', 'devsite.com');
$session->url->setSiteURL(undef);
is( $session->url->getSiteURL, 'http://devsite.com', 'getSiteURL where requested host is not the first configured site');
@ -268,8 +271,9 @@ is($session->url->makeAbsolute('page1'), '/page1', 'makeAbsolute: default baseUr
#
#######################################
my $extras = $session->config->get('extrasURL');
my $extras = WebGUI::Test->originalConfig('extrasURL');
WebGUI::Test->originalConfig('cdn');
$session->config->delete('cdn');
is($session->url->extras, $extras.'/', 'extras method returns URL to extras with a trailing slash');
@ -426,6 +430,8 @@ is(
#
#######################################
WebGUI::Test->originalConfig('sslEnabled');
##Test all the false cases, first
$session->config->set('sslEnabled', 0);

View file

@ -91,6 +91,7 @@ is($guidStorage->getDirectoryId, $newGuid, '... getDirectoryId');
#
####################################################
WebGUI::Test->originalConfig('cdn');
$session->config->delete('cdn');
# Note: the CDN configuration will be reverted after CDN tests below

View file

@ -483,6 +483,7 @@ $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');
@ -834,6 +835,7 @@ 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'),

View file

@ -53,9 +53,6 @@ my $origSessionTimeout = $session->setting->get('sessionTimeout');
my $sessionCount = $session->db->quickScalar('select count(*) from userSession');
my $scratchCount = $session->db->quickScalar('select count(*) from userSessionScratch');
note $sessionCount;
note $scratchCount;
my @sessions;
foreach (1..2) {

View file

@ -31,6 +31,7 @@ my $session = WebGUI::Test->session;
my $lib = WebGUI::Test->lib;
## Remove all macros but International, and set them to call WebGUI::Macro::Callback
WebGUI::Test->originalConfig('macros');
my $originalMacros = $session->config->get('macros');
my $configFileMacros = {};
for my $macro (keys %$originalMacros) {

View file

@ -32,22 +32,22 @@ use Log::Log4perl; # load early to ensure proper order of END blocks
use Clone qw(clone);
use File::Basename qw(dirname fileparse);
use File::Spec::Functions qw(abs2rel rel2abs catdir catfile updir);
use IO::Handle ();
use IO::Select ();
use Cwd ();
use Scalar::Util qw( blessed );
use List::MoreUtils qw( any );
use Carp qw( carp croak );
use JSON qw( from_json to_json );
use File::Copy ();
use File::Temp ();
use Scope::Guard;
our ($WEBGUI_TEST_ROOT, $WEBGUI_TEST_COLLATERAL, $WEBGUI_ROOT, $WEBGUI_LIB);
BEGIN {
our $WEBGUI_TEST_ROOT = rel2abs( catdir( dirname( __FILE__ ), (updir) x 2 ) );
our $WEBGUI_TEST_COLLATERAL = catdir(
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(
$WEBGUI_TEST_ROOT,
'supporting_collateral'
);
@ -86,30 +86,21 @@ our @EXPORT_OK = qw(session config collateral);
my $CLASS = __PACKAGE__;
my $original_config_file;
sub import {
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;
our $CONFIG_FILE = $ENV{ WEBGUI_CONFIG };
for my $tryPath (
rel2abs( $config ),
rel2abs( $config, $CLASS->root, 'etc' )
) {
if ( -e $tryPath ) {
$config = $tryPath;
}
}
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 _;
my $etcDir = Cwd::realpath(File::Spec->catdir($CLASS->root, 'etc'));
$CONFIG_FILE = File::Spec->abs2rel($CONFIG_FILE, $etcDir);
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 = abs2rel( $config, catdir( $CLASS->root, 'etc') );
}
goto &{ $_[0]->can('SUPER::import') };
}
@ -370,26 +361,8 @@ Returns the name of the WebGUI config file used for this test.
=cut
my $config_copy;
sub file {
return $config_copy
if $config_copy;
my $config_base = fileparse( $original_config_file, '.conf' );
my (undef, $config_copy_abs) = File::Temp::tempfile(
"$config_base-XXXX",
SUFFIX => '.conf',
UNLINK => 0,
OPEN => 0,
TMPDIR => 1,
);
File::Copy::copy($original_config_file, $config_copy_abs);
$CLASS->addToCleanup(sub {
unlink $config_copy_abs;
undef $config_copy;
undef $config;
});
$config_copy = abs2rel( $config_copy_abs, catdir( $WEBGUI_ROOT, 'etc') );
return $config_copy;
return our $CONFIG_FILE;
}
#----------------------------------------------------------------------------
@ -478,7 +451,7 @@ Optionally adds a filename to the end.
sub getTestCollateralPath {
my $class = shift;
my @path = @_;
return catfile(our $WEBGUI_TEST_COLLATERAL, @path);
return File::Spec->catfile(our $WEBGUI_TEST_COLLATERAL, @path);
}
sub collateral {
@ -596,6 +569,7 @@ sub prepareMailServer {
$CLASS->session->setting->set( 'smtpServer', $SMTP_HOST . ':' . $SMTP_PORT );
$CLASS->originalConfig('emailToLog');
$CLASS->session->config->set( 'emailToLog', 0 );
# Let it start up yo
@ -618,6 +592,38 @@ sub prepareMailServer {
#----------------------------------------------------------------------------
=head2 originalConfig ( $param )
Stores the original data from the config file, to be restored
automatically at the end of the test. This is a class method.
=cut
my %originalConfig;
sub originalConfig {
my ($class, $param) = @_;
my $safeValue = my $value = $CLASS->session->config->get($param);
if (ref $value) {
$safeValue = clone $value;
}
# add cleanup handler if this is the first time we were run
if (! keys %originalConfig) {
$class->addToCleanup(sub {
while (my ($key, $value) = each %originalConfig) {
if (defined $value) {
$CLASS->session->config->set($key, $value);
}
else {
$CLASS->session->config->delete($key);
}
}
});
}
$originalConfig{$param} = $safeValue;
}
#----------------------------------------------------------------------------
=head2 getMail ( )
Read a sent mail from the prepared mail server (L<prepareMailServer>)