From 16ef3251ea523b853dc7ae8b0839767335050019 Mon Sep 17 00:00:00 2001 From: Vadim Belman Date: Wed, 22 Jun 2016 20:54:38 -0400 Subject: [PATCH] Item13897: SaveScriptTests converted. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- UnitTestContrib/test/unit/FoswikiTestCase.pm | 48 +- UnitTestContrib/test/unit/PrefsTests.pm | 86 +- UnitTestContrib/test/unit/SaveScriptTests.pm | 1098 ++++++++++-------- core/bin/attach | 31 +- core/bin/changes | 31 +- core/bin/edit | 31 +- core/bin/logon | 31 +- core/bin/manage | 31 +- core/bin/oops | 31 +- core/bin/preview | 31 +- core/bin/previewauth | 31 +- core/bin/rdiff | 31 +- core/bin/rdiffauth | 31 +- core/bin/register | 31 +- core/bin/rename | 31 +- core/bin/resetpasswd | 31 +- core/bin/rest | 31 +- core/bin/restauth | 31 +- core/bin/save | 31 +- core/bin/search | 31 +- core/bin/statistics | 31 +- core/bin/upload | 31 +- core/bin/viewauth | 31 +- core/bin/viewfileauth | 31 +- core/lib/Foswiki/Response.pm | 31 +- core/lib/Foswiki/UI/ChangeForm.pm | 25 +- 26 files changed, 802 insertions(+), 1137 deletions(-) diff --git a/UnitTestContrib/test/unit/FoswikiTestCase.pm b/UnitTestContrib/test/unit/FoswikiTestCase.pm index 713957b6d1..34bcde72b6 100644 --- a/UnitTestContrib/test/unit/FoswikiTestCase.pm +++ b/UnitTestContrib/test/unit/FoswikiTestCase.pm @@ -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 ) { @@ -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 @@ -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? @@ -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, @@ -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. diff --git a/UnitTestContrib/test/unit/PrefsTests.pm b/UnitTestContrib/test/unit/PrefsTests.pm index a0b73b16db..966b19c79b 100644 --- a/UnitTestContrib/test/unit/PrefsTests.pm +++ b/UnitTestContrib/test/unit/PrefsTests.pm @@ -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); @@ -137,7 +150,7 @@ sub _setUserPref { return; } -sub test_system { +sub test_system_prefs { my $this = shift; $this->_setDefaultPref( "SOURCE", "DEFAULT" ); $this->_setDefaultPref( "FINALPREFERENCES", "" ); @@ -145,7 +158,9 @@ sub test_system { $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; @@ -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; @@ -178,7 +195,8 @@ 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") ); @@ -186,7 +204,7 @@ sub test_web_prefs { return; } -sub test_user { +sub test_user_prefs { my $this = shift; $this->_setUserPref( "SOURCE", "USER" ); @@ -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") ); @@ -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") ); @@ -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") ); @@ -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") ); @@ -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") ); @@ -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") ); @@ -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", @@ -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( @@ -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") ); @@ -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") ); @@ -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, }, @@ -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, }, } ); @@ -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") ); diff --git a/UnitTestContrib/test/unit/SaveScriptTests.pm b/UnitTestContrib/test/unit/SaveScriptTests.pm index 639a6ec0f9..eeea045f31 100644 --- a/UnitTestContrib/test/unit/SaveScriptTests.pm +++ b/UnitTestContrib/test/unit/SaveScriptTests.pm @@ -3,15 +3,12 @@ use v5.14; use Foswiki(); use Foswiki::UI::Save(); -use Unit::Request(); use Try::Tiny; use Moo; use namespace::clean; extends qw( FoswikiFnTestCase ); -my $UI_FN; - my $testform1 = <<'HERE'; | *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes* | | Select | select | 1 | Value_1, Value_2, *Value_3* | | @@ -99,8 +96,6 @@ around set_up => sub { my $this = shift; $orig->( $this, @_ ); - $UI_FN ||= $this->getUIFn('save'); - $this->test_user_2_forename('Buck'); $this->test_user_2_surname('Rogers'); $this->test_user_2_wikiname( @@ -156,23 +151,50 @@ CONTENT return; }; +# Foswiki::App handleRequestException callback function. +sub _cbHRE { + my $obj = shift; + my %args = @_; + $args{params}{exception}->rethrow; +} + +around createNewFoswikiApp => sub { + my $orig = shift; + my $this = shift; + + my %params = @_; + + $params{engineParams}{initialAttributes}{action} //= 'save'; + + $this->app->cfg->data->{DisableAllPlugins} = 1; + + return $orig->( $this, @_, + callbacks => { handleRequestException => \&_cbHRE }, ); +}; + # AUTOINC sub test_AUTOINC { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ['nowt'], - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ['nowt'], + }, + }, + engineParams => { + initialAttributes => { + user => $this->test_user_login, + path_info => '/' . $this->test_web . '.TestAutoAUTOINC00', + method => 'post', + }, + }, ); - $query->path_info( '/' . $this->test_web . '.TestAutoAUTOINC00' ); - $query->method('post'); - $this->createNewFoswikiSession( $this->test_user_login, $query ); my %old; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { $old{$t} = 1; } - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my $seen = 0; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { if ( $t eq 'TestAuto00' ) { @@ -183,9 +205,22 @@ sub test_AUTOINC { } } $this->assert($seen); - $query->method('pOsT'); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ['nowt'], + }, + }, + engineParams => { + initialAttributes => { + user => $this->test_user_login, + path_info => '/' . $this->test_web . '.TestAutoAUTOINC00', + method => 'pOsT', + }, + }, + ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $seen = 0; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { @@ -203,20 +238,26 @@ sub test_AUTOINC { # 10X sub test_XXXXXXXXXX { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ['nowt'], - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ['nowt'], + }, + }, + engineParams => { + initialAttributes => { + user => $this->test_user_login, + path_info => '/' . $this->test_web . '.TestTopicXXXXXXXXXX', + }, + }, ); - $query->path_info( '/' . $this->test_web . '.TestTopicXXXXXXXXXX' ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); my %old; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { $old{$t} = 1; } - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my $seen = 0; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { if ( $t eq 'TestTopic0' ) { @@ -227,8 +268,21 @@ sub test_XXXXXXXXXX { } } $this->assert($seen); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ['nowt'], + }, + }, + engineParams => { + initialAttributes => { + user => $this->test_user_login, + path_info => '/' . $this->test_web . '.TestTopicXXXXXXXXXX', + }, + }, + ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $seen = 0; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { if ( $t =~ m/^TestTopic[01]$/ ) { @@ -245,24 +299,30 @@ sub test_XXXXXXXXXX { # 9X sub test_XXXXXXXXX { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ['nowt'], - } - ); - $query->path_info( "/" . $this->test_web . "/TestTopicXXXXXXXXX" ); + my $this = shift; $this->assert( - !$this->session->topicExists( $this->test_web, 'TestTopic0' ) ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); + !$this->app->store->topicExists( $this->test_web, 'TestTopic0' ) ); + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ['nowt'], + }, + }, + engineParams => { + initialAttributes => { + user => $this->test_user_login, + path_info => '/' . $this->test_web . '.TestTopicXXXXXXXXX', + }, + }, + ); my %old; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { $old{$t} = 1; } - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - !$this->session->topicExists( $this->test_web, 'TestTopic0' ) ); + !$this->app->store->topicExists( $this->test_web, 'TestTopic0' ) ); my $seen = 0; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { if ( $t eq 'TestTopicXXXXXXXXX' ) { @@ -279,20 +339,26 @@ sub test_XXXXXXXXX { #11X sub test_XXXXXXXXXXX { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ['nowt'], - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ['nowt'], + }, + }, + engineParams => { + initialAttributes => { + user => $this->test_user_login, + path_info => '/' . $this->test_web . '.TestTopicXXXXXXXXXX', + }, + }, ); - $query->path_info( "/" . $this->test_web . "/TestTopicXXXXXXXXXXX" ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); my %old; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { $old{$t} = 1; } - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my $seen = 0; foreach my $t ( Foswiki::Func::getTopicList( $this->test_web ) ) { if ( $t eq 'TestTopic0' ) { @@ -308,15 +374,18 @@ sub test_XXXXXXXXXXX { } sub test_emptySave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - topic => [ $this->test_web . '.EmptyTestSaveScriptTopic' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + topic => [ $this->test_web . '.EmptyTestSaveScriptTopic' ], + }, + }, + enginParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'EmptyTestSaveScriptTopic' ); my $text = $meta->text; @@ -329,9 +398,10 @@ sub test_emptySave { sub test_simpleTextPreview { my $this = shift; my ( $test_web, $test_topic ) = ( $this->test_web, $this->test_topic ); - my $query = Unit::Request->new( - initializer => { - text => [<createNewFoswikiApp( + requestParams => { + initializer => { + text => [<no target self undelim @@ -340,17 +410,19 @@ CUT## messed up ##CUT HERE - action => ['preview'], - topic => [ $this->test_web . '.DeleteTestSaveScriptTopic' ] - } + action => ['preview'], + topic => [ $test_web . '.DeleteTestSaveScriptTopic' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - my ( $results, $stdout, $stderr ) = - $this->captureWithKey( save => $UI_FN, $this->session ); + my ( $text, $results, $stdout, $stderr ) = + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); - $results =~ s/.*CUT##(.*?)##CUT.*/$1/ms; + $text =~ s/.*CUT##(.*?)##CUT.*/$1/ms; - $this->assert_html_equals( <assert_html_equals( <no target self undelim self SQ @@ -364,16 +436,19 @@ HERE } sub test_simpleTextSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - action => ['save'], - topic => [ $this->test_web . '.DeleteTestSaveScriptTopic' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + action => ['save'], + topic => [ $this->test_web . '.DeleteTestSaveScriptTopic' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'DeleteTestSaveScriptTopic' ); my $text = $meta->text; @@ -384,19 +459,23 @@ sub test_simpleTextSave { } sub test_simpleTextSaveDeniedWebCHANGE { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - action => ['save'], - topic => [ $this->test_web . '.DeleteTestSaveScriptTopic3' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + action => ['save'], + topic => [ $this->test_web . '.DeleteTestSaveScriptTopic3' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_3_login, }, }, + callbacks => { handleRequestException => \&_cbHRE }, ); - $this->createNewFoswikiSession( $this->test_user_3_login, $query ); my $exception; try { - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); } catch { $exception = $_; @@ -421,7 +500,7 @@ qr/AccessControlException: Access to CHANGE TemporarySaveTestWebSave. for duck i $exception->stringify ); $this->assert( - !$this->session->topicExists( + !$this->app->store->topicExists( $this->test_web, 'DeleteTestSaveScriptTopic3' ) ); @@ -430,25 +509,31 @@ qr/AccessControlException: Access to CHANGE TemporarySaveTestWebSave. for duck i } sub test_templateTopicTextSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['Template Topic'], - action => ['save'], - topic => [ $this->test_web . '.TemplateTopic' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['Template Topic'], + action => ['save'], + topic => [ $this->test_web . '.TemplateTopic' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); - $query = Unit::Request->new( - initializer => { - templatetopic => ['TemplateTopic'], - action => ['save'], - topic => [ $this->test_web . '.TemplateTopic' ] - } + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['Template Topic'], + action => ['save'], + topic => [ $this->test_web . '.TemplateTopic' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'TemplateTopic' ); my $text = $meta->text; $this->assert_matches( qr/Template Topic/, $text ); @@ -459,25 +544,31 @@ sub test_templateTopicTextSave { # Save over existing topic sub test_prevTopicTextSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['WRONG'], - action => ['save'], - topic => [ $this->test_web . '.PrevTopicTextSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['WRONG'], + action => ['save'], + topic => [ $this->test_web . '.PrevTopicTextSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); - $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - action => ['save'], - topic => [ $this->test_web . '.PrevTopicTextSave' ] - } + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + action => ['save'], + topic => [ $this->test_web . '.PrevTopicTextSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'PrevTopicTextSave' ); my $text = $meta->text; @@ -489,17 +580,21 @@ sub test_prevTopicTextSave { # Save into missing web sub test_missingWebSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['WRONG'], - action => ['save'], - topic => [ 'MissingWeb' . '.PrevTopicTextSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['WRONG'], + action => ['save'], + topic => ['MissingWeb.PrevTopicTextSave'] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, + callbacks => { handleRequestException => \&_cbHRE }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); try { - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( 0, 'save into missing web worked' ); } catch { @@ -517,24 +612,31 @@ sub test_missingWebSave { # Save over existing topic with no text sub test_prevTopicEmptyTextSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - action => ['save'], - topic => [ $this->test_web . '.PrevTopicEmptyTextSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + action => ['save'], + topic => [ $this->test_web . '.PrevTopicEmptyTextSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); - $query = Unit::Request->new( - initializer => { - action => ['save'], - topic => [ $this->test_web . '.PrevTopicEmptyTextSave' ] - } + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); + + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + topic => [ $this->test_web . '.PrevTopicEmptyTextSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'PrevTopicEmptyTextSave' ); my $text = $meta->text; @@ -545,20 +647,23 @@ sub test_prevTopicEmptyTextSave { } sub test_simpleFormSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - formtemplate => ['TestForm1'], - action => ['save'], - 'Textfield' => ['Flintstone'], - topic => [ $this->test_web . '.SimpleFormSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + formtemplate => ['TestForm1'], + action => ['save'], + 'Textfield' => ['Flintstone'], + topic => [ $this->test_web . '.SimpleFormSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - $this->session->topicExists( $this->test_web, 'SimpleFormSave' ) ); + $this->app->store->topicExists( $this->test_web, 'SimpleFormSave' ) ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave' ); my $text = $meta->text; $this->assert_matches( qr/^CORRECT\s*$/, $text ); @@ -572,32 +677,39 @@ sub test_simpleFormSave { } sub test_templateTopicFormSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['Template Topic'], - formtemplate => ['TestForm1'], - 'Select' => ['Value_1'], - 'Textfield' => ['Fred'], - action => ['save'], - topic => [ $this->test_web . '.TemplateTopic' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['Template Topic'], + formtemplate => ['TestForm1'], + 'Select' => ['Value_1'], + 'Textfield' => ['Fred'], + action => ['save'], + topic => [ $this->test_web . '.TemplateTopic' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($xmeta) = Foswiki::Func::readTopic( $this->test_web, 'TemplateTopic' ); my $xtext = $xmeta->text; undef $xmeta; - $query = Unit::Request->new( - initializer => { - templatetopic => ['TemplateTopic'], - action => ['save'], - topic => [ $this->test_web . '.TemplateTopicAgain' ] - } + + $this->createNewFoswikiApp( + requestParams => { + initializer => { + templatetopic => ['TemplateTopic'], + action => ['save'], + topic => [ $this->test_web . '.TemplateTopicAgain' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'TemplateTopicAgain' ); my $text = $meta->text; @@ -613,29 +725,36 @@ sub test_templateTopicFormSave { } sub test_prevTopicFormSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['Template Topic'], - formtemplate => ['TestForm1'], - 'Select' => ['Value_1'], - 'Textfield' => ['Rubble'], - action => ['save'], - topic => [ $this->test_web . '.PrevTopicFormSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['Template Topic'], + formtemplate => ['TestForm1'], + 'Select' => ['Value_1'], + 'Textfield' => ['Rubble'], + action => ['save'], + topic => [ $this->test_web . '.PrevTopicFormSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); - $query = Unit::Request->new( - initializer => { - action => ['save'], - 'Textfield' => ['Barney'], - topic => [ $this->test_web . '.PrevTopicFormSave' ] - } + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); + + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + 'Textfield' => ['Barney'], + topic => [ $this->test_web . '.PrevTopicFormSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); my ( $responseText, $result, $stdout, $stderr ) = - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); # Uncomment to get output from command #print STDERR $responseText . $result . $stdout . $stderr . "\n"; @@ -654,24 +773,27 @@ sub test_prevTopicFormSave { } sub test_simpleFormSave1 { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => [$testtext_nometa], - formtemplate => ['TestForm1'], - 'Select' => ['Value_2'], - 'Radio' => ['3'], - 'Checkbox' => ['red'], - 'CheckboxandButtons' => ['hamster'], - 'Textfield' => ['Test'], - topic => [ $this->test_web . '.SimpleFormTopic' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => [$testtext_nometa], + formtemplate => ['TestForm1'], + 'Select' => ['Value_2'], + 'Radio' => ['3'], + 'Checkbox' => ['red'], + 'CheckboxandButtons' => ['hamster'], + 'Textfield' => ['Test'], + topic => [ $this->test_web . '.SimpleFormTopic' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - $this->session->topicExists( $this->test_web, 'SimpleFormTopic' ) ); + $this->app->store->topicExists( $this->test_web, 'SimpleFormTopic' ) ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormTopic' ); my $text = $meta->text; $this->assert_str_equals( 'TestForm1', $meta->get('FORM')->{name} ); @@ -685,7 +807,7 @@ sub test_simpleFormSave1 { # are deleted. sub test_simpleFormSave2 { my $this = shift; - $this->createNewFoswikiSession(); + $this->createNewFoswikiApp; my ($oldmeta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave2' ); @@ -697,23 +819,26 @@ sub test_simpleFormSave2 { undef $oldmeta; $meta->save( user => $this->test_user_login ); - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => [$testtext_nometa], - formtemplate => ['TestForm3'], - 'Select' => ['Value_2'], - 'Radio' => ['3'], - 'Checkbox' => ['red'], - 'CheckboxandButtons' => ['hamster'], - 'Textfield' => ['Test'], - topic => [ $this->test_web . '.SimpleFormSave2' ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => [$testtext_nometa], + formtemplate => ['TestForm3'], + 'Select' => ['Value_2'], + 'Radio' => ['3'], + 'Checkbox' => ['red'], + 'CheckboxandButtons' => ['hamster'], + 'Textfield' => ['Test'], + topic => [ $this->test_web . '.SimpleFormSave2' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - $this->session->topicExists( $this->test_web, 'SimpleFormSave2' ) ); + $this->app->store->topicExists( $this->test_web, 'SimpleFormSave2' ) ); undef $meta; ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave2' ); my $text = $meta->text; @@ -729,7 +854,7 @@ sub test_simpleFormSave2 { # during saves. sub test_simpleFormSave3 { my $this = shift; - $this->createNewFoswikiSession(); + $this->createNewFoswikiApp; my ($oldmeta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave3' ); @@ -741,23 +866,26 @@ sub test_simpleFormSave3 { undef $oldmeta; $meta->save( user => $this->test_user_login ); - my $query = Unit::Request->new( - initializer => { - action => ['save'], - text => [$testtext_nometa], - formtemplate => ['TestForm1'], - 'Select' => ['Value_2'], - 'Radio' => ['3'], - 'Checkbox' => ['red'], - 'CheckboxandButtons' => ['hamster'], - 'Textfield' => ['Test'], - topic => [ $this->test_web . '.SimpleFormSave3' ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => [$testtext_nometa], + formtemplate => ['TestForm1'], + 'Select' => ['Value_2'], + 'Radio' => ['3'], + 'Checkbox' => ['red'], + 'CheckboxandButtons' => ['hamster'], + 'Textfield' => ['Test'], + topic => [ $this->test_web . '.SimpleFormSave3' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - $this->session->topicExists( $this->test_web, 'SimpleFormSave3' ) ); + $this->app->store->topicExists( $this->test_web, 'SimpleFormSave3' ) ); undef $meta; ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave3' ); my $text = $meta->text; @@ -772,20 +900,23 @@ sub test_simpleFormSave3 { # The purpose of this test is to confirm that we can save the value 0 # We have made this bug several times in history sub test_simpleFormSaveZeroValue { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - formtemplate => ['TestForm1'], - action => ['save'], - 'Textfield' => ['0'], - topic => [ $this->test_web . '.SimpleFormSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + formtemplate => ['TestForm1'], + action => ['save'], + 'Textfield' => ['0'], + topic => [ $this->test_web . '.SimpleFormSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - $this->session->topicExists( $this->test_web, 'SimpleFormSave' ) ); + $this->app->store->topicExists( $this->test_web, 'SimpleFormSave' ) ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave' ); my $text = $meta->text; $this->assert_matches( qr/^CORRECT\s*$/, $text ); @@ -800,20 +931,23 @@ sub test_simpleFormSaveZeroValue { # Testing empty value form field values - Item9970 # The purpose of this test is to confirm that we can save an empty value sub test_simpleFormSaveEmptyValue { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ['CORRECT'], - formtemplate => ['TestForm1'], - action => ['save'], - 'Textfield' => [''], - topic => [ $this->test_web . '.SimpleFormSave' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ['CORRECT'], + formtemplate => ['TestForm1'], + action => ['save'], + 'Textfield' => [''], + topic => [ $this->test_web . '.SimpleFormSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert( - $this->session->topicExists( $this->test_web, 'SimpleFormSave' ) ); + $this->app->store->topicExists( $this->test_web, 'SimpleFormSave' ) ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'SimpleFormSave' ); my $text = $meta->text; $this->assert_matches( qr/^CORRECT\s*$/, $text ); @@ -831,15 +965,18 @@ sub test_templateTopicWithMeta { Foswiki::Func::saveTopicText( $this->test_web, "TemplateTopic", $testtext1 ); - my $query = Unit::Request->new( - initializer => { - templatetopic => ['TemplateTopic'], - action => ['save'], - topic => [ $this->test_web . '.TemplateTopicWithMeta' ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + templatetopic => ['TemplateTopic'], + action => ['save'], + topic => [ $this->test_web . '.TemplateTopicWithMeta' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'TemplateTopicWithMeta' ); my $text = $meta->text; @@ -854,12 +991,16 @@ sub test_templateTopicWithMeta { sub test_templateTopicWithAttachments { my $this = shift; - $this->assert( - open( my $FILE, ">", "$Foswiki::cfg{TempfileDir}/testfile.txt" ) ); + my $FILE; + my $testfile = $this->app->cfg->data->{TempfileDir} . "/testfile.txt"; + $this->assert( open( $FILE, ">", $testfile ), "Write to $testfile: $!" ); print $FILE "one two three"; $this->assert( close($FILE) ); $this->assert( - open( $FILE, ">", "$Foswiki::cfg{TempfileDir}/testfile2.txt" ) ); + open( + $FILE, ">", $this->app->cfg->data->{TempfileDir} . "/testfile2.txt" + ) + ); print $FILE "four five six"; $this->assert( close($FILE) ); @@ -888,15 +1029,18 @@ sub test_templateTopicWithAttachments { } ); - my $query = Unit::Request->new( - initializer => { - templatetopic => ['TemplateTopic'], - action => ['save'], - topic => [ $this->test_web . ".$testTopic" ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + templatetopic => ['TemplateTopic'], + action => ['save'], + topic => [ $this->test_web . ".$testTopic" ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ( $meta, $text ) = Foswiki::Func::readTopic( $this->test_web, $testTopic ); @@ -922,7 +1066,7 @@ sub test_templateTopicWithAttachments { sub test_merge { my $this = shift; - $this->createNewFoswikiSession(); + $this->createNewFoswikiApp; # Set up the original topic that the two edits started on my ($oldmeta) = Foswiki::Func::readTopic( $this->test_web, 'MergeSave' ); @@ -941,61 +1085,65 @@ sub test_merge { # Now build a query for the save at the end of the first edit, # forcing a revision increment. - my $query1 = Unit::Request->new( - initializer => { - action => ['save'], - text => ["Soggy bat"], - originalrev => $original, - forcenewrevision => 1, - formtemplate => ['TestForm4'], - 'Select' => ['Value_2'], - 'Radio' => ['3'], - 'Checkbox' => ['red'], - 'CheckboxandButtons' => ['hamster'], - 'Textfield' => ['Bat'], - 'Textarea' => [ <<'GUMP' ], + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ["Soggy bat"], + originalrev => $original, + forcenewrevision => 1, + formtemplate => ['TestForm4'], + 'Select' => ['Value_2'], + 'Radio' => ['3'], + 'Checkbox' => ['red'], + 'CheckboxandButtons' => ['hamster'], + 'Textfield' => ['Bat'], + 'Textarea' => [ <<'GUMP' ], Glug Glug Blog Glog Bungdit Din Glaggie GUMP - topic => [ $this->test_web . '.MergeSave' ] - } + topic => [ $this->test_web . '.MergeSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - - # Do the save - $this->createNewFoswikiSession( $this->test_user_login, $query1 ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $info = $meta->getRevisionInfo(); #print STDERR "First edit saved as $info->{version}_$info->{date}\n"; # Build a second query for the other save, based on the same original # version as the previous edit - my $query2 = Unit::Request->new( - initializer => { - action => ['save'], - text => ["Wet rat"], - originalrev => $original, - formtemplate => ['TestForm4'], - 'Select' => ['Value_2'], - 'Radio' => ['3'], - 'Checkbox' => ['red'], - 'CheckboxandButtons' => ['hamster'], - 'Textfield' => ['Rat'], - 'Textarea' => [ <<'GUMP' ], + # This time we expect a merge exception + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ["Wet rat"], + originalrev => $original, + formtemplate => ['TestForm4'], + 'Select' => ['Value_2'], + 'Radio' => ['3'], + 'Checkbox' => ['red'], + 'CheckboxandButtons' => ['hamster'], + 'Textfield' => ['Rat'], + 'Textarea' => [ <<'GUMP' ], Spletter Glug Blog Splut Bungdit Din GUMP - topic => [ $this->test_web . '.MergeSave' ] - } + topic => [ $this->test_web . '.MergeSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_2_login, }, }, + callbacks => { handleRequestException => \&_cbHRE }, ); - - # Do the save. This time we expect a merge exception - $this->createNewFoswikiSession( $this->test_user_2_login, $query2 ); try { - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); } catch { my $e = shift; @@ -1044,91 +1192,6 @@ ZIS return; } -# CC commented this test out, because it doesn't bear any relationship to any -# documented interaction mode for the save script :-/ -#sub test_restoreRevision { -# my $this = shift; -# -# # first write topic without meta -# my $query = Unit::Request->new({ -# text => [ 'FIRST REVISION' ], -# action => [ 'save' ], -# topic => [ $this->test_web.'.DeleteTestRestoreRevisionTopic' ] -# }); -# $this->createNewFoswikiSession( $this->test_user_login, $query ); -# $this->captureWithKey( save => &$UI_FN, $this->session); -# -# # retrieve revision number -# my ($meta) = Foswiki::Func::readTopic($this->test_web, 'DeleteTestRestoreRevisionTopic'); -# my $text = $meta->text; -# my $info = $meta->getRevisionInfo(); -# -# my $original = "$info->{version}_$info->{date}"; -# $this->assert_equals(1, $info->{version}); -# -# # write second revision with meta -# $query = Unit::Request->new({ -# action => [ 'save' ], -# text => [ 'SECOND REVISION' ], -# originalrev => $original, -# forcenewrevision => 1, -# formtemplate => [ 'TestForm1' ], -# 'Select' => [ 'Value_2' ], -# 'Radio' => [ '3' ], -# 'Checkbox' => [ 'red' ], -# 'CheckboxandButtons' => [ 'hamster' ], -# 'Textfield' => [ 'Test' ], -# topic => [ $this->test_web.'.DeleteTestRestoreRevisionTopic' ] -# }); -# $this->createNewFoswikiSession( $this->test_user_login, $query); -# $this->captureWithKey( save => $UI_FN, $this->session); -# -# ($meta) = Foswiki::Func::readTopic($this->test_web, 'DeleteTestRestoreRevisionTopic'); -# $text = $meta->text; -# $info = $meta->getRevisionInfo(); -# $original = "$info->{version}_$info->{date}"; -# $this->assert_equals(2, $info->{version}); -# -# # now restore topic to revision 1 -# # the form should be removed as well -# $query = Unit::Request->new({ -# action => [ 'manage' ], -# rev => 1, -# forcenewrevision => 1, -# topic => [ $this->test_web.'.DeleteTestRestoreRevisionTopic' ] -# }); -# $this->createNewFoswikiSession( $this->test_user_login, $query ); -# $this->captureWithKey( save => $UI_FN, $this->session); -# ($meta) = Foswiki::Func::readTopic($this->test_web, 'DeleteTestRestoreRevisionTopic'); -# $text = $meta->text; -# $info = $meta->getRevisionInfo(); -# $original = "$info->{version}_$info->{date}"; -# $this->assert_equals(3, $info->{version}); -# $this->assert_matches(qr/FIRST REVISION/, $text); -# $this->assert_null($meta->get('FORM')); -# -# # and restore topic to revision 2 -# # the form should be re-appended -# $query = Unit::Request->new({ -# action => [ 'manage' ], -# rev => 2, -# forcenewrevision => 1, -# topic => [ $this->test_web.'.DeleteTestRestoreRevisionTopic' ] -# }); -# $this->createNewFoswikiSession( $this->test_user_login, $query ); -# $this->captureWithKey( save => $UI_FN, $this->session); -# ($meta) = Foswiki::Func::readTopic($this->test_web, 'DeleteTestRestoreRevisionTopic'); -# $text = $meta->text; -# $info = $meta->getRevisionInfo(); -# $original = "$info->{version}_$info->{date}"; -# $this->assert_equals(4, $info->{rev}); -# $this->assert_matches(qr/SECOND REVISION/, $text); -# $this->assert_not_null($meta->get('FORM')); -# $this->assert_str_equals('TestForm1', $meta->get('FORM')->{name}); -# # field default values should be all '' -# $this->assert_str_equals('Test', $meta->get('FIELD', 'Textfield' )->{value}); -#} - # test interaction with reprev. Testcase: # # 1. A edits and saves (rev 1 now on disc) @@ -1144,7 +1207,8 @@ sub test_1897 { # make sure we have time to complete the test $Foswiki::cfg{ReplaceIfEditedAgainWithin} = 7200; - $this->createNewFoswikiSession( $this->test_user_login ); + $this->createNewFoswikiApp( engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); my ($oldmeta) = Foswiki::Func::readTopic( $this->test_web, 'MergeSave' ); my $oldtext = $testtext1; @@ -1174,16 +1238,19 @@ sub test_1897 { sleep(1); # tick the clock to ensure the date changes # A saves again, reprev triggers to create rev 1 again - $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ["Sweaty\ncat"], - originalrev => $original, - topic => [ $this->test_web . '.MergeSave' ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ["Sweaty\ncat"], + originalrev => $original, + topic => [ $this->test_web . '.MergeSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); # make sure it's still rev 1 as expected my $text2; @@ -1199,17 +1266,21 @@ sub test_1897 { $this->assert( $repRevDate != $orgDate ); # User B saves; make sure we get a merge notice. - $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ["Smelly\nrat"], - originalrev => $original, - topic => [ $this->test_web . '.MergeSave' ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ["Smelly\nrat"], + originalrev => $original, + topic => [ $this->test_web . '.MergeSave' ] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_2_login, }, }, + callbacks => { handleRequestException => \&_cbHRE }, ); - $this->createNewFoswikiSession( $this->test_user_2_login, $query ); try { - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); } catch { my $e = shift; @@ -1243,7 +1314,8 @@ sub test_cmdEqualsReprev { # make sure we have time to complete the test $Foswiki::cfg{ReplaceIfEditedAgainWithin} = 7200; - $this->createNewFoswikiSession( $this->test_user_login ); + $this->createNewFoswikiApp( engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); my ($oldmeta) = Foswiki::Func::readTopic( $this->test_web, 'RepRev' ); my $oldtext = $testtext1; @@ -1269,17 +1341,21 @@ sub test_cmdEqualsReprev { sleep(1); # tick the clock to ensure the date changes # admin reprevs to create rev 1 again with new text - $query = Unit::Request->new( - initializer => { - action => ['save'], - text => ["A Tale of Two Cities"], - cmd => ['repRev'], - topic => [ $this->test_web . '.RepRev' ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + text => ["A Tale of Two Cities"], + cmd => ['repRev'], + topic => [ $this->test_web . '.RepRev' ] + }, + }, + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{SuperAdminGroup}, }, + }, ); - - $this->createNewFoswikiSession( $Foswiki::cfg{SuperAdminGroup}, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); # make sure it's still rev 1 as expected my $text2; @@ -1302,18 +1378,23 @@ sub test_cmdEqualsReprev { } sub test_missingTemplateTopic { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - templatetopic => ['NonExistantTemplateTopic'], - action => ['save'], - topic => [ $this->test_web . '.FlibbleDeDib' ] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + templatetopic => ['NonExistantTemplateTopic'], + action => ['save'], + topic => [ $this->test_web . '.FlibbleDeDib' ] + }, + }, + engineParams => { + initialAttributes => + { user => $this->test_user_login, method => 'post', }, + }, + callbacks => { handleRequestException => \&_cbHRE }, ); - $query->method('post'); - $this->createNewFoswikiSession( $this->test_user_login, $query ); try { - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); } catch { my $e = shift; @@ -1329,17 +1410,23 @@ sub test_missingTemplateTopic { } sub test_addform { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['addform'], - topic => [ $this->test_web . "." . $this->test_topic ], - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['addform'], + topic => [ $this->test_web . "." . $this->test_topic ], + }, + }, + engineParams => { + initialAttributes => + { user => $this->test_user_login, method => 'POST', }, + }, + callbacks => { handleRequestException => \&_cbHRE }, ); - $query->method('POST'); - $this->createNewFoswikiSession( $this->test_user_login, $query ); try { - my ($text) = $this->captureWithKey( save => $UI_FN, $this->session ); + my ($text) = + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); foreach my $val (qw(TestForm1 TestForm2 TestForm3 TestForm4)) { ( my $tf ) = $text =~ m/.*().*/; @@ -1356,17 +1443,22 @@ sub test_addform { sub test_get { my $this = shift; - my $query = Unit::Request->new( - initializer => { - action => ['save'], - topic => [ $this->test_web . "." . $this->test_topic ] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + action => ['save'], + topic => [ $this->test_web . "." . $this->test_topic ] + }, + }, + engineParams => { + initialAttributes => + { user => $this->test_user_login, method => 'GET', }, + }, + callbacks => { handleRequestException => \&_cbHRE }, ); - $query->method('GET'); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - try { - my ($text) = $this->captureWithKey( save => $UI_FN, $this->session ); + my ($text) = + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); $this->assert_matches( qr/^Status: 403.*$/m, $text ); } catch { @@ -1378,20 +1470,23 @@ sub test_get { } sub test_preferenceSave { - my $this = shift; - my $query = Unit::Request->new( - initializer => { - text => ["CORRECT\n * Set UNSETME = x\n"], - action => ['save'], - topic => [ $this->test_web . '.PrefTopic' ], - "Set+SETME" => ['set me'], - "Set+SETME2" => ['set me 2'], - "Local+LOCALME" => ['local me'], - "Local+LOCALME2" => ['local me 2'] - } + my $this = shift; + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ["CORRECT\n * Set UNSETME = x\n"], + action => ['save'], + topic => [ $this->test_web . '.PrefTopic' ], + "Set+SETME" => ['set me'], + "Set+SETME2" => ['set me 2'], + "Local+LOCALME" => ['local me'], + "Local+LOCALME2" => ['local me 2'] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, 'PrefTopic' ); my $text = $meta->text; $this->assert_equals( 'local me', @@ -1404,23 +1499,26 @@ sub test_preferenceSave { $meta->get( 'PREFERENCE', 'SETME2' )->{value} ); undef $meta; - $query = Unit::Request->new( - initializer => { - text => ["CORRECT\n * Set UNSETME = x\n"], - action => ['save'], - topic => [ $this->test_web . '.PrefTopic' ], - "Unset+SETME" => [1], - "Unset+LOCALME2" => [1], - - # Default+ does nothing without a corresponding Set+ or Local+ - "Set+SETME2" => ['set me 2'], - "Local+LOCALME" => ['local me'], - "Default+LOCALME" => ['local me'], - "Default+SETME2" => ['set me 2'] - } + $this->createNewFoswikiApp( + requestParams => { + initializer => { + text => ["CORRECT\n * Set UNSETME = x\n"], + action => ['save'], + topic => [ $this->test_web . '.PrefTopic' ], + "Unset+SETME" => [1], + "Unset+LOCALME2" => [1], + + # Default+ does nothing without a corresponding Set+ or Local+ + "Set+SETME2" => ['set me 2'], + "Local+LOCALME" => ['local me'], + "Default+LOCALME" => ['local me'], + "Default+SETME2" => ['set me 2'] + }, + }, + engineParams => + { initialAttributes => { user => $this->test_user_login, }, }, ); - $this->createNewFoswikiSession( $this->test_user_login, $query ); - $this->captureWithKey( save => $UI_FN, $this->session ); + $this->captureWithKey( save => sub { $this->app->handleRequest }, ); ($meta) = Foswiki::Func::readTopic( $this->test_web, 'PrefTopic' ); $text = $meta->text; $this->assert_null( $meta->get( 'PREFERENCE', 'SETME' ) ); diff --git a/core/bin/attach b/core/bin/attach index 16914df0f4..6b579eab38 100755 --- a/core/bin/attach +++ b/core/bin/attach @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/changes b/core/bin/changes index 16914df0f4..6b579eab38 100755 --- a/core/bin/changes +++ b/core/bin/changes @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/edit b/core/bin/edit index 16914df0f4..6b579eab38 100755 --- a/core/bin/edit +++ b/core/bin/edit @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/logon b/core/bin/logon index 16914df0f4..6b579eab38 100755 --- a/core/bin/logon +++ b/core/bin/logon @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/manage b/core/bin/manage index 16914df0f4..6b579eab38 100755 --- a/core/bin/manage +++ b/core/bin/manage @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/oops b/core/bin/oops index 16914df0f4..6b579eab38 100755 --- a/core/bin/oops +++ b/core/bin/oops @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/preview b/core/bin/preview index 16914df0f4..6b579eab38 100755 --- a/core/bin/preview +++ b/core/bin/preview @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/previewauth b/core/bin/previewauth index 16914df0f4..6b579eab38 100755 --- a/core/bin/previewauth +++ b/core/bin/previewauth @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/rdiff b/core/bin/rdiff index 16914df0f4..6b579eab38 100755 --- a/core/bin/rdiff +++ b/core/bin/rdiff @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/rdiffauth b/core/bin/rdiffauth index 16914df0f4..6b579eab38 100755 --- a/core/bin/rdiffauth +++ b/core/bin/rdiffauth @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/register b/core/bin/register index 16914df0f4..6b579eab38 100755 --- a/core/bin/register +++ b/core/bin/register @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/rename b/core/bin/rename index 16914df0f4..6b579eab38 100755 --- a/core/bin/rename +++ b/core/bin/rename @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/resetpasswd b/core/bin/resetpasswd index 16914df0f4..6b579eab38 100755 --- a/core/bin/resetpasswd +++ b/core/bin/resetpasswd @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/rest b/core/bin/rest index 16914df0f4..6b579eab38 100755 --- a/core/bin/rest +++ b/core/bin/rest @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/restauth b/core/bin/restauth index 16914df0f4..6b579eab38 100755 --- a/core/bin/restauth +++ b/core/bin/restauth @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/save b/core/bin/save index 16914df0f4..6b579eab38 100755 --- a/core/bin/save +++ b/core/bin/save @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/search b/core/bin/search index 16914df0f4..6b579eab38 100755 --- a/core/bin/search +++ b/core/bin/search @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/statistics b/core/bin/statistics index 16914df0f4..6b579eab38 100755 --- a/core/bin/statistics +++ b/core/bin/statistics @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/upload b/core/bin/upload index 16914df0f4..6b579eab38 100755 --- a/core/bin/upload +++ b/core/bin/upload @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/viewauth b/core/bin/viewauth index 16914df0f4..6b579eab38 100755 --- a/core/bin/viewauth +++ b/core/bin/viewauth @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/bin/viewfileauth b/core/bin/viewfileauth index 16914df0f4..6b579eab38 100755 --- a/core/bin/viewfileauth +++ b/core/bin/viewfileauth @@ -1,32 +1,9 @@ #! /usr/bin/env perl # See bottom of file for license and copyright information -use strict; -use warnings; - -use File::Spec; - -BEGIN { - if ( defined $ENV{GATEWAY_INTERFACE} || defined $ENV{MOD_PERL} ) { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI'; - use CGI::Carp qw(fatalsToBrowser); - $SIG{__DIE__} = \&CGI::Carp::confess; - } - else { - $Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI'; - require Carp; - $SIG{__DIE__} = \&Carp::confess; - } - my ( $volume, $binDir, $action ) = File::Spec->splitpath(__FILE__); - my $setlib = File::Spec->catpath( $volume, $binDir, 'setlib.cfg' ); - @INC = ( '.', grep { $_ ne '.' } @INC ) unless $binDir; - require $setlib; - $action =~ s/\..*$//; # Remove eventual file extension - $ENV{FOSWIKI_ACTION} = $action; -} - -use Foswiki (); -use Foswiki::UI (); -$Foswiki::engine->run(); +use Cwd; +use lib Cwd::abs_path("../lib"); +use Foswiki::App; +exit Foswiki::App->run; __END__ Foswiki - The Free and Open Source Wiki, http://foswiki.org/ diff --git a/core/lib/Foswiki/Response.pm b/core/lib/Foswiki/Response.pm index a39ed5a3f8..587e8271f9 100644 --- a/core/lib/Foswiki/Response.pm +++ b/core/lib/Foswiki/Response.pm @@ -429,7 +429,11 @@ sub pushHeader { # Wrapper method for the object attribute. sub cookies { my $this = shift; - $this->setCookies(@_) if @_; + if (@_) { + ASSERT( !$this->outputHasStarted, 'Too late to change cookies' ) + if DEBUG; + $this->setCookies(@_) if @_; + } return @{ $this->getCookies }; } @@ -496,16 +500,6 @@ sub __deprecated_finalize { $req->deleteUploads; - # Finalize cookies. - # SMELL: Review comment below, from CGI: - # if the user indicates an expiration time, then we need - # both an Expires and a Date header (so that the browser is - # uses OUR clock) - $this->pushHeader( 'Set-Cookie', - Scalar::Util::blessed($_) - && $_->isa('CGI::Cookie') ? $_->as_string : $_ ) - foreach $this->cookies; - # Finalize the rest of the headers. if ( $req && $req->method && uc( $req->method ) eq 'HEAD' ) { $this->clear_body; @@ -554,6 +548,21 @@ sub as_array { push @{ $rc[1] }, $hdr => $_ foreach @$val; } + # Set cookies. + # SMELL: Review comment below, from CGI: + # if the user indicates an expiration time, then we need both an Expires + # and a Date header (so that the browser is using OUR clock) + if ( scalar( $this->cookies ) > 0 ) { + foreach my $cookie ( $this->cookies ) { + push @{ $rc[1] }, 'Set-Cookie' => ( + Scalar::Util::blessed($cookie) + && $cookie->isa('CGI::Cookie') + ? $cookie->as_string + : $cookie + ); + } + } + # Never return undef body. Though let the attribute be undef to handle some # special cases. $rc[2] = [ $this->body // '' ]; diff --git a/core/lib/Foswiki/UI/ChangeForm.pm b/core/lib/Foswiki/UI/ChangeForm.pm index b02ee809a1..a5aace8ea4 100644 --- a/core/lib/Foswiki/UI/ChangeForm.pm +++ b/core/lib/Foswiki/UI/ChangeForm.pm @@ -9,9 +9,8 @@ Service functions used by the UI packages =cut package Foswiki::UI::ChangeForm; +use v5.14; -use strict; -use warnings; use Try::Tiny; use Assert; @@ -19,6 +18,10 @@ use Foswiki (); use Foswiki::Form (); use Foswiki::Func (); +use Moo; +use namespace::clean; +extends qw(Foswiki::UI); + BEGIN { if ( $Foswiki::cfg{UseLocale} ) { require locale; @@ -28,18 +31,19 @@ BEGIN { =begin TML ----+ ClassMethod generate( $session, $web, $topic, $editaction ) +---+ ObjectMethod generate( $web, $topic, $editaction ) Generate the page that supports selection of the form. =cut sub generate { - my ( $session, $topicObject, $editaction ) = @_; - ASSERT( $session->isa('Foswiki') ) if DEBUG; + my $this = shift; + my ( $topicObject, $editaction ) = @_; - my $page = $session->templates->readTemplate('changeform'); - my $q = $session->request; + my $app = $this->app; + my $page = $app->templates->readTemplate('changeform'); + my $q = $app->request; my $formName = $q->param('formtemplate') || ''; my $fqFormName; @@ -55,7 +59,7 @@ sub generate { $fqFormName = $formName; } else { - $fqFormName = _normalizeName( $topicObject, $formName ); + $fqFormName = $this->_normalizeName( $topicObject, $formName ); } my @webforms = Foswiki::Form::getAvailableForms($topicObject); @@ -64,7 +68,7 @@ sub generate { my $formList = ''; my $formElemCount = 0; foreach my $webform (@webforms) { - my $fqwebform = _normalizeName( $topicObject, $webform ); + my $fqwebform = $this->_normalizeName( $topicObject, $webform ); $formElemCount++; $formList .= CGI::br() if ($formList); @@ -98,7 +102,7 @@ sub generate { if $parent; $page =~ s/%TOPICPARENT%/$parent/g; - my $redirectTo = $session->redirectto() || ''; + my $redirectTo = $app->redirectto() || ''; $page =~ s/%REDIRECTTO%/$redirectTo/g; my $text = ''; @@ -118,6 +122,7 @@ sub generate { } sub _normalizeName { + my $this = shift; my ( $topicObject, $name ) = @_; if ($name) {