From a6db13d739a6e051948dbac93f275a8e3169601e Mon Sep 17 00:00:00 2001 From: Vadim Belman Date: Thu, 30 Jun 2016 12:38:10 -0400 Subject: [PATCH] Item13897: All basic tests are passing... ... except for SeleniumConfigTests. - Unified TOC macro calling syntax to match all other macros and make it callable through execMacro(). - execMacro() can now accept additional arguments to pass them over to the macro being called. - Incorporated a fix to Request from the master. --- UnitTestContrib/lib/Unit/TestRunner.pm | 41 +++--- UnitTestContrib/test/unit/Fn_SEARCH.pm | 26 ++-- UnitTestContrib/test/unit/Fn_TOPICLIST.pm | 2 + UnitTestContrib/test/unit/Fn_USERINFO.pm | 9 +- UnitTestContrib/test/unit/FormDefTests.pm | 15 +- UnitTestContrib/test/unit/FormattingTests.pm | 9 +- .../test/unit/FoswikiStoreTestCase.pm | 17 ++- UnitTestContrib/test/unit/FoswikiTestCase.pm | 33 +++-- UnitTestContrib/test/unit/FuncTests.pm | 131 +++++++++++++----- UnitTestContrib/test/unit/FuncUsersTests.pm | 51 +++++-- .../test/unit/HTMLValidationTests.pm | 15 +- .../test/unit/HierarchicalWebsTests.pm | 3 + UnitTestContrib/test/unit/InitFormTests.pm | 5 +- UnitTestContrib/test/unit/ManageDotPmTests.pm | 65 +++++---- UnitTestContrib/test/unit/QueryTests.pm | 2 + UnitTestContrib/test/unit/RenderFormTests.pm | 3 + UnitTestContrib/test/unit/RequestTests.pm | 90 ++++++------ UnitTestContrib/test/unit/TOCTests.pm | 18 ++- UnitTestContrib/test/unit/ViewScriptTests.pm | 5 +- core/lib/Foswiki/Macros.pm | 8 +- core/lib/Foswiki/Macros/TOC.pm | 31 +++-- core/lib/Foswiki/Meta.pm | 10 +- core/lib/Foswiki/Object.pm | 9 +- core/lib/Foswiki/Request.pm | 16 ++- core/lib/Foswiki/Request/Upload.pm | 1 - 25 files changed, 397 insertions(+), 218 deletions(-) diff --git a/UnitTestContrib/lib/Unit/TestRunner.pm b/UnitTestContrib/lib/Unit/TestRunner.pm index ccd32bbbbc..d87c83fed4 100644 --- a/UnitTestContrib/lib/Unit/TestRunner.pm +++ b/UnitTestContrib/lib/Unit/TestRunner.pm @@ -11,11 +11,12 @@ script that runs testcases. =cut -use Devel::Symdump(); -use File::Spec(); use Try::Tiny; use Unit::TestCase; use Foswiki::Exception (); +use Unit::Eavesdrop (); +use Devel::Symdump (); +use File::Spec (); use Moo; use namespace::clean; @@ -24,7 +25,7 @@ extends 'Foswiki::Object'; use Assert; -sub CHECKLEAK { 0 } +sub CHECKLEAK { 0 || $ENV{FOSWIKI_CHECKLEAK} } BEGIN { if (CHECKLEAK) { @@ -424,7 +425,7 @@ sub runOneInNewProcess { "-worker", $suite,, $testToRun, $tempfilename ); my $command = join( ' ', @command ); - print "Running: $command\n"; + print "RUNNING AS PROCESS: $command\n"; $ENV{PATH} =~ /(.*)/; $ENV{PATH} = $1; # untaint @@ -498,13 +499,12 @@ DIE $tempfilename = $1; my $suite = $testSuiteModule; - eval "use $suite"; - die $@ if $@; + + Foswiki::load_package($suite); my $tester = $suite->new( testSuite => $suite ); my $log = "stdout.$$.log"; - require Unit::Eavesdrop; open( my $logfh, ">", $log ) || die $!; print STDERR "Logging to $log\n"; my $stdout = new Unit::Eavesdrop('STDOUT'); @@ -518,17 +518,22 @@ DIE my $action = __PACKAGE__->runOne( $tester, $suite, $testToRun ); { - local $SIG{__WARN__} = sub { die $_[0]; }; - eval { close $logfh; }; - if ($@) { - if ( $@ =~ /Bad file descriptor/ and $suite eq 'EngineTests' ) { - - # This is expected - ignore it - } - else { - - # propagate the error - die $@; + local $SIG{__WARN__} = sub { + my $e = shift; + Foswiki::Exception::Fatal->rethrow($e); + }; + try { + close $logfh; + } + catch { + my $e = Foswiki::Exception::Fatal->transmute( $_, 0 ); + my $errmsg = $e->stringify; + unless ($errmsg =~ /Bad file descriptor/ + and $suite eq 'EngineTests' ) + { + + # Expected for EngineTests - ignore it. Otherwise – rethrow. + $e->rethrow; } } } diff --git a/UnitTestContrib/test/unit/Fn_SEARCH.pm b/UnitTestContrib/test/unit/Fn_SEARCH.pm index bb96bcce50..6e3691464e 100644 --- a/UnitTestContrib/test/unit/Fn_SEARCH.pm +++ b/UnitTestContrib/test/unit/Fn_SEARCH.pm @@ -51,6 +51,9 @@ our $AElig; around set_up => sub { my $orig = shift; my ($this) = shift; + + $this->app->cfg->data->{DisableAllPlugins} = 1; + $orig->( $this, @_ ); my $timestamp = time(); @@ -1482,7 +1485,6 @@ sub test_nofinalnewline { sub test_formatted_search_summary_with_exclamation_marks { my $this = shift; - my $app = $this->app; $this->set_up_for_formatted_search(); my $actual, my $expected; @@ -1510,7 +1512,6 @@ sub test_formatted_search_summary_with_exclamation_marks { # Item8718 sub test_formatted_search_with_exclamation_marks_inside_bracket_link { my $this = shift; - my $app = $this->app; $this->set_up_for_formatted_search(); my $actual, my $expected; @@ -1589,7 +1590,6 @@ sub test_format_displayed_value { sub test_METASEARCH { my $this = shift; - my $app = $this->app; $this->set_up_for_formatted_search(); my $actual, my $expected; @@ -2755,7 +2755,6 @@ sub verify_getTopicList { sub verify_casesensitivesetting { my $this = shift; - my $app = $this->app; my $actual, my $expected; @@ -4088,8 +4087,12 @@ Number of topics: 4 CRUD # Now we create the WikiGuest user topic, to test both outputs - my $app = $this->app; - if ( !$app->store->topicExists( 'TemporarySEARCHUsersWeb', 'WikiGuest' ) ) { + if ( + !$this->app->store->topicExists( + 'TemporarySEARCHUsersWeb', 'WikiGuest' + ) + ) + { my ($userTopic) = Foswiki::Func::readTopic( 'TemporarySEARCHUsersWeb', 'WikiGuest' ); $userTopic->text('Just this poor old WikiGuest'); @@ -4097,7 +4100,9 @@ CRUD undef $userTopic; } $this->assert( - $app->store->topicExists( 'TemporarySEARCHUsersWeb', 'WikiGuest' ), + $this->app->store->topicExists( + 'TemporarySEARCHUsersWeb', 'WikiGuest' + ), 'Failed to create user topic in TemporarySEACHUsersWeb' ); @@ -6813,10 +6818,11 @@ HERE $this->createNewFoswikiApp( requestParams => { initializer => '', }, engineParams => { - initialAttributes => - { path_info => "/$test_web/" . $this->test_topic, }, + initialAttributes => { + path_info => "/$test_web/" . $this->test_topic, + user => $this->app->cfg->data->{AdminUserLogin}, + }, }, - user => $this->app->cfg->data->{AdminUserLogin}, ); $this->assert_str_equals( $this->test_web, $this->app->request->web ); while ( my ( $fwaddress, $metatext ) = each %topics ) { diff --git a/UnitTestContrib/test/unit/Fn_TOPICLIST.pm b/UnitTestContrib/test/unit/Fn_TOPICLIST.pm index bde0de474a..662846b1c7 100644 --- a/UnitTestContrib/test/unit/Fn_TOPICLIST.pm +++ b/UnitTestContrib/test/unit/Fn_TOPICLIST.pm @@ -23,6 +23,8 @@ around set_up => sub { my $orig = shift; my $this = shift; + $this->app->cfg->data->{DisableAllPlugins} = 1; + $orig->( $this, @_ ); $Foswiki::cfg{EnableHierarchicalWebs} = 1; my $webObject = $this->populateNewWeb( $this->test_web . "/SubWeb" ); diff --git a/UnitTestContrib/test/unit/Fn_USERINFO.pm b/UnitTestContrib/test/unit/Fn_USERINFO.pm index 7e66e97c2e..67dc107b77 100644 --- a/UnitTestContrib/test/unit/Fn_USERINFO.pm +++ b/UnitTestContrib/test/unit/Fn_USERINFO.pm @@ -108,7 +108,8 @@ sub test_antispam { $Foswiki::cfg{AntiSpam}{HideUserDetails} = 1; # ScumBag should only see his own information - $this->createNewFoswikiApp( user => "ScumBag" ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => "ScumBag" }, }, ); my $ui = $this->test_topicObject->expandMacros(<<"HERE"); %USERINFO{"ScumBag" format="$testformat"}% HERE @@ -139,7 +140,11 @@ HERE # Admin user should see everything $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); $ui = $this->test_topicObject->expandMacros(<<"HERE"); %USERINFO{"ScumBag" format="$testformat"}% HERE diff --git a/UnitTestContrib/test/unit/FormDefTests.pm b/UnitTestContrib/test/unit/FormDefTests.pm index 97a046bbdd..a857c5e26e 100644 --- a/UnitTestContrib/test/unit/FormDefTests.pm +++ b/UnitTestContrib/test/unit/FormDefTests.pm @@ -13,6 +13,15 @@ extends qw( FoswikiFnTestCase ); use Assert; +around set_up => sub { + my $orig = shift; + my $this = shift; + + $this->app->cfg->data->{DisableAllPlugins} = 1; + + $orig->( $this, @_ ); +}; + sub test_minimalForm { my $this = shift; @@ -338,7 +347,11 @@ sub test_Item10987_formObjClass { my ($this) = @_; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserWikiName} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserWikiName}, }, + }, + ); my $formObj = Foswiki::Form->loadCached( $this->app, $Foswiki::cfg{SystemWebName}, 'UserForm' ); diff --git a/UnitTestContrib/test/unit/FormattingTests.pm b/UnitTestContrib/test/unit/FormattingTests.pm index cdd586fe4b..7846105dc7 100644 --- a/UnitTestContrib/test/unit/FormattingTests.pm +++ b/UnitTestContrib/test/unit/FormattingTests.pm @@ -225,8 +225,7 @@ around set_up => sub { my $orig = shift; my $this = shift; - $| = 1; - + $this->app->cfg->data->{DisableAllPlugins} = 1; $orig->( $this, @_ ); $this->sup( $this->app->cfg->getScriptUrl( 0, 'view' ) ); my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'H_' ); @@ -1909,7 +1908,11 @@ sub _create_link_test_fixtures { $this->_create_topic( $this->test_web, 'Aa' ); $this->_create_topic( $this->test_web, 'AA' ); $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); Foswiki::Func::createWeb('Aa'); $this->_create_topic( 'Aa', 'Bb' ); Foswiki::Func::createWeb('AA'); diff --git a/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm b/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm index b80fef0c77..e0e4b8de5b 100644 --- a/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm +++ b/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm @@ -8,6 +8,7 @@ use utf8; # # Subclasses are expected to implement set_up_for_verify() # +use Foswiki::Exception (); use File::Spec(); use Try::Tiny; @@ -55,7 +56,7 @@ around set_up => sub { my $orig = shift; my $this = shift; $orig->( $this, @_ ); - $Foswiki::cfg{EnableHierarchicalWebs} = 1; + $this->app->cfg->data->{EnableHierarchicalWebs} = 1; # Data for attachments $this->t_data( join( '', map( chr($_), ( 0 .. 255 ) ) ) ); @@ -97,14 +98,22 @@ sub fixture_groups { next unless $alg =~ s/^(.*)\.pm$/$1/; next if $alg =~ m/RcsWrap/ && !$this->rcs_installed; ($alg) = $alg =~ m/^(.*)$/ms; # untaint - Foswiki::load_package("Foswiki::Store::$alg"); + my $module = "Foswiki::Store::$alg"; + try { + Foswiki::load_package($module); + } + catch { + my $errmsg = Foswiki::Exception::errorStr( + Foswiki::Exception::Fatal->transmute( $_, 0 ) ); + say STDERR "Skipping ", $module, + " because of the error: ", $errmsg; + }; my $algname = $alg; next if defined &{$algname}; no strict 'refs'; *{$algname} = sub { my $self = shift; - $Foswiki::cfg{Store}{Implementation} = - 'Foswiki::Store::' . $alg; + $Foswiki::cfg{Store}{Implementation} = $module; $self->set_up_for_verify(); }; use strict 'refs'; diff --git a/UnitTestContrib/test/unit/FoswikiTestCase.pm b/UnitTestContrib/test/unit/FoswikiTestCase.pm index 34bcde72b6..a44ad552c3 100644 --- a/UnitTestContrib/test/unit/FoswikiTestCase.pm +++ b/UnitTestContrib/test/unit/FoswikiTestCase.pm @@ -783,18 +783,19 @@ s/((\$Foswiki::cfg\{.*?\})\s*=.*?;)(?:\n|$)/push(@moreConfig, $1) unless (eval " # Force completion of %Foswiki::cfg # This must be done before moving the logging. $cfgData->{Store}{Implementation} = 'Foswiki::Store::PlainFile'; - $this->pushApp; - my $tmp = Unit::TestApp->new( - user => undef, - env => $this->app->cloneEnv, - cfg => $this->app->cfg->clone, - ); - ASSERT( $tmp->cfg->app == $tmp, - "Object app attr doesn't point to the new app" ); - ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS; - undef $tmp; # finish() will be called automatically. - ASSERT( !defined $Foswiki::app ) if SINGLE_SINGLETONS; - $this->popApp; + + #$this->pushApp; + #my $tmp = Unit::TestApp->new( + # user => undef, + # env => $this->app->cloneEnv, + # cfg => $this->app->cfg->clone, + #); + #ASSERT( $tmp->cfg->app == $tmp, + # "Object app attr doesn't point to the new app" ); + #ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS; + #undef $tmp; # finish() will be called automatically. + #ASSERT( !defined $Foswiki::app ) if SINGLE_SINGLETONS; + #$this->popApp; # 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 @@ -1107,6 +1108,12 @@ sub createNewFoswikiApp { $this->app($app); $this->_fixupAppObjects; + # WorkDir is set to _tempDir but _tempDir might be cleaned up before $app + # gets completely shutdown. This draws some app frameworks to fail upon + # cleanup as they rely upon WorkDir. By storing the _tempDir object on app's + # heap we let them shutdown cleanly. + $app->heap->{TestCase_TempDir} = $this->_tempDir; + ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS; if ( $this->test_web && $this->test_topic ) { @@ -1255,6 +1262,7 @@ sub _fixupAppObjects { sub pushApp { my $this = shift; + my %params; my $holderObj = $this->localize(@_); @@ -1270,6 +1278,7 @@ sub popApp { pop @{ $this->_holderStack }; $Foswiki::app = $this->app; + $this->app->cfg->_setupGLOBs; $this->_fixupAppObjects; } diff --git a/UnitTestContrib/test/unit/FuncTests.pm b/UnitTestContrib/test/unit/FuncTests.pm index d0d7e20634..7e359acb62 100644 --- a/UnitTestContrib/test/unit/FuncTests.pm +++ b/UnitTestContrib/test/unit/FuncTests.pm @@ -103,7 +103,7 @@ around BUILDARGS => sub { around set_up => sub { my $orig = shift; my $this = shift; - $| = 1; + $this->app->cfg->data->{DisableAllPlugins} = 1; $orig->( $this, @_ ); my ($topicObject) = Foswiki::Func::readTopic( @@ -217,7 +217,11 @@ sub test_createWeb_permissions { $this->pushApp; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); my $defaultUserWikiName = $this->app->cfg->data->{DefaultUserWikiName}; $this->assert( @@ -268,7 +272,11 @@ qr/Access to CHANGE TemporaryFuncTestWebFunc\/Blahsub. for BaseUserMapping_666 i "Test should not have created the web" ); $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); Foswiki::Func::saveTopicText( $this->test_web, 'WebPreferences', <<"END", @@ -327,7 +335,11 @@ sub test_Item9021 { $this->app->cfg->data->{EnableHierarchicalWebs} = 1; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); try { Foswiki::Func::createWeb( $this->test_web . "Missing/Blah" ); @@ -356,7 +368,11 @@ sub test_createWeb_InvalidBase { $this->app->cfg->data->{EnableHierarchicalWebs} = 1; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); try { Foswiki::Func::createWeb( $this->test_web . "InvaliBase", @@ -382,7 +398,11 @@ sub test_createWeb_hierarchyDisabled { $this->app->cfg->data->{EnableHierarchicalWebs} = 0; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); try { Foswiki::Func::createWeb( $this->test_web . "/Subweb" ); @@ -952,7 +972,8 @@ sub test_noauth_saveTopic { my $ttext = " APPLE \n * Set ALLOWTOPICVIEW = SomeUser \n * Set DENYTOPICCHANGE = BaseUserMapping_666,MrWhite \n "; - $this->createNewFoswikiApp( user => $userLogin ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => $userLogin, }, }, ); Foswiki::Func::saveTopicText( $this->test_web, $topic, $ttext ); $this->assert( Foswiki::Func::topicExists( $this->test_web, $topic ) ); @@ -1796,7 +1817,11 @@ sub test_checkWebAccessPermission { my $this = shift; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); my $defaultUserWikiName = $this->app->cfg->data->{DefaultUserWikiName}; Foswiki::Func::saveTopicText( $this->test_web, @@ -2289,12 +2314,14 @@ sub test_eachChangeSince { sleep(1); # to move into a new time step my $start = time(); - $this->createNewFoswikiApp( user => $user1 ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => $user1, }, }, ); my ($meta) = Foswiki::Func::readTopic( $this->test_web, "ClutterBuck" ); $meta->text("One"); $meta->save(); - $this->createNewFoswikiApp( user => $user2 ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => $user2, }, }, ); undef $meta; ($meta) = Foswiki::Func::readTopic( $this->test_web, "PiggleNut" ); $meta->text("One"); @@ -2304,13 +2331,17 @@ sub test_eachChangeSince { sleep(1); my $mid = time(); - $this->createNewFoswikiApp( user => $user2 ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => $user2, }, }, ); + undef $meta; ($meta) = Foswiki::Func::readTopic( $this->test_web, "ClutterBuck" ); $meta->text("One"); $meta->save(); - $this->createNewFoswikiApp( user => $user1 ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => $user1, }, }, ); + undef $meta; ($meta) = Foswiki::Func::readTopic( $this->test_web, "PiggleNut" ); $meta->text("Two"); @@ -2392,7 +2423,11 @@ sub test_4411 { my $this = shift; $this->assert( Foswiki::Func::isGuest(), $this->app->user ); $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); $this->assert( !Foswiki::Func::isGuest(), $this->app->user ); return; @@ -2420,8 +2455,9 @@ HERE engineParams => $this->app->_cloneData( $this->app->engineParams, 'engineParams' ), ); - $this->createNewFoswikiApp( %appInitParams, - user => $this->app->cfg->data->{GuestUserLogin}, ); + $appInitParams{engineParams}{initialAttributes}{user} = + $this->app->cfg->data->{GuestUserLogin}; + $this->createNewFoswikiApp(%appInitParams); $this->assert_str_equals( "naff", Foswiki::Func::getPreferencesValue("PSIBG") ); Foswiki::Func::setPreferencesValue( "PSIBG", "KJHD" ); @@ -2434,8 +2470,7 @@ HERE HERE #$this->createNewFoswikiSession( $this->app->cfg->data->{GuestUserLogin}, $q ); - $this->createNewFoswikiApp( %appInitParams, - user => $this->app->cfg->data->{GuestUserLogin}, ); + $this->createNewFoswikiApp(%appInitParams); $this->assert_str_equals( "naff", Foswiki::Func::getPreferencesValue("PSIBG") ); Foswiki::Func::setPreferencesValue( "PSIBG", "KJHD" ); @@ -2962,36 +2997,45 @@ sub test_getUrlHost { my $query; - my $cfg = $this->app->cfg; - $cfg->data->{DefaultUrlHost} = 'http://foswiki.org'; - $cfg->data->{ForceDefaultUrlHost} = 0; + $this->app->cfg->data->{DefaultUrlHost} = 'http://foswiki.org'; + $this->app->cfg->data->{ForceDefaultUrlHost} = 0; $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => { setUrl => 'http://localhost/Main/SvenDowideit', }, + engineParams => { + intialAttributes => + { setUrl => 'http://localhost/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( $this->app->cfg->data->{DefaultUrlHost}, Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'http://localhost:8080/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'http://localhost:8080/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( 'http://localhost:8080', Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => { setUrl => 'https://localhost/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'https://localhost/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( 'https://localhost', Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'https://localhost:8080/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'https://localhost:8080/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( 'https://localhost:8080', Foswiki::Func::getUrlHost() ); @@ -2999,16 +3043,20 @@ sub test_getUrlHost { $this->app->cfg->data->{RemovePortNumber} = 1; $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'http://localhost:8080/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'http://localhost:8080/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( $this->app->cfg->data->{DefaultUrlHost}, Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'https://localhost:8080/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'https://localhost:8080/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( 'https://localhost', Foswiki::Func::getUrlHost() ); @@ -3027,31 +3075,40 @@ sub test_getUrlHost_ForceDefaultUrlHost { $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => { setUrl => 'http://localhost/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'http://localhost/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( $this->app->cfg->data->{DefaultUrlHost}, Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'http://localhost:8080/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'http://localhost:8080/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( $this->app->cfg->data->{DefaultUrlHost}, Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'https://www.foswiki.org/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'https://www.foswiki.org/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( $this->app->cfg->data->{DefaultUrlHost}, Foswiki::Func::getUrlHost() ); $this->createNewFoswikiApp( requestParams => { initializer => "", }, - engineParams => - { setUrl => 'https:8443//www.foswiki.org/Main/SvenDowideit', }, + engineParams => { + initialAttributes => + { setUrl => 'https:8443//www.foswiki.org/Main/SvenDowideit', }, + }, ); $this->assert_str_equals( $this->app->cfg->data->{DefaultUrlHost}, Foswiki::Func::getUrlHost() ); diff --git a/UnitTestContrib/test/unit/FuncUsersTests.pm b/UnitTestContrib/test/unit/FuncUsersTests.pm index 1353501e85..6197feab4b 100644 --- a/UnitTestContrib/test/unit/FuncUsersTests.pm +++ b/UnitTestContrib/test/unit/FuncUsersTests.pm @@ -196,7 +196,11 @@ sub set_up_for_verify { my $this = shift; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); try { $this->registerUser( $loginname{UserA}, 'User', 'A', @@ -1645,7 +1649,11 @@ sub verify_addToGroup { # Force a re-read $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); $this->assert( Foswiki::Func::isGroupMember( 'ZeeGroup', 'UserZ' ) ); @@ -1655,7 +1663,11 @@ sub verify_addToGroup { # Force a re-read $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); $this->assert( Foswiki::Func::isGroupMember( 'ZeeGroup', 'UserA86' ) ); $this->assert( !Foswiki::Func::isGroupMember( 'ZeeGroup', 'UserA' ) ); @@ -1665,7 +1677,11 @@ sub verify_addToGroup { # Force a re-read $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); $this->assert( Foswiki::Func::isGroupMember( 'ZeeGroup', 'UserA86' ) ); $this->assert( Foswiki::Func::isGroupMember( 'ZeeGroup', 'UserA' ) ); @@ -1721,7 +1737,11 @@ sub verify_NestedGroups { # Force a re-read $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); #test nested groups $this->assert( Foswiki::Func::addUserToGroup( 'UserZ', 'TeeGroup', 1 ) ); @@ -1730,7 +1750,8 @@ sub verify_NestedGroups { # Force a re-read - $this->createNewFoswikiApp( user => 'UserZ' ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => 'UserZ', }, }, ); my $it = Foswiki::Func::eachGroupMember('TeeGroup'); my @list; @@ -2073,7 +2094,11 @@ sub DISABLEDverify_denyNonAdminReadOfAdminGroupTopic { # Force a re-read $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); $this->assert( Foswiki::Func::addUserToGroup( 'UserB', 'AdminGroup', 1 ) ); @@ -2087,7 +2112,11 @@ sub DISABLEDverify_denyNonAdminReadOfAdminGroupTopic { { $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserLogin} ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserLogin}, }, + }, + ); my $it = Foswiki::Func::eachGroupMember('AdminGroup'); my @list; @@ -2106,7 +2135,8 @@ sub DISABLEDverify_denyNonAdminReadOfAdminGroupTopic { # Force a re-read - $this->createNewFoswikiApp( user => 'UserB' ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => 'UserB', }, }, ); my $it = Foswiki::Func::eachGroupMember('AdminGroup'); my @list; @@ -2123,7 +2153,8 @@ sub DISABLEDverify_denyNonAdminReadOfAdminGroupTopic { # Force a re-read - $this->createNewFoswikiApp( user => 'UserZ' ); + $this->createNewFoswikiApp( + engineParams => { initialAttributes => { user => 'UserZ', }, }, ); my $it = Foswiki::Func::eachGroupMember('AdminGroup'); my @list; diff --git a/UnitTestContrib/test/unit/HTMLValidationTests.pm b/UnitTestContrib/test/unit/HTMLValidationTests.pm index 26ddc6b35a..b4fa396b50 100644 --- a/UnitTestContrib/test/unit/HTMLValidationTests.pm +++ b/UnitTestContrib/test/unit/HTMLValidationTests.pm @@ -31,8 +31,6 @@ my %expected_status = ( manage => 400, # See TODO comment below. upload => 400, # See TODO comment below. register => 501, # See TODO comment below. - rename => - 403, # SMELL Not sure if this is correct but this is what we get now. ); #TODO: this is beause we're calling the UI::function, not UI:Execute - need to re-write it to use the full engine @@ -41,9 +39,9 @@ my %expect_non_html = ( restauth => 1, viewfile => 1, viewfileauth => 1, - register => 1, #TODO: missing action make it throw an exception - manage => 1, #TODO: missing action make it throw an exception - upload => 1, #TODO: zero size upload + register => 1, #TODO: missing action make it throw an exception + manage => 1, #TODO: missing action make it throw an exception + upload => 1, #TODO: zero size upload resetpasswd => 1, ); @@ -221,8 +219,12 @@ sub call_UI_FN { #turn off ASSERTS so we get less plain text erroring - the user should always see html local $ENV{FOSWIKI_ASSERTS} = 0; + + # HomePagePlugin currently breaks everything by enforcing web/topic and + # ignoring what's been set in parameters. + $this->app->cfg->data->{Plugins}{HomePagePlugin}{Enabled} = 0; + $this->createNewFoswikiApp( - user => $this->test_user_login, env => \%ENV, requestParams => { initializer => \%constructor, }, engineParams => { @@ -230,6 +232,7 @@ sub call_UI_FN { path_info => "/$web/$topic", method => "GET", action => $this->script_name, + user => $this->test_user_login, }, }, ); diff --git a/UnitTestContrib/test/unit/HierarchicalWebsTests.pm b/UnitTestContrib/test/unit/HierarchicalWebsTests.pm index 365882400c..2b4e441904 100644 --- a/UnitTestContrib/test/unit/HierarchicalWebsTests.pm +++ b/UnitTestContrib/test/unit/HierarchicalWebsTests.pm @@ -16,7 +16,10 @@ around set_up => sub { my $orig = shift; my $this = shift; + $this->app->cfg->data->{DisableAllPlugins} = 1; + $this->app->cfg->data->{EnableHierarchicalWebs} = 1; + $this->sub_web("Subweb"); $this->sub_web_path( $this->test_web . "/" . $this->sub_web ); $orig->( $this, @_ ); diff --git a/UnitTestContrib/test/unit/InitFormTests.pm b/UnitTestContrib/test/unit/InitFormTests.pm index 5e548d2f5d..9e088e5917 100644 --- a/UnitTestContrib/test/unit/InitFormTests.pm +++ b/UnitTestContrib/test/unit/InitFormTests.pm @@ -105,7 +105,10 @@ around set_up => sub { my $cfgData = $this->app->cfg->data; - $this->createNewFoswikiApp( user => $cfgData->{AdminUserLogin} ); + $cfgData->{DisableAllPlugins} = 1; + + $this->createNewFoswikiApp( engineParams => + { initialAttributes => { user => $cfgData->{AdminUserLogin}, }, }, ); Foswiki::Func::createWeb($testweb); $this->createNewFoswikiApp; my $app = $this->app; diff --git a/UnitTestContrib/test/unit/ManageDotPmTests.pm b/UnitTestContrib/test/unit/ManageDotPmTests.pm index 9da033d04e..daf6308d95 100644 --- a/UnitTestContrib/test/unit/ManageDotPmTests.pm +++ b/UnitTestContrib/test/unit/ManageDotPmTests.pm @@ -21,8 +21,6 @@ has stderr => ( is => 'rw', ); has new_user_login => ( is => 'rw', ); has new_user_wikiname => ( is => 'rw', ); -#$Error::Debug = 1; - my $REG_TMPL; my $session_id; # Capture session ID immediately after registering a new user @@ -31,7 +29,8 @@ my $session_id; # Capture session ID immediately after registering a new user around set_up => sub { my $orig = shift; my $this = shift; - $| = 1; + + $this->app->cfg->data->{DisableAllPlugins} = 1; $orig->( $this, @_ ); $REG_TMPL = @@ -665,7 +664,11 @@ sub test_NoUserAddToNewGroupCreateAsAdmin { my $ret; $this->reCreateFoswikiApp( - user => $this->app->cfg->data->{AdminUserWikiName}, ); + engineParams => { + initialAttributes => + { user => $this->app->cfg->data->{AdminUserWikiName}, }, + }, + ); $ret = $this->addUserToGroup( { @@ -785,7 +788,6 @@ sub verify_resetEmailOkay { my $newEmail = 'brian@family.guy'; $this->createNewFoswikiApp( - user => $uname, requestParams => { initializer => { 'LoginName' => [$uname], @@ -800,6 +802,7 @@ sub verify_resetEmailOkay { initialAttributes => { path_info => '/' . $this->users_web . '/WebHome', action => 'manage', + user => $uname, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -896,7 +899,6 @@ EOM $fh->close; $this->createNewFoswikiApp( - user => $cfgData->{AdminUserWikiName}, requestParams => { initializer => { 'LogTopic' => [$logTopic], @@ -909,6 +911,7 @@ EOM initialAttributes => { path_info => "/" . $this->test_web . "/$regTopic", action => 'manage', + user => $cfgData->{AdminUserWikiName}, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1042,7 +1045,6 @@ EOM $fh->close; $this->createNewFoswikiApp( - user => $this->app->cfg->data->{AdminUserWikiName}, requestParams => { initializer => { 'LogTopic' => [$logTopic], @@ -1055,6 +1057,7 @@ EOM initialAttributes => { path_info => "/" . $this->test_web . "/$regTopic", action => 'manage', + user => $this->app->cfg->data->{AdminUserWikiName}, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1105,7 +1108,6 @@ sub verify_deleteUser { $this->app->users->setPassword( $cUID, $newPassU, $oldPassU ) ); $this->createNewFoswikiApp( - user => $uname, requestParams => { initializer => { 'password' => ['12345'], @@ -1117,6 +1119,7 @@ sub verify_deleteUser { initialAttributes => { path_info => "/" . $this->test_web . "/Arbitrary", action => 'manage', + user => $uname, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1174,7 +1177,6 @@ sub verify_deleteUserAsAdmin { : 'EricCartman'; $this->createNewFoswikiApp( - user => 'AdminUser', requestParams => { initializer => { 'user' => $this->new_user_wikiname, @@ -1187,6 +1189,7 @@ sub verify_deleteUserAsAdmin { method => 'POST', action => 'manage', path_info => "/System/ManagingUsers", + user => 'AdminUser', }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1282,7 +1285,6 @@ sub verify_deleteUserWithPrefix { : 'EricCartman'; $this->createNewFoswikiApp( - user => 'AdminUser', requestParams => { initializer => { 'user' => $this->new_user_wikiname, @@ -1296,6 +1298,7 @@ sub verify_deleteUserWithPrefix { path_info => "/System/ManagingUsers", method => 'POST', action => 'manage', + user => 'AdminUser', }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1332,7 +1335,6 @@ sub verify_deleteUserWithPrefix { : 'EricCartman'; $this->createNewFoswikiApp( - user => 'AdminUser', requestParams => { initializer => { 'user' => $this->new_user_wikiname, @@ -1346,6 +1348,7 @@ sub verify_deleteUserWithPrefix { path_info => "/System/ManagingUsers", method => 'POST', action => 'manage', + user => 'AdminUser', }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1421,7 +1424,6 @@ sub test_createDefaultWeb { # SMELL: Test fails unless the "user" is the AdminGroup. $this->createNewFoswikiApp( - user => $this->app->cfg->data->{SuperAdminGroup}, requestParams => { initializer => { 'action' => ['createweb'], @@ -1438,6 +1440,7 @@ sub test_createDefaultWeb { initialAttributes => { path_info => "/" . $this->test_web . "/Arbitrary", action => 'manage', + user => $this->app->cfg->data->{SuperAdminGroup}, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1518,7 +1521,6 @@ TEXT undef $testTopic; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => { 'action' => ['saveSettings'], @@ -1532,6 +1534,7 @@ TEXT initialAttributes => { path_info => "/" . $this->test_web . "/SaveSettings", action => 'manage', + user => $this->test_user_login, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1547,11 +1550,12 @@ TEXT }; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { intializer => {}, }, engineParams => { - initialAttributes => - { path_info => "/" . $this->test_web . "/SaveSettings", }, + initialAttributes => { + path_info => "/" . $this->test_web . "/SaveSettings", + user => $this->test_user_login, + }, }, ); @@ -1589,7 +1593,6 @@ TEXT undef $testTopic; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => { 'action' => ['saveSettings'], @@ -1605,6 +1608,7 @@ TEXT initialAttributes => { path_info => "/" . $this->test_web . "/SaveSettings", action => 'manage', + user => $this->test_user_login, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1623,11 +1627,12 @@ TEXT }; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => {}, }, engineParams => { - initialAttributes => - { path_info => "/" . $this->test_web . "/SaveSettings", }, + initialAttributes => { + path_info => "/" . $this->test_web . "/SaveSettings", + user => $this->test_user_login, + }, }, ); @@ -1663,7 +1668,6 @@ TEXT undef $testTopic; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => { 'action' => ['saveSettings'], @@ -1677,6 +1681,7 @@ TEXT initialAttributes => { path_info => "/" . $this->test_web . "/SaveSettings", action => 'manage', + user => $this->test_user_login, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1692,11 +1697,12 @@ TEXT }; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => {}, }, engineParams => { - initialAttributes => - { path_info => "/" . $this->test_web . "/SaveSettings", }, + initialAttributes => { + path_info => "/" . $this->test_web . "/SaveSettings", + user => $this->test_user_login, + }, }, ); @@ -1732,7 +1738,6 @@ TEXT undef $testTopic; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => { 'action' => ['saveSettings'], @@ -1746,6 +1751,7 @@ TEXT initialAttributes => { path_info => "/" . $this->test_web . "/SaveSettings", action => 'manage', + user => $this->test_user_login, }, }, callbacks => { handleRequestException => \&_cbHRE, }, @@ -1770,11 +1776,12 @@ TEXT }; $this->createNewFoswikiApp( - user => $this->test_user_login, requestParams => { initializer => {}, }, engineParams => { - initialAttributes => - { path_info => "/" . $this->test_web . "/SaveSettings", }, + initialAttributes => { + path_info => "/" . $this->test_web . "/SaveSettings", + user => $this->test_user_login, + }, }, ); @@ -1801,7 +1808,6 @@ sub test_createEmptyWeb { # SMELL: Test fails unless the "user" is the AdminGroup. $this->createNewFoswikiApp( - user => $this->app->cfg->data->{SuperAdminGroup}, requestParams => { initializer => { 'action' => ['createweb'], @@ -1821,6 +1827,7 @@ sub test_createEmptyWeb { initialAttributes => { path_info => "/" . $this->test_web . "/SaveSettings", action => 'manage', + user => $this->app->cfg->data->{SuperAdminGroup}, }, }, callbacks => { handleRequestException => \&_cbHRE, }, diff --git a/UnitTestContrib/test/unit/QueryTests.pm b/UnitTestContrib/test/unit/QueryTests.pm index 1e794a40f5..94ed921989 100644 --- a/UnitTestContrib/test/unit/QueryTests.pm +++ b/UnitTestContrib/test/unit/QueryTests.pm @@ -81,6 +81,8 @@ sub skip { around set_up => sub { my $orig = shift; my $this = shift; + + $this->app->cfg->data->{DisableAllPlugins} = 1; $orig->( $this, @_ ); # Force pure perl text search; the query alg may map to a plain text diff --git a/UnitTestContrib/test/unit/RenderFormTests.pm b/UnitTestContrib/test/unit/RenderFormTests.pm index 6c823e52ca..2e42333507 100644 --- a/UnitTestContrib/test/unit/RenderFormTests.pm +++ b/UnitTestContrib/test/unit/RenderFormTests.pm @@ -49,6 +49,9 @@ CODE around set_up => sub { my $orig = shift; my $this = shift; + + $this->app->cfg->data->{DisableAllPlugins} = 1; + $orig->( $this, @_ ); Foswiki::Func::saveTopic( $this->test_web, "WebPreferences", undef, diff --git a/UnitTestContrib/test/unit/RequestTests.pm b/UnitTestContrib/test/unit/RequestTests.pm index 464794f22c..fc259096ce 100644 --- a/UnitTestContrib/test/unit/RequestTests.pm +++ b/UnitTestContrib/test/unit/RequestTests.pm @@ -19,17 +19,21 @@ around set_up => sub { # Test default empty constructor sub test_empty_new { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); - - $this->assert_str_equals( '', $req->action, '$req->action() not empty' ); - $this->assert_str_equals( '', $req->pathInfo, - '$req->pathInfo() not empty' ); - $this->assert_str_equals( '', $req->remoteAddress, - '$req->remoteAddress() not empty' ); - $this->assert_str_equals( '', $req->uri, '$req->uri() not empty' ); - $this->assert_null( $req->method, '$req->method() not null' ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); + + $this->assert_equals( $this->app->engine->pathData->{action}, + $req->action, '$req->action not set from engine' ); + $this->assert_equals( $this->app->engine->pathData->{path_info} // '', + $req->pathInfo, '$req->pathInfo not empty' ); + $this->assert_equals( $this->app->engine->connectionData->{remoteAddress}, + $req->remoteAddress, '$req->remoteAddress not set from engine' ); + $this->assert_equals( $this->app->engine->connectionData->{method}, + $req->method, '$req->method not set from engine' ); + $this->assert_equals( $this->app->engine->connectionData->{method}, + $req->method, '$req->method not set from engine' ); + $this->assert_equals( $this->app->engine->connectionData->{serverPort}, + $req->serverPort, '$req->serverPort not set from engine' ); $this->assert_null( $req->remoteUser, '$req->remoteUser() not null' ); - $this->assert_null( $req->serverPort, '$req->serverPort() not null' ); my @list = $req->header(); $this->assert_str_equals( 0, scalar @list, '$req->header not empty' ); @@ -58,7 +62,7 @@ sub test_new_from_hash { 'undef' => undef, multi_undef => [], ); - my $req = Foswiki::Request->new( initializer => \%init ); + my $req = $this->create( 'Foswiki::Request', initializer => \%init ); $this->assert_str_equals( 5, scalar $req->multi_param(), @@ -102,7 +106,7 @@ empty= EOF ); seek( $tmp, 0, 0 ); - my $req = Foswiki::Request->new( initializer => $tmp ); + my $req = $this->create( 'Foswiki::Request', initializer => $tmp ); $this->assert_str_equals( 4, scalar $req->param(), @@ -131,26 +135,26 @@ EOF sub test_action { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); + $this->assert_str_equals( $this->app->engine->pathData->{action}, + $req->action, 'Wrong initial "action" value: not set from engine' ); foreach (qw(view edit save upload preview rdiff)) { - $this->assert_str_not_equals( $_, $req->action, - 'Wrong initial "action" value' ); $req->action($_); $this->assert_str_equals( $_, $req->action, 'Wrong action value' ); - $this->assert_str_equals( $_, $ENV{FOSWIKI_ACTION}, - 'Wrong FOSWIKI_ACTION environment' ); + $this->assert_str_equals( + $_, + $this->app->env->{FOSWIKI_ACTION}, + 'Wrong FOSWIKI_ACTION environment' + ); } } sub test_method { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); + $this->assert_equals( $this->app->engine->connectionData->{method}, + $req->method, 'Wrong initial "method" value: not set from engine' ); foreach (qw(GET HEAD POST)) { - $this->assert_str_not_equals( - $_, - $req->method || '', - 'Wrong initial "method" value' - ); $req->method($_); $this->assert_str_equals( $_, $req->method, 'Wrong method value' ); } @@ -158,7 +162,7 @@ sub test_method { sub test_pathInfo { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); foreach ( qw(/ /abc /abc/ /abc/def /abc/def/), '' ) { $this->assert_str_not_equals( $_, $req->pathInfo, 'Wrong initial "pathInfo" value' ); @@ -169,7 +173,7 @@ sub test_pathInfo { sub test_protocol { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->secure(0); $this->assert_str_equals( 'http', $req->protocol, 'Wrong protocol' ); $this->assert_num_equals( 0, $req->secure, 'Wrong secure flag' ); @@ -180,7 +184,7 @@ sub test_protocol { sub test_uri { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); foreach ( qw(/ /abc/def /abc/ /Web/Topic?a=b&b=c), '' ) { $this->assert_str_not_equals( $_, $req->uri, 'Wrong initial "uri" value' ); @@ -191,7 +195,7 @@ sub test_uri { sub test_remoteAddress { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); foreach (qw(127.0.0.1 10.1.1.1 192.168.0.1)) { $req->remoteAddress($_); $this->assert_str_equals( $_, $req->remoteAddress, @@ -201,7 +205,7 @@ sub test_remoteAddress { sub test_remoteUser { my $this = shift; - my $req = Foswiki::Request->new( intializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); foreach (qw(WikiGuest guest foo bar Baz)) { $req->remoteUser($_); $this->assert_str_equals( $_, $req->remoteUser, @@ -211,7 +215,7 @@ sub test_remoteUser { sub test_serverPort { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); foreach (qw(80 443 8080)) { $req->serverPort($_); $this->assert_num_equals( $_, $req->serverPort, @@ -221,7 +225,7 @@ sub test_serverPort { sub test_queryString { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->param( -name => 'simple1', -value => 's1' ); $this->assert_equals( 'simple1=s1', $req->query_string, 'Wrong query string' ); @@ -238,12 +242,12 @@ sub test_queryString { sub perform_url_test { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); my ( $secure, $host, $action, $path ) = @_; $req->secure($secure); $req->header( Host => $host ); $req->action($action); - $req->path_info($path); + $req->pathInfo($path); $req->param( -name => 'simple1', -value => 's1 s1' ); $req->param( -name => 'simple2', -value => 's2' ); $req->multi_param( -name => 'multi', -value => [qw(m1 m2)] ); @@ -341,7 +345,7 @@ sub test_url_alien_suffix { sub test_query_param { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->queryParam( -name => 'q1', -value => 'v1' ); my @result = $req->multi_param('q1'); @@ -401,7 +405,7 @@ sub test_query_param { $this->assert_deep_equals( [ 0, '', 0 ], \@result, 'wrong value from queryParam()' ); - $req = Foswiki::Request->new( initializer => "" ); + $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->method('POST'); $req->queryParam( -name => 'q1', -value => 'v1' ); @result = $req->multi_param('q1'); @@ -414,7 +418,7 @@ sub test_query_param { sub test_body_param { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->bodyParam( -name => 'q1', -value => 'v1' ); my @result = $req->multi_param('q1'); @@ -474,7 +478,7 @@ sub test_body_param { sub test_cookies { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); my %cookies = (); $cookies{c1} = $req->cookie( -name => 'c1', -value => 'value1' ); $this->assert( @@ -534,7 +538,7 @@ sub test_cookies { sub test_delete { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->multi_param( -name => 'q2', -values => [qw(v1 v2)] ); $req->param( -name => 'q1', -value => 'v1' ); @@ -586,7 +590,7 @@ sub test_delete { sub test_delete_all { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->multi_param( -name => 'q2', -values => [qw(v1 v2)] ); $req->param( -name => 'q1', -value => 'v1' ); @@ -643,7 +647,7 @@ sub test_delete_all { sub test_header { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->header( 'h-1' => 'v1' ); my @result = $req->header('H-1'); @@ -679,7 +683,7 @@ sub test_header { sub test_save { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); scalar $req->param( -name => 'simple', -value => 's1' ); scalar $req->param( -name => 'simple2', -value => 's2' ); scalar $req->multi_param( -name => 'multi', -value => [qw(m1 m2)] ); @@ -715,7 +719,7 @@ empty= EOF ); seek( $tmp, 0, 0 ); - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); $req->load($tmp); $this->assert_str_equals( 4, @@ -745,7 +749,7 @@ EOF sub test_upload { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); require File::Temp; my $tmp = File::Temp->new( UNLINK => 1 ); @@ -785,7 +789,7 @@ EOF sub test_accessors { my $this = shift; - my $req = Foswiki::Request->new( initializer => "" ); + my $req = $this->create( 'Foswiki::Request', initializer => "" ); my $accept = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'; diff --git a/UnitTestContrib/test/unit/TOCTests.pm b/UnitTestContrib/test/unit/TOCTests.pm index e352dbf18a..d464f23c31 100644 --- a/UnitTestContrib/test/unit/TOCTests.pm +++ b/UnitTestContrib/test/unit/TOCTests.pm @@ -14,7 +14,6 @@ use Foswiki; use Foswiki::UI::Edit; use Foswiki::Form; use Foswiki::Macros::TOC; -use Unit::Request; use Unit::Response; use Moo; @@ -61,12 +60,10 @@ sub skip { sub setup_TOCtests { my ( $this, $text, $params, $tocparams ) = @_; - my $query = new Unit::Request(); + $surl = $this->app->cfg->getScriptUrl(1); - $surl = $this->session->getScriptUrl(1); - - $this->session->webName( $this->test_web ); - $this->session->topicName( $this->test_topic ); + $this->app->request->web( $this->test_web ); + $this->app->request->topic( $this->test_topic ); use Foswiki::Attrs; my $attr = new Foswiki::Attrs($params); @@ -78,7 +75,8 @@ sub setup_TOCtests { # Now generate the TOC my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, $this->test_topic ); - my $res = $this->session->TOC( $text, $topicObject, $tocparams ); + my $res = + $this->app->macros->execMacro( 'TOC', $tocparams, $topicObject, $text ); eval 'use HTML::TreeBuilder; use HTML::Element;'; if ($@) { @@ -182,7 +180,7 @@ s/
/<\/a>
session->getScriptUrl( 0, 'view' ); + my $url = $this->app->cfg->getScriptUrl( 0, 'view' ); my $text = <<'HERE'; ---+ A level 1 head!line @@ -227,7 +225,7 @@ s/
/<\/a>
session->getScriptUrl( 0, 'view' ); + my $url = $this->app->cfg->getScriptUrl( 0, 'view' ); my $text = <<'HERE'; ---+ A level 1 head!line @@ -270,7 +268,7 @@ s/
/<\/a>
session->getScriptUrl( 0, 'view' ); + my $url = $this->app->cfg->getScriptUrl( 0, 'view' ); my $text = <<'HERE'; %TOC% diff --git a/UnitTestContrib/test/unit/ViewScriptTests.pm b/UnitTestContrib/test/unit/ViewScriptTests.pm index 0038b2baae..5310fb355b 100644 --- a/UnitTestContrib/test/unit/ViewScriptTests.pm +++ b/UnitTestContrib/test/unit/ViewScriptTests.pm @@ -88,6 +88,7 @@ around BUILDARGS => sub { around set_up => sub { my $orig = shift; my $this = shift; + $this->app->cfg->data->{DisableAllPlugins} = 1; $orig->( $this, @_ ); #set up nested web $this->test_web/Nest @@ -207,9 +208,9 @@ around createNewFoswikiApp => sub { my $orig = shift; my $this = shift; - my $app = $orig->( $this, @_ ); + $this->app->cfg->data->{DisableAllPlugins} = 1; - $app->cfg->data->{DisableAllPlugins} = 1; + my $app = $orig->( $this, @_ ); return $app; }; diff --git a/core/lib/Foswiki/Macros.pm b/core/lib/Foswiki/Macros.pm index 3a0da45167..14627f70a1 100644 --- a/core/lib/Foswiki/Macros.pm +++ b/core/lib/Foswiki/Macros.pm @@ -166,10 +166,9 @@ sub expandMacros { # are complete, and has to reprocess the entire topic. if ( $text =~ m/%TOC(?:\{.*\})?%/ ) { - Foswiki::load_package('Foswiki::Macros::TOC'); my $tocInstance = 1; $text =~ -s/%TOC(?:\{(.*?)\})?%/$this->TOC($text, $topicObject, $1, $tocInstance++)/ge; +s/%TOC(?:\{(.*?)\})?%/$this->execMacro('TOC', $1, $topicObject, $text, $tocInstance++)/ge; } # Codev.FormattedSearchWithConditionalOutput: remove lines, @@ -668,7 +667,7 @@ Executes macro defined by its name $macroName. sub execMacro { my $this = shift; - my ( $macroName, $attrs, $topicObject ) = @_; + my ( $macroName, $attrs, $topicObject, @macroArgs ) = @_; my $rc; @@ -692,7 +691,8 @@ sub execMacro { if ( ref( $this->registered->{$macroName} ) eq 'CODE' ) { $rc = - $this->registered->{$macroName}->( $this->app, $attrs, $topicObject ); + $this->registered->{$macroName} + ->( $this->app, $attrs, $topicObject, @macroArgs ); } else { # Create macro object unless it already exists. diff --git a/core/lib/Foswiki/Macros/TOC.pm b/core/lib/Foswiki/Macros/TOC.pm index e2828a6474..95b3f2c048 100644 --- a/core/lib/Foswiki/Macros/TOC.pm +++ b/core/lib/Foswiki/Macros/TOC.pm @@ -37,19 +37,22 @@ BEGIN { # * $headingPatternDa : ---++... dashes section heading # * $headingPatternHt : <h[1-6]> HTML section heading </h[1-6]> sub TOC { - my ( $this, $text, $topicObject, $args, $tocInstance ) = @_; - - my $app = $this->app; + my ( $this, $args, $topicObject, $text, $tocInstance ) = @_; require Foswiki::Attrs; - my $params = new Foswiki::Attrs($args); - my $isSameTopic = 1; # is the toc for this topic? + my $params = + UNIVERSAL::isa( $args, 'Foswiki::Attrs' ) + ? $args + : new Foswiki::Attrs($args); + my $isSameTopic = 1; # is the toc for this topic? my $tocTopic = $params->{_DEFAULT}; my $tocWeb = $params->{web}; my $tocId = $params->{id}; my $align = $params->{align}; + $text //= $topicObject->text; + unless ( defined $tocId ) { $tocInstance = '' if ( !defined $tocInstance || $tocInstance eq '1' ); $tocId = 'foswikiTOC' . $tocInstance; @@ -59,7 +62,7 @@ sub TOC { $tocWeb ||= $topicObject->web; $tocTopic ||= $topicObject->topic; ( $tocWeb, $tocTopic ) = - $app->request->normalizeWebTopicName( $tocWeb, $tocTopic ); + $this->request->normalizeWebTopicName( $tocWeb, $tocTopic ); if ( $tocWeb eq $topicObject->web && $tocTopic eq $topicObject->topic ) { @@ -69,9 +72,9 @@ sub TOC { # Data for topic coming from another topic $params->{differentTopic} = 1; - $topicObject = Foswiki::Meta->load( $app, $tocWeb, $tocTopic ); + $topicObject = Foswiki::Meta->load( $this, $tocWeb, $tocTopic ); if ( !$topicObject->haveAccess('VIEW') ) { - return $app->inlineAlert( 'alerts', 'access_denied', + return $this->inlineAlert( 'alerts', 'access_denied', $tocWeb, $tocTopic ); } $text = $topicObject->text; @@ -100,15 +103,15 @@ sub TOC { $text =~ s/\0/{depth}; - $maxDepth ||= $app->prefs->getPreference('TOC_MAX_DEPTH') + $maxDepth ||= $this->prefs->getPreference('TOC_MAX_DEPTH') || 6; - my $minDepth = $app->prefs->getPreference('TOC_MIN_DEPTH') + my $minDepth = $this->prefs->getPreference('TOC_MIN_DEPTH') || 1; # get the title attribute my $title = $params->{title} - || $app->prefs->getPreference('TOC_TITLE') + || $this->prefs->getPreference('TOC_TITLE') || ''; $title = CGI::span( { class => 'foswikiTocTitle' }, $title ) if ($title); @@ -116,7 +119,7 @@ sub TOC { my $result = ''; # Find URL parameters - my $query = $app->request; + my $query = $this->request; my @qparams = (); foreach my $name ( $query->param ) { next if ( $name eq 'keywords' ); @@ -139,7 +142,7 @@ sub TOC { # clear the set of unique anchornames in order to inhibit # the 'relabeling' of anchor names if the same topic is processed # more than once, cf. explanation in expandMacros() - my $anchors = $app->renderer->getAnchorNames($topicObject); + my $anchors = $this->renderer->getAnchorNames($topicObject); $anchors->clear(); $text =~ s/^(\#$Foswiki::regex{wikiWordRegex})/ @@ -232,7 +235,7 @@ sub TOC { $isSameTopic ? Foswiki::make_params(@qparams) . '#' . $a->{anchor} - : $app->cfg->getScriptUrl( + : $this->cfg->getScriptUrl( 0, 'view', $topicObject->web, $topicObject->topic, '#' => $a->{anchor}, @qparams diff --git a/core/lib/Foswiki/Meta.pm b/core/lib/Foswiki/Meta.pm index 528e582ffa..f74fae9efd 100644 --- a/core/lib/Foswiki/Meta.pm +++ b/core/lib/Foswiki/Meta.pm @@ -636,8 +636,14 @@ which may have surprising effects on other code that shares the object. sub unload { my $this = shift; +#if ( DEBUG && !defined $this->{app} ) { +# say STDERR Carp::longmess( "App is undefined in object created at ", +# $this->__orig_file, ":", $this->__orig_line, " {{", $this->__orig_stack, "}}" ); +#} + # Delete preferences object loaded for this meta object. - delete $this->app->heap->{topic_preferences}{ $this->__id }; + delete $this->app->heap->{topic_preferences}{ $this->__id } + if defined $this->app && defined $this->app->heap->{topic_preferences}; # Avoid collisions, initiate removal from MetaCache only and only if object # has been previously stored in the cache. @@ -963,7 +969,7 @@ sub populateNewWeb { $prefsTopicObject = $this->create( $this, web => $this->web, - topic => $Foswiki::cfg{WebPrefsTopicName}, + topic => $this->app->cfg->data->{WebPrefsTopicName}, text => $prefsText ); $prefsTopicObject->save(); diff --git a/core/lib/Foswiki/Object.pm b/core/lib/Foswiki/Object.pm index a92543098b..cf280b85ca 100644 --- a/core/lib/Foswiki/Object.pm +++ b/core/lib/Foswiki/Object.pm @@ -201,7 +201,8 @@ sub _cloneData { # Check if ref has been cloned before and avoid deep recursion. if ( defined $heap->{cloning_ref}{$refAddr} ) { Foswiki::Exception::Fatal->throw( text => - "Circular dependecy detected on a object being cloned" ); +"Circular dependecy detected on a object being cloned for attribute $attr" + ); } elsif ( defined $heap->{cloned_ref}{$refAddr} ) { @@ -223,7 +224,9 @@ sub _cloneData { # Class without clone method. Try to copy it 'manually' by # cloning as a hash and blessing the resulting hashref into # $val's class. - $cloned = $this->_cloneData( \%{$val}, $attr ); + # SMELL Pretty much unreliable for complex classes. + $cloned = + $this->_cloneData( {%$val}, "$attr.blessed($class)" ); bless $cloned, ref($val) if $cloned != $val; } @@ -304,6 +307,8 @@ sub clone { my $newObj = ref($this)->new(@profile); + $this->_clear__clone_heap; + return $newObj; } diff --git a/core/lib/Foswiki/Request.pm b/core/lib/Foswiki/Request.pm index 0217366d09..de4feb731b 100644 --- a/core/lib/Foswiki/Request.pm +++ b/core/lib/Foswiki/Request.pm @@ -202,8 +202,8 @@ has method => ( ); # SMELL XXX remote_user is not used anymore, it is now Foswiki::App::remoteUser attribute. -has remote_user => ( is => 'rw', ); -has server_port => ( +has remoteUser => ( is => 'rw', ); +has serverPort => ( is => 'rw', lazy => 1, default => sub { $_[0]->app->engine->connectionData->{serverPort} }, @@ -271,8 +271,8 @@ has _pathParsed => ( *Delete = \&delete; *remote_addr = \&remote_address; *remoteAddress = \&remote_address; -*remoteUser = \&remote_user; -*serverPort = \&server_port; +*remote_user = \&remoteUser; +*server_port = \&serverPort; *delete_all = \&deleteAll; *user_agent = \&userAgent; @@ -1048,19 +1048,21 @@ sub parse { return $resp; } - my @parts = split( /\//, $query_path ); # split the path + my @parts = split( /[\/.]+/, $query_path ); # split the path # Single component. It's a web unless the $topic_flag is set. if ( scalar(@parts) eq 1 ) { print STDERR "Checking single component:\n" if TRACE; my $resp = {}; if ($topic_flag) { - $resp->{topic} = Foswiki::Sandbox::untaint( $query_path, + $resp->{topic} = + Foswiki::Sandbox::untaint( $parts[0], \&Foswiki::Sandbox::validateTopicName ); $resp->{invalidTopic} = $parts[0] unless defined $resp->{topic}; } else { - $resp->{web} = Foswiki::Sandbox::untaint( $query_path, + $resp->{web} = + Foswiki::Sandbox::untaint( $parts[0], \&Foswiki::Sandbox::validateWebName ); $resp->{invalidWeb} = $parts[0] unless defined $resp->{web}; } diff --git a/core/lib/Foswiki/Request/Upload.pm b/core/lib/Foswiki/Request/Upload.pm index fa7a7a1213..b4a20e5ff8 100644 --- a/core/lib/Foswiki/Request/Upload.pm +++ b/core/lib/Foswiki/Request/Upload.pm @@ -38,7 +38,6 @@ sub DEMOLISH { #SMELL: Note: untaint filename. Taken from CGI.pm # (had to be updated for OSX in Dec2008) - say STDERR __PACKAGE__, "::DEMOLISH"; $this->tmpname =~ m{^([a-zA-Z0-9_\+ \'\":/.\$\\~-]+)$}; my $file = $1; if ( scalar( unlink($file) ) != 1 ) {