Skip to content

Commit

Permalink
Item13897: SaveScriptTests converted.
Browse files Browse the repository at this point in the history
- Fixed PrefsTests – the problem was unrelated to the previous commit but
was caused by HomePagePlugin overriding current request web.

- Converted all bin/ scripts to the new model.

- Fixed a bug with cookies not being sent to the browser.

- Foswiki::UI::ChangeForm converted to OO
  • Loading branch information
vrurg committed Jun 23, 2016
1 parent aa29949 commit 16ef325
Show file tree
Hide file tree
Showing 26 changed files with 802 additions and 1,137 deletions.
48 changes: 25 additions & 23 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -680,6 +680,7 @@ around set_up => sub {
my $this = shift;

$orig->( $this, @_ );
my $cfgData = $this->app->cfg->data;

$this->_clear__EnvSafe;
foreach my $sym ( keys %ENV ) {
Expand All @@ -700,9 +701,9 @@ around set_up => sub {
# in lib/MANIFEST) are enabled, but they are *all* enabled.

# First disable all plugins
foreach my $k ( keys %{ $Foswiki::cfg{Plugins} } ) {
next unless ref( $Foswiki::cfg{Plugins}{$k} ) eq 'HASH';
$Foswiki::cfg{Plugins}{$k}{Enabled} = 0;
foreach my $k ( keys %{ $cfgData->{Plugins} } ) {
next unless ref( $cfgData->{Plugins}{$k} ) eq 'HASH';
$cfgData->{Plugins}{$k}{Enabled} = 0;
}

# then reenable only those listed in MANIFEST
Expand All @@ -718,14 +719,14 @@ around set_up => sub {

# Don't enable EmptyPlugin - Disabled by default
if ( $extension =~ m/Plugin$/ && $extension ne 'EmptyPlugin' ) {
unless ( exists $Foswiki::cfg{Plugins}{$extension}{Module} ) {
$Foswiki::cfg{Plugins}{$extension}{Module} =
unless ( exists $cfgData->{Plugins}{$extension}{Module} ) {
$cfgData->{Plugins}{$extension}{Module} =
'Foswiki::Plugins::' . $extension;
print STDERR "WARNING: $extension has no module defined, "
. "it might not load!\n"
. "\tGuessed it to $Foswiki::cfg{Plugins}{$extension}{Module}\n";
. "\tGuessed it to $cfgData->{Plugins}{$extension}{Module}\n";
}
$Foswiki::cfg{Plugins}{$extension}{Enabled} = 1;
$cfgData->{Plugins}{$extension}{Enabled} = 1;
}

# Is there a Config.spec?
Expand Down Expand Up @@ -772,15 +773,16 @@ s/((\$Foswiki::cfg\{.*?\})\s*=.*?;)(?:\n|$)/push(@moreConfig, $1) unless (eval "

ASSERT( !defined $Foswiki::app ) if SINGLE_SINGLETONS;

$Foswiki::cfg{WorkingDir} = $this->tempDir;
mkdir("$Foswiki::cfg{WorkingDir}/tmp");
mkdir("$Foswiki::cfg{WorkingDir}/registration_approvals");
mkdir("$Foswiki::cfg{WorkingDir}/work_areas");
mkdir("$Foswiki::cfg{WorkingDir}/requestTmp");
$this->app->cfg->data->{WorkingDir} = $this->tempDir;
foreach my $subdir (qw(tmp registration_approvals work_areas requestTmp)) {
my $newDir =
File::Spec->catfile( $this->app->cfg->data->{WorkingDir}, $subdir );
ASSERT( mkdir($newDir), "mkdir($newDir) : $!" );
}

# Force completion of %Foswiki::cfg
# This must be done before moving the logging.
$Foswiki::cfg{Store}{Implementation} = 'Foswiki::Store::PlainFile';
$cfgData->{Store}{Implementation} = 'Foswiki::Store::PlainFile';
$this->pushApp;
my $tmp = Unit::TestApp->new(
user => undef,
Expand All @@ -797,24 +799,24 @@ s/((\$Foswiki::cfg\{.*?\})\s*=.*?;)(?:\n|$)/push(@moreConfig, $1) unless (eval "
# Note this does not do much, except for some tests that use it directly.
# The first call to File::Temp caches the temp directory name, so
# this value won't get used for anything created by File::Temp
$Foswiki::cfg{TempfileDir} = "$Foswiki::cfg{WorkingDir}/requestTmp";
$cfgData->{TempfileDir} = "$cfgData->{WorkingDir}/requestTmp";

# Move logging into a temporary directory
my $logdir = Cwd::getcwd() . '/testlogs';
$logdir =~ m/^(.*)$/;
$logdir = $1;
$Foswiki::cfg{Log}{Dir} = $logdir;
$cfgData->{Log}{Dir} = $logdir;
mkdir($logdir) unless -d $logdir;
$Foswiki::cfg{Log}{Implementation} = 'Foswiki::Logger::Compatibility';
$Foswiki::cfg{LogFileName} = "$logdir/FoswikiTestCase.log";
$Foswiki::cfg{WarningFileName} = "$logdir/FoswikiTestCase.warn";
$Foswiki::cfg{DebugFileName} = "$logdir/FoswikiTestCase.debug";
$Foswiki::cfg{AdminUserWikiName} = 'AdminUser';
$Foswiki::cfg{AdminUserLogin} = 'root';
$Foswiki::cfg{SuperAdminGroup} = 'AdminGroup';
$cfgData->{Log}{Implementation} = 'Foswiki::Logger::Compatibility';
$cfgData->{LogFileName} = "$logdir/FoswikiTestCase.log";
$cfgData->{WarningFileName} = "$logdir/FoswikiTestCase.warn";
$cfgData->{DebugFileName} = "$logdir/FoswikiTestCase.debug";
$cfgData->{AdminUserWikiName} = 'AdminUser';
$cfgData->{AdminUserLogin} = 'root';
$cfgData->{SuperAdminGroup} = 'AdminGroup';

# The unit tests really need CGI sessions or captureWithKey fails
$Foswiki::cfg{Sessions}{EnableGuestSessions} = 1;
$cfgData->{Sessions}{EnableGuestSessions} = 1;

# This must be done *after* disabling/enabling the plugins
# so that tests derived from this class can enable additional plugins.
Expand Down
86 changes: 60 additions & 26 deletions UnitTestContrib/test/unit/PrefsTests.pm
Expand Up @@ -71,6 +71,19 @@ around tear_down => sub {
$orig->($this);
};

around createNewFoswikiApp => sub {
my $orig = shift;
my $this = shift;
my $app = $orig->( $this, @_ );

# Some plugins are interfering with rendering process.
# Special not on HomePagePlugin which unconditionally sets web/topic on
# request even whtn they're already set by the engine.
$app->cfg->data->{DisableAllPlugins} = 1;

return $app;
};

sub _set {
my ( $this, $web, $topic, $pref, $val, $type ) = @_;
$this->assert_not_null($web);
Expand Down Expand Up @@ -137,15 +150,17 @@ sub _setUserPref {
return;
}

sub test_system {
sub test_system_prefs {
my $this = shift;
$this->_setDefaultPref( "SOURCE", "DEFAULT" );
$this->_setDefaultPref( "FINALPREFERENCES", "" );
$this->_setSitePref( "FINALPREFERENCES", "" );
$this->_setWebPref( "FINALPREFERENCES", "" );
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp( user => $this->test_user_login );
my $t =
$this->createNewFoswikiApp( engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, }, );
$this->assert_str_equals( "DEFAULT", $t->prefs->getPreference("SOURCE") );

return;
Expand All @@ -161,7 +176,9 @@ sub test_local {
$this->_setWebPref( "FINALPREFERENCES", "" );
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp( user => $this->test_user_login );
my $t =
$this->createNewFoswikiApp( engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, }, );
$this->assert_str_equals( "SITE", $t->prefs->getPreference("SOURCE") );

return;
Expand All @@ -178,15 +195,16 @@ sub test_web_prefs {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "WEB", $t->prefs->getPreference("SOURCE") );

return;
}

sub test_user {
sub test_user_prefs {
my $this = shift;

$this->_setUserPref( "SOURCE", "USER" );
Expand All @@ -197,7 +215,12 @@ sub test_user {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams => {
initialAttributes => {
user => $this->test_user_login,
path_info => "/" . $this->test_web . "/" . $this->test_topic,
},
},
%topicAppParams,
);
$this->assert_str_equals( "USER", $t->prefs->getPreference("SOURCE") );
Expand All @@ -215,7 +238,8 @@ sub test_topic_prefs {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "TOPIC", $t->prefs->getPreference("SOURCE") );
Expand All @@ -237,7 +261,8 @@ sub test_order {
$this->_setWebPref( "FINALPREFERENCES", "" );
$this->_setUserPref( "FINALPREFERENCES", "" );
my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "TOPIC", $t->prefs->getPreference("SOURCE") );
Expand All @@ -260,7 +285,8 @@ sub test_finalSystem {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "DEFAULT", $t->prefs->getPreference("SOURCE") );
Expand All @@ -283,7 +309,8 @@ sub test_finalSite {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "SITE", $t->prefs->getPreference("SOURCE") );
Expand All @@ -306,7 +333,8 @@ sub test_finalWeb {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "WEB", $t->prefs->getPreference("SOURCE") );
Expand Down Expand Up @@ -348,7 +376,8 @@ sub test_nouser {
$this->_setUserPref( "FINALPREFERENCES", "" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "WEB",
Expand All @@ -363,10 +392,7 @@ sub test_local_to_default {
$this->_setDefaultPref( "SOURCE", "GLOBAL" );
$this->_setDefaultPref( "SOURCE", "LOCAL", "Local" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
%topicAppParams,
);
my $t = $this->createNewFoswikiApp( %topicAppParams, );
$this->assert_str_equals( "GLOBAL", $t->prefs->getPreference("SOURCE") );

$t = $this->createNewFoswikiApp(
Expand All @@ -391,7 +417,8 @@ sub test_local_to_site {
$this->_setSitePref( "SOURCE", "LOCAL", "Local" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "GLOBAL", $t->prefs->getPreference("SOURCE") );
Expand All @@ -400,9 +427,13 @@ sub test_local_to_site {
$this->app->cfg->data->{LocalSitePreferences} );

$t = $this->createNewFoswikiApp(
user => $this->test_user_login,
requestParams => { initializer => '', },
engineParams => { initialAttributes => { path_info => "/$tw/$tt", }, },
engineParams => {
initialAttributes => {
path_info => "/$tw/$tt",
user => $this->test_user_login,
},
},
);
$this->assert_str_equals( "LOCAL", $t->prefs->getPreference("SOURCE") );

Expand All @@ -416,17 +447,18 @@ sub test_local_to_user {
$this->_setUserPref( "SOURCE", "LOCAL", "Local" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams
);
$this->assert_str_equals( "GLOBAL", $t->prefs->getPreference("SOURCE") );

$t = $this->createNewFoswikiApp(
user => $this->test_user_login,
requestParams => { initializer => '', },
engineParams => {
initialAttributes => {
path_info => "/"
user => $this->test_user_login,
path_info => "/"
. $this->app->cfg->data->{UsersWebName} . "/"
. $this->test_user_wikiname,
},
Expand All @@ -444,19 +476,20 @@ sub test_local_to_web {
$this->_setWebPref( "SOURCE", "LOCAL", "Local" );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "GLOBAL", $t->prefs->getPreference("SOURCE") );

$t = $this->createNewFoswikiApp(
user => $this->test_user_login,
requestParams => { initializer => '', },
engineParams => {
initialAttributes => {
path_info => "/"
path_info => "/"
. $this->test_web . "/"
. $this->app->cfg->data->{WebPrefsTopicName},
user => $this->test_user_login,
},
}
);
Expand All @@ -473,7 +506,8 @@ sub test_whitespace {
$this->_setTopicPref( "THREE", "VAL\n " );

my $t = $this->createNewFoswikiApp(
user => $this->test_user_login,
engineParams =>
{ initialAttributes => { user => $this->test_user_login, }, },
%topicAppParams,
);
$this->assert_str_equals( "VAL ", $t->prefs->getPreference("ONE") );
Expand Down

0 comments on commit 16ef325

Please sign in to comment.