Ignore:
Timestamp:
01/23/12 06:00:05 (4 months ago)
Author:
PaulHarvey
Message:

Item11431: Clean UnitTests of Foswiki->new/finish

Committing what was 96 commits rebased on top of Foswikirev:13781. You
can view this full commit history at
 https://github.com/csirac2/UnitTestContrib/commits/Item11431-rebased

Tackling memory leaks, this effort seems to have saved 300MB and 10
minutes from the cost of running a full FoswikiSuite.

The recipe was:

  • Find and remove all Foswiki->new/finish calls with $this->createNewFoswikiSession()
  • Generally removed $fatwilly variables and replaced with $this->{session}, to avoid references to ->finish()'d Foswiki singleton/session objects
  • Addressed perlcriticisms in touched files
  • Convert Foswiki::Meta->new/load to Foswiki::Func::readTopic, for the sake of store2 re-integration
  • Call $topicObject->finish() where/whenever we can

Some of the tests in the default plugins need a little work, and
there's some uncommitted stuff against core lib/Foswiki.pm to help
assert SINGLE_SINGLETONS from Foswiki::new/::finish subs, we'll get
to that later...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UnitTestContrib/test/unit/AccessControlTests.pm

    r13730 r13791  
    33use warnings; 
    44 
    5 use FoswikiFnTestCase; 
     5use FoswikiFnTestCase(); 
    66our @ISA = qw( FoswikiFnTestCase ); 
    77 
     
    4141    $this->SUPER::set_up(); 
    4242 
    43     my $topicObject = Foswiki::Meta->new( 
    44         $this->{session}, 
    45         $Foswiki::cfg{UsersWebName}, 
    46         $Foswiki::cfg{DefaultUserWikiName}, '' 
    47     ); 
    48     $topicObject->save(); 
     43    my ($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, 
     44        $Foswiki::cfg{DefaultUserWikiName} ); 
     45    $topicObject->text(''); 
     46    $topicObject->save(); 
     47    $topicObject->finish(); 
    4948    $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); 
    5049    $MrWhite = $this->{session}->{users}->getCanonicalUserID('white'); 
     
    5857    $MrYellow = $this->{session}->{users}->getCanonicalUserID('yellow'); 
    5958 
    60     $topicObject = 
    61       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    62         "ReservoirDogsGroup", <<"THIS"); 
     59    $this->createNewFoswikiSession(); 
     60    ($topicObject) = 
     61      Foswiki::Func::readTopic( $this->{users_web}, "ReservoirDogsGroup" ); 
     62    $topicObject->text(<<"THIS"); 
    6363   * Set GROUP = MrWhite, $this->{users_web}.MrBlue 
    6464THIS 
    6565    $topicObject->save(); 
    66  
    67     return; 
    68 } 
    69  
    70 sub tear_down { 
    71     my $this = shift; 
    72     $this->SUPER::tear_down(); 
     66    $topicObject->finish(); 
    7367 
    7468    return; 
     
    7973    $web   ||= $this->{test_web}; 
    8074    $topic ||= $this->{test_topic}; 
    81     my $topicObject = Foswiki::Meta->load( $this->{session}, $web, $topic ); 
     75    my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 
    8276    $this->assert( !$topicObject->haveAccess( $mode, $user ), 
    8377        "$user $mode $web.$topic" ); 
     
    106100        ); 
    107101    } 
     102    $topicObject->finish(); 
    108103 
    109104    return; 
     
    114109    $web   ||= $this->{test_web}; 
    115110    $topic ||= $this->{test_topic}; 
    116     my $topicObject = Foswiki::Meta->load( $this->{session}, $web, $topic ); 
     111    my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 
    117112    $this->assert( $topicObject->haveAccess( $mode, $user ), 
    118113        "$user $mode $web.$topic" ); 
     
    141136        ); 
    142137    } 
     138    $topicObject->finish(); 
    143139 
    144140    return; 
     
    152148sub test_denytopic { 
    153149    my $this = shift; 
    154     my $topicObject = 
    155       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    156         $this->{test_topic}, <<"THIS"); 
     150    my ($topicObject) = 
     151      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     152    $topicObject->text(<<"THIS"); 
    157153If DENYTOPIC is set to a list of wikinames 
    158154    * people in the list will be DENIED. 
     
    161157THIS 
    162158    $topicObject->save(); 
    163  
    164     $this->{session}->finish(); 
    165     $this->{session} = Foswiki->new(); 
    166  
     159    $topicObject->finish(); 
     160 
     161    $this->createNewFoswikiSession(); 
    167162    $this->PERMITTED( "VIEW", $MrGreen ); 
    168163    $this->DENIED( "VIEW", $MrYellow ); 
     
    177172sub test_empty_denytopic { 
    178173    my $this = shift; 
    179     my $topicObject = 
    180       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    181         $this->{test_topic}, <<'THIS'); 
     174    my ($topicObject) = 
     175      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     176    $topicObject->text(<<'THIS'); 
    182177If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 
    183178    * access is PERMITTED _i.e _ no-one is denied access to this topic 
     
    185180THIS 
    186181    $topicObject->save(); 
    187  
    188     $this->{session}->finish(); 
    189     $this->{session} = Foswiki->new(); 
     182    $topicObject->finish(); 
     183 
     184    $this->createNewFoswikiSession(); 
    190185    $this->PERMITTED( "VIEW", $MrGreen ); 
    191186    $this->PERMITTED( "VIEW", $MrYellow ); 
     
    200195sub test_whitespace_denytopic { 
    201196    my $this = shift; 
    202     my $topicObject = 
    203       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    204         $this->{test_topic}, <<'THIS'); 
     197    my ($topicObject) = 
     198      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     199    $topicObject->text(<<'THIS'); 
    205200If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 
    206201    * access is PERMITTED _i.e _ no-one is denied access to this topic 
     
    208203THIS 
    209204    $topicObject->save(); 
    210  
    211     $this->{session}->finish(); 
    212     $this->{session} = Foswiki->new(); 
     205    $topicObject->finish(); 
     206 
     207    $this->createNewFoswikiSession(); 
    213208    $this->PERMITTED( "VIEW", $MrGreen ); 
    214209    $this->PERMITTED( "VIEW", $MrYellow ); 
     
    223218sub test_denytopic_whitespace { 
    224219    my $this = shift; 
    225     my $topicObject = 
    226       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    227         $this->{test_topic}, <<'THIS'); 
     220    my ($topicObject) = 
     221      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     222    $topicObject->text(<<'THIS'); 
    228223If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 
    229224    * access is PERMITTED _i.e _ no-one is denied access to this topic 
     
    231226THIS 
    232227    $topicObject->save(); 
    233  
    234     $this->{session}->finish(); 
    235     $this->{session} = Foswiki->new(); 
     228    $topicObject->finish(); 
     229 
     230    $this->createNewFoswikiSession(); 
    236231    $this->PERMITTED( "VIEW", $MrGreen ); 
    237232    $this->PERMITTED( "VIEW", $MrYellow ); 
     
    246241sub test_allowtopic { 
    247242    my $this = shift; 
    248     my $topicObject = 
    249       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    250         $this->{test_topic}, <<'THIS'); 
     243    my ($topicObject) = 
     244      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     245    $topicObject->text(<<'THIS'); 
    251246If ALLOWTOPIC is set 
    252247   1. people in the list are PERMITTED 
     
    255250THIS 
    256251    $topicObject->save(); 
    257  
    258     $this->{session}->finish(); 
    259     $this->{session} = Foswiki->new(); 
     252    $topicObject->finish(); 
     253 
     254    $this->createNewFoswikiSession(); 
    260255    $this->PERMITTED( "VIEW", $MrOrange ); 
    261256    $this->DENIED( "VIEW", $MrGreen ); 
     
    271266sub test_allowtopic_a { 
    272267    my $this = shift; 
    273     my $topicObject = 
    274       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    275         $this->{test_topic}, <<'THIS'); 
     268    my ($topicObject) = 
     269      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     270    $topicObject->text(<<'THIS'); 
    276271If ALLOWTOPIC is set 
    277272   1. people in the list are PERMITTED 
     
    280275THIS 
    281276    $topicObject->save(); 
     277    $topicObject->finish(); 
    282278 
    283279    my $topicquery = Unit::Request->new(""); 
     
    285281 
    286282    # renew Foswiki, so WebPreferences gets re-read 
    287     $this->{session}->finish(); 
    288     $this->{session} = Foswiki->new( undef, $topicquery ); 
     283    $this->createNewFoswikiSession(); 
    289284    $this->PERMITTED( "VIEW", $MrOrange ); 
    290     $this->{session}->finish(); 
    291     $this->{session} = Foswiki->new( undef, $topicquery ); 
     285    $this->createNewFoswikiSession( undef, $topicquery ); 
    292286    $this->DENIED( "VIEW", $MrGreen ); 
    293     $this->{session}->finish(); 
    294     $this->{session} = Foswiki->new( undef, $topicquery ); 
     287    $this->createNewFoswikiSession( undef, $topicquery ); 
    295288    $this->DENIED( "VIEW", $MrYellow ); 
    296     $this->{session}->finish(); 
    297     $this->{session} = Foswiki->new( undef, $topicquery ); 
     289    $this->createNewFoswikiSession( undef, $topicquery ); 
    298290    $this->DENIED( "VIEW", $MrWhite ); 
    299     $this->{session}->finish(); 
    300     $this->{session} = Foswiki->new( undef, $topicquery ); 
     291    $this->createNewFoswikiSession( undef, $topicquery ); 
    301292    $this->DENIED( "view", $MrBlue ); 
    302293 
     
    309300sub test_allowtopic_b { 
    310301    my $this = shift; 
    311     my $topicObject = 
    312       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    313         $this->{test_topic}, <<'THIS'); 
     302    my ($topicObject) = 
     303      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     304    $topicObject->text(<<'THIS'); 
    314305If ALLOWTOPIC is set 
    315306   1. people in the list are PERMITTED 
     
    318309THIS 
    319310    $topicObject->save(); 
     311    $topicObject->finish(); 
    320312 
    321313    # renew Foswiki, so WebPreferences gets re-read 
    322     $this->{session}->finish(); 
    323     $this->{session} = Foswiki->new(); 
     314    $this->createNewFoswikiSession(); 
    324315    $this->PERMITTED( "VIEW", $MrOrange ); 
    325     $this->{session}->finish(); 
    326     $this->{session} = Foswiki->new(); 
     316    $this->createNewFoswikiSession(); 
    327317    $this->DENIED( "VIEW", $MrGreen ); 
    328     $this->{session}->finish(); 
    329     $this->{session} = Foswiki->new(); 
     318    $this->createNewFoswikiSession(); 
    330319    $this->DENIED( "VIEW", $MrYellow ); 
    331     $this->{session}->finish(); 
    332     $this->{session} = Foswiki->new(); 
     320    $this->createNewFoswikiSession(); 
    333321    $this->DENIED( "VIEW", $MrWhite ); 
    334     $this->{session}->finish(); 
    335     $this->{session} = Foswiki->new(); 
     322    $this->createNewFoswikiSession(); 
    336323    $this->DENIED( "view", $MrBlue ); 
    337324 
     
    343330sub test_allowtopic_c { 
    344331    my $this = shift; 
    345     my $topicObject = 
    346       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    347         $this->{test_topic}, <<'THIS'); 
     332    my ($topicObject) = 
     333      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     334    $topicObject->text(<<'THIS'); 
    348335If ALLOWTOPIC is set 
    349336   1. people in the list are PERMITTED 
     
    360347    ); 
    361348    $topicObject->save(); 
     349    $topicObject->finish(); 
    362350 
    363351    # renew Foswiki, so WebPreferences gets re-read 
    364     $this->{session}->finish(); 
    365     $this->{session} = Foswiki->new(); 
     352    $this->createNewFoswikiSession(); 
    366353    $this->PERMITTED( "VIEW", $MrOrange ); 
    367     $this->{session}->finish(); 
    368     $this->{session} = Foswiki->new(); 
     354    $this->createNewFoswikiSession(); 
    369355    $this->DENIED( "VIEW", $MrGreen ); 
    370     $this->{session}->finish(); 
    371     $this->{session} = Foswiki->new(); 
     356    $this->createNewFoswikiSession(); 
    372357    $this->PERMITTED( "VIEW", $MrYellow ); 
    373     $this->{session}->finish(); 
    374     $this->{session} = Foswiki->new(); 
     358    $this->createNewFoswikiSession(); 
    375359    $this->DENIED( "VIEW", $MrWhite ); 
    376     $this->{session}->finish(); 
    377     $this->{session} = Foswiki->new(); 
     360    $this->createNewFoswikiSession(); 
    378361    $this->DENIED( "view", $MrBlue ); 
    379362 
     
    384367sub test_denyweb { 
    385368    my $this = shift; 
    386     my $topicObject = 
    387       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    388         $Foswiki::cfg{WebPrefsTopicName}, <<"THIS"); 
     369    my ($topicObject) = 
     370      Foswiki::Func::readTopic( $this->{test_web}, 
     371        $Foswiki::cfg{WebPrefsTopicName} ); 
     372    $topicObject->text(<<"THIS"); 
    389373If DENYWEB is set to a list of wikiname 
    390374    * people in the list are DENIED access 
     
    392376THIS 
    393377    $topicObject->save(); 
     378    $topicObject->finish(); 
    394379 
    395380    # renew Foswiki, so WebPreferences gets re-read 
    396     $this->{session}->finish(); 
    397     $this->{session} = Foswiki->new(); 
    398     $topicObject = Foswiki::Meta->new( 
    399         $this->{session},    $this->{test_web}, 
    400         $this->{test_topic}, "Null points" 
    401     ); 
    402     $topicObject->save(); 
     381    $this->createNewFoswikiSession(); 
     382    ($topicObject) = 
     383      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     384    $topicObject->text("Null points"); 
     385    $topicObject->save(); 
     386    $topicObject->finish(); 
     387 
    403388    $this->DENIED( "VIEW", $MrOrange ); 
    404389    $this->PERMITTED( "VIEW", $MrGreen ); 
     
    412397# Test that ALLOWWEB works in a top-level web with no finalisation 
    413398sub test_allow_web { 
    414     my $this        = shift; 
    415     my $topicObject = Foswiki::Meta->new( 
    416         $this->{session}, 
    417         $this->{test_web}, $Foswiki::cfg{WebPrefsTopicName}, 
     399    my $this = shift; 
     400    my ($topicObject) = 
     401      Foswiki::Func::readTopic( $this->{test_web}, 
     402        $Foswiki::cfg{WebPrefsTopicName} ); 
     403    $topicObject->text( 
    418404        <<'THIS' 
    419405If ALLOWWEB is set to a list of wikinames 
     
    422408   * Set ALLOWWEBVIEW = MrGreen MrYellow MrWhite 
    423409THIS 
    424         , undef 
    425     ); 
    426     $topicObject->save(); 
     410    ); 
     411    $topicObject->save(); 
     412    $topicObject->finish(); 
    427413 
    428414    # renew Foswiki, so WebPreferences gets re-read 
    429     $this->{session}->finish(); 
    430     $this->{session} = Foswiki->new(); 
    431     $topicObject = Foswiki::Meta->new( 
    432         $this->{session},    $this->{test_web}, 
    433         $this->{test_topic}, "Null points" 
    434     ); 
    435     $topicObject->save(); 
     415    $this->createNewFoswikiSession(); 
     416    ($topicObject) = 
     417      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     418    $topicObject->text("Null points"); 
     419    $topicObject->save(); 
     420    $topicObject->finish(); 
    436421    $this->DENIED( "VIEW", $MrOrange ); 
    437422    $this->PERMITTED( "VIEW", $MrGreen ); 
     
    445430# Test that Web.UserName is equivalent to UserName in ACLs 
    446431sub test_webDotUserName { 
    447     my $this        = shift; 
    448     my $topicObject = Foswiki::Meta->new( 
    449         $this->{session}, $this->{test_web}, $this->{test_topic}, 
     432    my $this = shift; 
     433    my ($topicObject) = 
     434      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     435    $topicObject->text( 
    450436        <<'THIS' 
    451437If ALLOWTOPIC is set 
     
    454440   * Set ALLOWTOPICVIEW = MrYellow,%USERSWEB%.MrOrange,Nosuchweb.MrGreen,%MAINWEB%.MrBlue,%SYSTEMWEB%.MrWhite 
    455441THIS 
    456         , undef 
    457     ); 
    458     $topicObject->save(); 
    459     $this->{session}->finish(); 
    460     $this->{session} = Foswiki->new(); 
     442    ); 
     443    $topicObject->save(); 
     444    $topicObject->finish(); 
     445    $this->createNewFoswikiSession(); 
    461446    $this->PERMITTED( "VIEW", $MrOrange ); 
    462447    $this->DENIED( "VIEW", $MrGreen ); 
     
    502487   * Set ALLOWTOPICVIEW = %USERSWEB%.MrGreen 
    503488THIS 
    504     my $topicObject = 
    505       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    506         $this->{test_topic}, $text ); 
    507     $topicObject->save(); 
    508     $this->{session}->finish(); 
    509  
    510     $this->{session} = Foswiki->new(); 
    511     $topicObject = 
    512       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    513         $this->{test_topic} ); 
     489    my ($topicObject) = 
     490      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     491    $topicObject->text($text); 
     492    $topicObject->save(); 
     493    $topicObject->finish(); 
     494    $this->createNewFoswikiSession(); 
     495 
     496    ($topicObject) = 
     497      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    514498    $this->_checkSettings($topicObject); 
     499    $topicObject->finish(); 
    515500 
    516501    return; 
     
    521506    my $this = shift; 
    522507 
    523     my $topicObject = 
    524       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    525         $this->{test_topic}, 'Empty' ); 
     508    my ($topicObject) = 
     509      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     510    $topicObject->text('Empty'); 
    526511    my $args = { 
    527512        name  => 'ALLOWTOPICVIEW', 
     
    532517    $topicObject->putKeyed( 'PREFERENCE', $args ); 
    533518    $topicObject->save(); 
    534     $this->{session}->finish(); 
    535  
    536     $this->{session} = Foswiki->new(); 
    537     $topicObject = 
    538       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    539         $this->{test_topic} ); 
     519    $topicObject->finish(); 
     520    $this->createNewFoswikiSession(); 
     521 
     522    ($topicObject) = 
     523      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    540524 
    541525    $this->_checkSettings($topicObject); 
     526    $topicObject->finish(); 
    542527 
    543528    return; 
     
    551536   * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange 
    552537THIS 
    553     my $topicObject = 
    554       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    555         $this->{test_topic}, $text ); 
     538    my ($topicObject) = 
     539      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     540    $topicObject->text($text); 
    556541    my $args = { 
    557542        name  => 'ALLOWTOPICVIEW', 
     
    562547    $topicObject->putKeyed( 'PREFERENCE', $args ); 
    563548    $topicObject->save(); 
    564     $this->{session}->finish(); 
    565  
    566     $this->{session} = Foswiki->new(); 
    567     $topicObject = 
    568       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    569         $this->{test_topic} ); 
     549    $topicObject->finish(); 
     550    $this->createNewFoswikiSession(); 
     551 
     552    ($topicObject) = 
     553      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    570554    $this->_checkSettings($topicObject); 
     555    $topicObject->finish(); 
    571556 
    572557    return; 
     
    581566 
    582567    # First build a parent web with view restricted to MrGreen 
    583     my $topicObject = 
    584       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    585         $this->{test_topic}, "Nowt" ); 
    586     $topicObject->save(); 
    587  
    588     $topicObject = 
    589       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    590         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     568    my ($topicObject) = 
     569      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     570    $topicObject->text("Nowt"); 
     571    $topicObject->save(); 
     572    $topicObject->finish(); 
     573 
     574    ($topicObject) = 
     575      Foswiki::Func::readTopic( $this->{test_web}, 
     576        $Foswiki::cfg{WebPrefsTopicName} ); 
     577    $topicObject->text(<<'THIS'); 
    591578   * Set ALLOWWEBVIEW = MrGreen 
    592579THIS 
    593580    $topicObject->save(); 
     581    $topicObject->finish(); 
    594582 
    595583    # Now build a subweb with view restricted to MrOrange 
    596584    my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 
    597585    $webObject->populateNewWeb(); 
    598     $topicObject = 
    599       Foswiki::Meta->new( $this->{session}, $subweb, 
    600         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     586    $webObject->finish(); 
     587    ($topicObject) = 
     588      Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 
     589    $topicObject->text(<<'THIS'); 
    601590   * Set ALLOWWEBVIEW = MrOrange 
    602591THIS 
    603592    $topicObject->save(); 
    604     $this->{session}->finish(); 
     593    $topicObject->finish(); 
    605594 
    606595    # Ensure that MrOrange can read the subweb and MrGreen the parent web 
    607     $this->{session} = Foswiki->new(); 
     596    $this->createNewFoswikiSession(); 
    608597    $this->PERMITTED( "VIEW", $MrOrange, $subweb ); 
    609598    $this->DENIED( "VIEW", $MrGreen, $subweb ); 
     
    623612    # First build a parent web with view restricted to MrGreen, and 
    624613    # finalise the setting 
    625     my $topicObject = 
    626       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    627         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     614    my ($topicObject) = 
     615      Foswiki::Func::readTopic( $this->{test_web}, 
     616        $Foswiki::cfg{WebPrefsTopicName} ); 
     617    $topicObject->text(<<'THIS'); 
    628618   * Set ALLOWWEBVIEW = MrGreen 
    629619   * Set FINALPREFERENCES = ALLOWWEBVIEW 
    630620THIS 
    631621    $topicObject->save(); 
     622    $topicObject->finish(); 
    632623 
    633624    # Now build a subweb with no restrictions 
    634625    my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 
    635626    $webObject->populateNewWeb(); 
    636     $topicObject = 
    637       Foswiki::Meta->new( $this->{session}, $subweb, 
    638         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
    639 THIS 
    640     $topicObject->save(); 
    641     $this->{session}->finish(); 
    642  
    643     $this->{session} = Foswiki->new(); 
     627    $webObject->finish(); 
     628    ($topicObject) = 
     629      Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 
     630    $topicObject->text(<<'THIS'); 
     631THIS 
     632    $topicObject->save(); 
     633    $topicObject->finish(); 
     634 
     635    $this->createNewFoswikiSession(); 
    644636    $this->PERMITTED( "VIEW", $MrGreen, $subweb ); 
    645637    $this->DENIED( "VIEW", $MrOrange, $subweb ); 
     
    659651    # First build a parent web with view restricted to MrGreen, and 
    660652    # finalise the setting 
    661     my $topicObject = 
    662       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    663         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     653    my ($topicObject) = 
     654      Foswiki::Func::readTopic( $this->{test_web}, 
     655        $Foswiki::cfg{WebPrefsTopicName} ); 
     656    $topicObject->text(<<'THIS'); 
    664657   * Set ALLOWWEBVIEW = MrGreen 
    665658   * Set FINALPREFERENCES = ALLOWWEBVIEW 
    666659THIS 
    667660    $topicObject->save(); 
     661    $topicObject->finish(); 
    668662 
    669663    # Now build a subweb with view restricted to MrOrange 
    670664    my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 
    671665    $webObject->populateNewWeb(); 
    672     $topicObject = 
    673       Foswiki::Meta->new( $this->{session}, $subweb, 
    674         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     666    $webObject->finish(); 
     667    ($topicObject) = 
     668      Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 
     669    $topicObject->text(<<'THIS'); 
    675670   * Set ALLOWWEBVIEW = MrOrange 
    676671THIS 
    677672    $topicObject->save(); 
    678     $this->{session}->finish(); 
    679  
    680     $this->{session} = Foswiki->new(); 
     673    $topicObject->finish(); 
     674    $this->createNewFoswikiSession(); 
     675 
    681676    $this->DENIED( "VIEW", $MrOrange, $subweb ); 
    682677    $this->PERMITTED( "VIEW", $MrGreen, $subweb ); 
     
    696691 
    697692    # Create a topic with an anchor, viewable only by MrYellow 
    698     my $topicObject = Foswiki::Meta->new( 
    699         $this->{session}, $this->{test_web}, $test_topic, 
    700         <<'THIS' 
     693    my ($topicObject) = 
     694      Foswiki::Func::readTopic( $this->{test_web}, $test_topic ); 
     695    $topicObject->text(<<'THIS'); 
    701696If there is an anchor, and some access restrictions, 
    702697anchor is preserved after login. 
     
    704699   * Set ALLOWTOPICVIEW = MrYellow 
    705700THIS 
    706         , undef 
    707     ); 
    708     $topicObject->save(); 
     701    $topicObject->save(); 
     702    $topicObject->finish(); 
    709703 
    710704    # Request the page with the full UI 
     
    720714    my $viewUrl = 
    721715      $this->{session} 
    722       ->getScriptUrl( '0', 'view', $this->{test_web}, $test_topic ); 
     716      ->getScriptUrl( 0, 'view', $this->{test_web}, $test_topic ); 
    723717    $query->uri("$viewUrl"); 
     718    $this->finishFoswikiSession(); 
    724719    my ($text) = $this->capture( 
    725720        sub { 
    726             $Foswiki::Plugins::SESSION->{response} = 
    727               Foswiki::UI::handleRequest($query); 
     721            my $response = Foswiki::UI::handleRequest($query); 
     722            $this->createNewFoswikiSession( undef, $query ); 
     723            $this->{session}{response} = $response; 
    728724        } 
    729725    ); 
     
    732728    my $loginUrl = 
    733729      $this->{session} 
    734       ->getScriptUrl( '0', 'login', $this->{test_web}, $test_topic ); 
     730      ->getScriptUrl( 0, 'login', $this->{test_web}, $test_topic ); 
    735731 
    736732    # Item11121: the test doesn't tolerate ShortURLs, for example. 
     
    748744 
    749745    # Check the redirect contains the login url + view to this topic 
    750     $this->assert_matches( 
    751         qr#^$loginUrl.*/view/$this->{test_web}/$test_topic$#, 
    752         $redirect_to, 
    753         "Login did not redirect to a page with the proper anchor:\n" 
     746    my $regex = qr#^\Q$loginUrl\E.*/view/$this->{test_web}/$test_topic$#; 
     747    $this->assert_matches( $regex, $redirect_to, 
     748            "Login did not redirect to a page with the proper anchor:\n" 
    754749          . "Location: $redirect_to\n" 
    755           . "Expected: ^$loginUrl.*\%23anchor\$" 
    756     ); 
     750          . "Expected: $regex" ); 
    757751 
    758752    # Get the redirected page after login 
Note: See TracChangeset for help on using the changeset viewer.