Added WebGUI::Test and updated t/Config.t
This commit is contained in:
parent
76ef4da780
commit
3f6176397b
2 changed files with 95 additions and 24 deletions
39
t/Config.t
39
t/Config.t
|
|
@ -8,31 +8,22 @@
|
|||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
# ---- BEGIN DO NOT EDIT ----
|
||||
use strict;
|
||||
use lib '../lib';
|
||||
use Getopt::Long;
|
||||
# ---- END DO NOT EDIT ----
|
||||
|
||||
use WebGUI::Config;
|
||||
use strict;
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use Test::More tests => 6; # increment this value for each test you create
|
||||
|
||||
$|=1;
|
||||
my $configFile;
|
||||
GetOptions(
|
||||
'configFile=s'=>\$configFile
|
||||
);
|
||||
exit 1 unless ($configFile);
|
||||
|
||||
my $config = WebGUI::Config->new("..", $configFile);
|
||||
|
||||
ok(defined $config, "load config");
|
||||
ok($config->get("dsn") ne "", "get()");
|
||||
is($config->getFilename,$configFile,"getFilename()");
|
||||
is($config->getWebguiRoot, "..", "getWebguiRoot()");
|
||||
WebGUI::Config->loadAllConfigs("..");
|
||||
ok(exists $WebGUI::Config::config{$configFile}, "loadAllConfigs");
|
||||
ok(defined WebGUI::Config->readAllConfigs(".."), "readAllConfigs");
|
||||
|
||||
|
||||
my $config = WebGUI::Test->config;
|
||||
my $configFile = WebGUI::Test->file;
|
||||
my $webguiRoot = WebGUI::Test->root;
|
||||
|
||||
ok( defined $config, "load config" );
|
||||
ok( $config->get("dsn") ne "", "get()" );
|
||||
is( $config->getFilename,$configFile,"getFilename()" );
|
||||
is( $config->getWebguiRoot, $webguiRoot, "getWebguiRoot()" );
|
||||
ok( exists $WebGUI::Config::config{$configFile}, "loadAllConfigs" );
|
||||
ok( defined WebGUI::Config->readAllConfigs($webguiRoot), "readAllConfigs" );
|
||||
|
|
|
|||
80
t/lib/WebGUI/Test.pm
Normal file
80
t/lib/WebGUI/Test.pm
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package WebGUI::Test;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our ( $SESSION, $WEBGUI_ROOT, $CONFIG_FILE, $WEBGUI_LIB );
|
||||
|
||||
use IO::Handle qw[];
|
||||
use File::Spec qw[];
|
||||
|
||||
BEGIN {
|
||||
|
||||
STDERR->autoflush(1);
|
||||
|
||||
( $CONFIG_FILE, $WEBGUI_LIB ) = @ENV{ qw( WEBGUI_CONFIG WEBGUI_LIB ) };
|
||||
|
||||
unless ( defined $CONFIG_FILE && $CONFIG_FILE ) {
|
||||
warn qq/Enviroment variable WEBGUI_CONFIG must be set.\n/;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unless ( -e $CONFIG_FILE ) {
|
||||
warn qq/WEBGUI_CONFIG path '$CONFIG_FILE' does not exist.\n/;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unless ( -f _ ) {
|
||||
warn qq/WEBGUI_CONFIG path '$CONFIG_FILE' is not a file.\n/;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
unless ( -r _ ) {
|
||||
warn qq/WEBGUI_CONFIG path '$CONFIG_FILE' is not readable by effective uid '$>'.\n/;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$WEBGUI_ROOT = $CONFIG_FILE;
|
||||
|
||||
unless ( File::Spec->file_name_is_absolute($WEBGUI_ROOT) ) {
|
||||
$WEBGUI_ROOT = File::Spec->rel2abs($WEBGUI_ROOT);
|
||||
}
|
||||
|
||||
$CONFIG_FILE = ( File::Spec->splitpath( $WEBGUI_ROOT ) )[2];
|
||||
$WEBGUI_ROOT = substr( $WEBGUI_ROOT, 0, index( $WEBGUI_ROOT, File::Spec->catdir( 'etc', $CONFIG_FILE ) ) );
|
||||
$WEBGUI_ROOT = File::Spec->canonpath($WEBGUI_ROOT);
|
||||
|
||||
$WEBGUI_LIB ||= File::Spec->catpath( $WEBGUI_ROOT, 'lib' );
|
||||
|
||||
lib->import( $WEBGUI_LIB );
|
||||
|
||||
unless ( eval "require WebGUI::Session;" ) {
|
||||
warn qq/Failed to require package 'WebGUI::Session'. Reason: '$@'.\n/;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$SESSION = WebGUI::Session->open( $WEBGUI_ROOT, $CONFIG_FILE );
|
||||
}
|
||||
|
||||
END {
|
||||
$SESSION->close if defined $SESSION;
|
||||
}
|
||||
|
||||
sub file {
|
||||
return $CONFIG_FILE;
|
||||
}
|
||||
|
||||
sub config {
|
||||
return undef unless defined $SESSION;
|
||||
return $SESSION->config;
|
||||
}
|
||||
|
||||
sub session {
|
||||
return $SESSION;
|
||||
}
|
||||
|
||||
sub root {
|
||||
return $WEBGUI_ROOT;
|
||||
}
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue