Changeset 13791


Ignore:
Timestamp:
01/23/12 06:00:05 (4 weeks 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...

Location:
trunk/UnitTestContrib/test/unit
Files:
42 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 
  • trunk/UnitTestContrib/test/unit/AddressTests.pm

    r13376 r13791  
    266266    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    267267 
    268     $this->{session}->finish() if $this->{session}; 
    269     $this->{session} = Foswiki->new( $Foswiki::cfg{AdminUserLogin}, $query ); 
     268    $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin}, $query ); 
    270269 
    271270    ( $this->{test_topicObject} ) = 
  • trunk/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm

    r13730 r13791  
    55#Sven wishes he could use ISA AccessControlTest, but the unit test system doesn't do inherited test subs 
    66 
    7 use FoswikiFnTestCase; 
     7use FoswikiFnTestCase(); 
    88our @ISA = qw( FoswikiFnTestCase ); 
    99 
     
    1212use Foswiki::Meta    (); 
    1313use Foswiki::Plugins (); 
     14use Foswiki::Configure::Dependency(); 
    1415 
    1516# For Anchor test 
    1617use Foswiki::UI (); 
     18 
     19my $post11 = 0; 
    1720 
    1821sub new { 
     
    2023    my $self = $class->SUPER::new( 'AccessControl', @args ); 
    2124 
     25    my $dep = new Foswiki::Configure::Dependency( 
     26        type    => "perl", 
     27        module  => "Foswiki", 
     28        version => ">=1.2" 
     29    ); 
     30    my ( $ok, $message ) = $dep->check(); 
     31    $post11 = $ok; 
     32 
    2233    return $self; 
    2334} 
    2435 
     36=todo 
    2537sub loadExtraConfig { 
    2638    my ( $this, $context, @args ) = @_; 
     
    3547    return; 
    3648} 
     49=cut 
    3750 
    3851my $MrWhite; 
     
    4659    $this->SUPER::set_up(); 
    4760 
    48     my $topicObject = Foswiki::Meta->new( 
    49         $this->{session}, 
    50         $Foswiki::cfg{UsersWebName}, 
    51         $Foswiki::cfg{DefaultUserWikiName}, '' 
    52     ); 
    53     $topicObject->save(); 
     61    my ($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, 
     62        $Foswiki::cfg{DefaultUserWikiName} ); 
     63    $topicObject->text(''); 
     64    $topicObject->save(); 
     65    $topicObject->finish(); 
    5466    $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); 
    5567    $MrWhite = $this->{session}->{users}->getCanonicalUserID('white'); 
     
    6375    $MrYellow = $this->{session}->{users}->getCanonicalUserID('yellow'); 
    6476 
    65     $topicObject = 
    66       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    67         "ReservoirDogsGroup", <<"THIS"); 
     77    $this->createNewFoswikiSession(); 
     78    ($topicObject) = 
     79      Foswiki::Func::readTopic( $this->{users_web}, "ReservoirDogsGroup" ); 
     80    $topicObject->text(<<"THIS"); 
    6881   * Set GROUP = MrWhite, $this->{users_web}.MrBlue 
    6982THIS 
    7083    $topicObject->save(); 
    71  
    72     return; 
    73 } 
    74  
    75 sub tear_down { 
    76     my $this = shift; 
    77     $this->SUPER::tear_down(); 
     84    $topicObject->finish(); 
    7885 
    7986    return; 
     
    8491    $web   ||= $this->{test_web}; 
    8592    $topic ||= $this->{test_topic}; 
    86     my $topicObject = Foswiki::Meta->load( $this->{session}, $web, $topic ); 
     93    my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 
    8794    $this->assert( !$topicObject->haveAccess( $mode, $user ), 
    8895        "$user $mode $web.$topic" ); 
     96 
     97    if ($post11) { 
     98        require Foswiki::Address; 
     99        $this->assert( 
     100            !$this->{session}->access->haveAccess( $mode, $user, $topicObject ), 
     101            "$user $mode $web.$topic" 
     102        ); 
     103        $this->assert( 
     104            !$this->{session}->access->haveAccess( 
     105                $mode, $user, $topicObject->web, $topicObject->topic 
     106            ), 
     107            "$user $mode $web.$topic" 
     108        ); 
     109        $this->assert( 
     110            !$this->{session}->access->haveAccess( 
     111                $mode, $user, 
     112                Foswiki::Address->new( 
     113                    web   => $topicObject->web, 
     114                    topic => $topicObject->topic 
     115                ) 
     116            ), 
     117            "$user $mode $web.$topic" 
     118        ); 
     119    } 
     120    $topicObject->finish(); 
    89121 
    90122    return; 
     
    95127    $web   ||= $this->{test_web}; 
    96128    $topic ||= $this->{test_topic}; 
    97     my $topicObject = Foswiki::Meta->load( $this->{session}, $web, $topic ); 
     129    my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 
    98130    $this->assert( $topicObject->haveAccess( $mode, $user ), 
    99131        "$user $mode $web.$topic" ); 
     132 
     133    if ($post11) { 
     134        require Foswiki::Address; 
     135        $this->assert( 
     136            $this->{session}->access->haveAccess( $mode, $user, $topicObject ), 
     137            "$user $mode $web.$topic" 
     138        ); 
     139        $this->assert( 
     140            $this->{session}->access->haveAccess( 
     141                $mode, $user, $topicObject->web, $topicObject->topic 
     142            ), 
     143            "$user $mode $web.$topic" 
     144        ); 
     145        $this->assert( 
     146            $this->{session}->access->haveAccess( 
     147                $mode, $user, 
     148                Foswiki::Address->new( 
     149                    web   => $topicObject->web, 
     150                    topic => $topicObject->topic 
     151                ) 
     152            ), 
     153            "$user $mode $web.$topic" 
     154        ); 
     155    } 
     156    $topicObject->finish(); 
    100157 
    101158    return; 
     
    109166sub test_denytopic { 
    110167    my $this = shift; 
    111     my $topicObject = 
    112       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    113         $this->{test_topic}, <<"THIS"); 
     168    my ($topicObject) = 
     169      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     170    $topicObject->text(<<"THIS"); 
    114171If DENYTOPIC is set to a list of wikinames 
    115172    * people in the list will be DENIED. 
     
    118175THIS 
    119176    $topicObject->save(); 
    120  
    121     $this->{session}->finish(); 
    122     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    123     $this->{session} = Foswiki->new(); 
     177    $topicObject->finish(); 
     178 
     179    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     180    $this->createNewFoswikiSession(); 
    124181 
    125182    $this->DENIED( "VIEW", $MrGreen ); 
     
    136193sub test_empty_denytopic { 
    137194    my $this = shift; 
    138     my $topicObject = 
    139       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    140         $this->{test_topic}, <<'THIS'); 
     195    my ($topicObject) = 
     196      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     197    $topicObject->text(<<'THIS'); 
    141198If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 
    142199    * access is PERMITTED _i.e _ no-one is denied access to this topic 
     
    144201THIS 
    145202    $topicObject->save(); 
    146  
    147     $this->{session}->finish(); 
    148     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    149     $this->{session} = Foswiki->new(); 
     203    $topicObject->finish(); 
     204 
     205    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     206    $this->createNewFoswikiSession(); 
    150207    $this->DENIED( "VIEW", $MrGreen ); 
    151208    $this->DENIED( "VIEW", $MrYellow ); 
     
    161218sub test_whitespace_denytopic { 
    162219    my $this = shift; 
    163     my $topicObject = 
    164       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    165         $this->{test_topic}, <<'THIS'); 
     220    my ($topicObject) = 
     221      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     222    $topicObject->text(<<'THIS'); 
    166223If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 
    167224    * access is PERMITTED _i.e _ no-one is denied access to this topic 
     
    169226THIS 
    170227    $topicObject->save(); 
    171  
    172     $this->{session}->finish(); 
    173     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    174     $this->{session} = Foswiki->new(); 
     228    $topicObject->finish(); 
     229 
     230    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     231    $this->createNewFoswikiSession(); 
    175232    $this->DENIED( "VIEW", $MrGreen ); 
    176233    $this->DENIED( "VIEW", $MrYellow ); 
     
    186243sub test_denytopic_whitespace { 
    187244    my $this = shift; 
    188     my $topicObject = 
    189       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    190         $this->{test_topic}, <<'THIS'); 
     245    my ($topicObject) = 
     246      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     247    $topicObject->text(<<'THIS'); 
    191248If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 
    192249    * access is PERMITTED _i.e _ no-one is denied access to this topic 
     
    194251THIS 
    195252    $topicObject->save(); 
    196  
    197     $this->{session}->finish(); 
    198     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    199     $this->{session} = Foswiki->new(); 
     253    $topicObject->finish(); 
     254 
     255    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     256    $this->createNewFoswikiSession(); 
    200257    $this->DENIED( "VIEW", $MrGreen ); 
    201258    $this->DENIED( "VIEW", $MrYellow ); 
     
    211268sub test_allowtopic { 
    212269    my $this = shift; 
    213     my $topicObject = 
    214       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    215         $this->{test_topic}, <<'THIS'); 
     270    my ($topicObject) = 
     271      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     272    $topicObject->text(<<'THIS'); 
    216273If ALLOWTOPIC is set 
    217274   1. people in the list are PERMITTED 
     
    220277THIS 
    221278    $topicObject->save(); 
    222  
    223     $this->{session}->finish(); 
    224     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    225     $this->{session} = Foswiki->new(); 
     279    $topicObject->finish(); 
     280 
     281    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     282    $this->createNewFoswikiSession(); 
    226283    $this->DENIED( "VIEW", $MrOrange ); 
    227284    $this->DENIED( "VIEW", $MrGreen ); 
     
    238295sub test_allowtopic_a { 
    239296    my $this = shift; 
    240     my $topicObject = 
    241       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    242         $this->{test_topic}, <<'THIS'); 
     297    my ($topicObject) = 
     298      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     299    $topicObject->text(<<'THIS'); 
    243300If ALLOWTOPIC is set 
    244301   1. people in the list are PERMITTED 
     
    247304THIS 
    248305    $topicObject->save(); 
     306    $topicObject->finish(); 
    249307 
    250308    my $topicquery = Unit::Request->new(""); 
    251309    $topicquery->path_info("/$this->{test_web}/$this->{test_topic}"); 
    252310 
    253     # reFoswiki->new, so WebPreferences gets re-read 
    254     $this->{session}->finish(); 
    255     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    256     $this->{session} = Foswiki->new( undef, $topicquery ); 
    257     $this->DENIED( "VIEW", $MrOrange ); 
    258     $this->{session}->finish(); 
    259     $this->{session} = Foswiki->new( undef, $topicquery ); 
    260     $this->DENIED( "VIEW", $MrGreen ); 
    261     $this->{session}->finish(); 
    262     $this->{session} = Foswiki->new( undef, $topicquery ); 
    263     $this->DENIED( "VIEW", $MrYellow ); 
    264     $this->{session}->finish(); 
    265     $this->{session} = Foswiki->new( undef, $topicquery ); 
    266     $this->DENIED( "VIEW", $MrWhite ); 
    267     $this->{session}->finish(); 
    268     $this->{session} = Foswiki->new( undef, $topicquery ); 
    269     $this->DENIED( "view", $MrBlue ); 
    270     $this->{session}->finish(); 
    271     $this->{session} = Foswiki->new(); 
     311    # renew Foswiki, so WebPreferences gets re-read 
     312    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     313    $this->createNewFoswikiSession( undef, $topicquery ); 
     314    $this->DENIED( "VIEW", $MrOrange ); 
     315    $this->createNewFoswikiSession( undef, $topicquery ); 
     316    $this->DENIED( "VIEW", $MrGreen ); 
     317    $this->createNewFoswikiSession( undef, $topicquery ); 
     318    $this->DENIED( "VIEW", $MrYellow ); 
     319    $this->createNewFoswikiSession( undef, $topicquery ); 
     320    $this->DENIED( "VIEW", $MrWhite ); 
     321    $this->createNewFoswikiSession( undef, $topicquery ); 
     322    $this->DENIED( "view", $MrBlue ); 
     323    $this->createNewFoswikiSession( undef, $topicquery ); 
    272324    $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 
    273325 
     
    280332sub test_allowtopic_b { 
    281333    my $this = shift; 
    282     my $topicObject = 
    283       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    284         $this->{test_topic}, <<'THIS'); 
     334    my ($topicObject) = 
     335      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     336    $topicObject->text(<<'THIS'); 
    285337If ALLOWTOPIC is set 
    286338   1. people in the list are PERMITTED 
     
    289341THIS 
    290342    $topicObject->save(); 
    291  
    292     # reFoswiki->new, so WebPreferences gets re-read 
    293     $this->{session}->finish(); 
    294     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    295     $this->{session} = Foswiki->new(); 
    296     $this->DENIED( "VIEW", $MrOrange ); 
    297     $this->{session}->finish(); 
    298     $this->{session} = Foswiki->new(); 
    299     $this->DENIED( "VIEW", $MrGreen ); 
    300     $this->{session}->finish(); 
    301     $this->{session} = Foswiki->new(); 
    302     $this->DENIED( "VIEW", $MrYellow ); 
    303     $this->{session}->finish(); 
    304     $this->{session} = Foswiki->new(); 
    305     $this->DENIED( "VIEW", $MrWhite ); 
    306     $this->{session}->finish(); 
    307     $this->{session} = Foswiki->new(); 
    308     $this->DENIED( "view", $MrBlue ); 
    309     $this->{session}->finish(); 
    310     $this->{session} = Foswiki->new(); 
     343    $topicObject->finish(); 
     344 
     345    # renew Foswiki, so WebPreferences gets re-read 
     346    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     347    $this->createNewFoswikiSession(); 
     348    $this->DENIED( "VIEW", $MrOrange ); 
     349    $this->createNewFoswikiSession(); 
     350    $this->DENIED( "VIEW", $MrGreen ); 
     351    $this->createNewFoswikiSession(); 
     352    $this->DENIED( "VIEW", $MrYellow ); 
     353    $this->createNewFoswikiSession(); 
     354    $this->DENIED( "VIEW", $MrWhite ); 
     355    $this->createNewFoswikiSession(); 
     356    $this->DENIED( "view", $MrBlue ); 
     357    $this->createNewFoswikiSession(); 
    311358    $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 
    312359 
     
    318365sub test_allowtopic_c { 
    319366    my $this = shift; 
    320     my $topicObject = 
    321       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    322         $this->{test_topic}, <<'THIS'); 
     367    my ($topicObject) = 
     368      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     369    $topicObject->text(<<'THIS'); 
    323370If ALLOWTOPIC is set 
    324371   1. people in the list are PERMITTED 
     
    335382    ); 
    336383    $topicObject->save(); 
    337  
    338     # reFoswiki->new, so WebPreferences gets re-read 
    339     $this->{session}->finish(); 
    340     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    341     $this->{session} = Foswiki->new(); 
    342     $this->DENIED( "VIEW", $MrOrange ); 
    343     $this->{session}->finish(); 
    344     $this->{session} = Foswiki->new(); 
    345     $this->DENIED( "VIEW", $MrGreen ); 
    346     $this->{session}->finish(); 
    347     $this->{session} = Foswiki->new(); 
    348     $this->DENIED( "VIEW", $MrYellow ); 
    349     $this->{session}->finish(); 
    350     $this->{session} = Foswiki->new(); 
    351     $this->DENIED( "VIEW", $MrWhite ); 
    352     $this->{session}->finish(); 
    353     $this->{session} = Foswiki->new(); 
    354     $this->DENIED( "view", $MrBlue ); 
    355     $this->{session}->finish(); 
    356     $this->{session} = Foswiki->new(); 
     384    $topicObject->finish(); 
     385 
     386    # renew Foswiki, so WebPreferences gets re-read 
     387    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     388    $this->createNewFoswikiSession(); 
     389    $this->DENIED( "VIEW", $MrOrange ); 
     390    $this->createNewFoswikiSession(); 
     391    $this->DENIED( "VIEW", $MrGreen ); 
     392    $this->createNewFoswikiSession(); 
     393    $this->DENIED( "VIEW", $MrYellow ); 
     394    $this->createNewFoswikiSession(); 
     395    $this->DENIED( "VIEW", $MrWhite ); 
     396    $this->createNewFoswikiSession(); 
     397    $this->DENIED( "view", $MrBlue ); 
     398    $this->createNewFoswikiSession(); 
    357399    $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 
    358400 
     
    363405sub test_denyweb { 
    364406    my $this = shift; 
    365     my $topicObject = 
    366       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    367         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     407    my ($topicObject) = 
     408      Foswiki::Func::readTopic( $this->{test_web}, 
     409        $Foswiki::cfg{WebPrefsTopicName} ); 
     410    $topicObject->text(<<"THIS"); 
    368411If DENYWEB is set to a list of wikiname 
    369412    * people in the list are DENIED access 
     
    371414THIS 
    372415    $topicObject->save(); 
    373  
    374     # reFoswiki->new, so WebPreferences gets re-read 
    375     $topicObject = Foswiki::Meta->new( 
    376         $this->{session},    $this->{test_web}, 
    377         $this->{test_topic}, "Null points" 
    378     ); 
    379     $topicObject->save(); 
    380  
    381     $this->{session}->finish(); 
    382     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    383     $this->{session} = Foswiki->new(); 
     416    $topicObject->finish(); 
     417 
     418    # renew Foswiki, so WebPreferences gets re-read 
     419    $this->createNewFoswikiSession(); 
     420    ($topicObject) = 
     421      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     422    $topicObject->text("Null points"); 
     423    $topicObject->save(); 
     424    $topicObject->finish(); 
     425 
     426    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     427    $this->createNewFoswikiSession(); 
    384428 
    385429    $this->DENIED( "VIEW", $MrOrange ); 
     
    395439# Test that ALLOWWEB works in a top-level web with no finalisation 
    396440sub test_allow_web { 
    397     my $this        = shift; 
    398     my $topicObject = Foswiki::Meta->new( 
    399         $this->{session}, 
    400         $this->{test_web}, $Foswiki::cfg{WebPrefsTopicName}, 
     441    my $this = shift; 
     442    my ($topicObject) = 
     443      Foswiki::Func::readTopic( $this->{test_web}, 
     444        $Foswiki::cfg{WebPrefsTopicName} ); 
     445    $topicObject->text( 
    401446        <<'THIS' 
    402447If ALLOWWEB is set to a list of wikinames 
     
    405450   * Set ALLOWWEBVIEW = MrGreen MrYellow MrWhite 
    406451THIS 
    407         , undef 
    408     ); 
    409     $topicObject->save(); 
    410  
    411     $topicObject = Foswiki::Meta->new( 
    412         $this->{session},    $this->{test_web}, 
    413         $this->{test_topic}, "Null points" 
    414     ); 
    415     $topicObject->save(); 
    416  
    417     # reFoswiki->new, so WebPreferences gets re-read 
    418     $this->{session}->finish(); 
    419     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    420     $this->{session} = Foswiki->new(); 
     452    ); 
     453    $topicObject->save(); 
     454    $topicObject->finish(); 
     455 
     456    ($topicObject) = 
     457      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     458    $topicObject->text("Null points"); 
     459    $topicObject->save(); 
     460    $topicObject->finish(); 
     461 
     462    # renew Foswiki, so WebPreferences gets re-read 
     463    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     464    $this->createNewFoswikiSession(); 
    421465 
    422466    $this->DENIED( "VIEW", $MrOrange ); 
     
    432476# Test that Web.UserName is equivalent to UserName in ACLs 
    433477sub test_webDotUserName { 
    434     my $this        = shift; 
    435     my $topicObject = Foswiki::Meta->new( 
    436         $this->{session}, $this->{test_web}, $this->{test_topic}, 
     478    my $this = shift; 
     479    my ($topicObject) = 
     480      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     481    $topicObject->text( 
    437482        <<'THIS' 
    438483If ALLOWTOPIC is set 
     
    441486   * Set ALLOWTOPICVIEW = MrYellow,%USERSWEB%.MrOrange,Nosuchweb.MrGreen,%MAINWEB%.MrBlue,%SYSTEMWEB%.MrWhite 
    442487THIS 
    443         , undef 
    444     ); 
    445     $topicObject->save(); 
    446  
    447     # reFoswiki->new, so WebPreferences gets re-read 
    448     $this->{session}->finish(); 
    449     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    450     $this->{session} = Foswiki->new(); 
     488    ); 
     489    $topicObject->save(); 
     490    $topicObject->finish(); 
     491 
     492    # renew Foswiki, so WebPreferences gets re-read 
     493    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     494    $this->createNewFoswikiSession(); 
    451495 
    452496    $this->DENIED( "VIEW", $MrOrange ); 
     
    498542   * Set ALLOWTOPICVIEW = %USERSWEB%.MrGreen 
    499543THIS 
    500     my $topicObject = 
    501       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    502         $this->{test_topic}, $text ); 
    503     $topicObject->save(); 
    504  
    505     # reFoswiki->new, so WebPreferences gets re-read 
    506     $this->{session}->finish(); 
    507     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    508     $this->{session} = Foswiki->new(); 
    509  
    510     $topicObject = 
    511       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    512         $this->{test_topic} ); 
     544    my ($topicObject) = 
     545      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     546    $topicObject->text($text); 
     547    $topicObject->save(); 
     548    $topicObject->finish(); 
     549 
     550    # renew Foswiki, so WebPreferences gets re-read 
     551    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     552    $this->createNewFoswikiSession(); 
     553 
     554    ($topicObject) = 
     555      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    513556    $this->_checkSettings($topicObject); 
     557    $topicObject->finish(); 
    514558 
    515559    return; 
     
    520564    my $this = shift; 
    521565 
    522     my $topicObject = 
    523       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    524         $this->{test_topic}, 'Empty' ); 
     566    my ($topicObject) = 
     567      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     568    $topicObject->text('Empty'); 
    525569    my $args = { 
    526570        name  => 'ALLOWTOPICVIEW', 
     
    531575    $topicObject->putKeyed( 'PREFERENCE', $args ); 
    532576    $topicObject->save(); 
    533  
    534     # reFoswiki->new, so WebPreferences gets re-read 
    535     $this->{session}->finish(); 
    536     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    537     $this->{session} = Foswiki->new(); 
    538  
    539     $topicObject = 
    540       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    541         $this->{test_topic} ); 
     577    $topicObject->finish(); 
     578 
     579    # renew Foswiki, so WebPreferences gets re-read 
     580    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     581    $this->createNewFoswikiSession(); 
     582 
     583    ($topicObject) = 
     584      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    542585 
    543586    $this->_checkSettings($topicObject); 
     587    $topicObject->finish(); 
    544588 
    545589    return; 
     
    553597   * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange 
    554598THIS 
    555     my $topicObject = 
    556       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    557         $this->{test_topic}, $text ); 
     599    my ($topicObject) = 
     600      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     601    $topicObject->text($text); 
    558602    my $args = { 
    559603        name  => 'ALLOWTOPICVIEW', 
     
    564608    $topicObject->putKeyed( 'PREFERENCE', $args ); 
    565609    $topicObject->save(); 
    566  
    567     # reFoswiki->new, so WebPreferences gets re-read 
    568     $this->{session}->finish(); 
    569     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    570     $this->{session} = Foswiki->new(); 
    571  
    572     $topicObject = 
    573       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    574         $this->{test_topic} ); 
     610    $topicObject->finish(); 
     611 
     612    # renew Foswiki, so WebPreferences gets re-read 
     613    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     614    $this->createNewFoswikiSession(); 
     615 
     616    ($topicObject) = 
     617      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    575618    $this->_checkSettings($topicObject); 
     619    $topicObject->finish(); 
    576620 
    577621    return; 
     
    586630 
    587631    # First build a parent web with view restricted to MrGreen 
    588     my $topicObject = 
    589       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    590         $this->{test_topic}, "Nowt" ); 
    591     $topicObject->save(); 
    592  
    593     $topicObject = 
    594       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    595         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     632    my ($topicObject) = 
     633      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     634    $topicObject->text("Nowt"); 
     635    $topicObject->save(); 
     636    $topicObject->finish(); 
     637 
     638    ($topicObject) = 
     639      Foswiki::Func::readTopic( $this->{test_web}, 
     640        $Foswiki::cfg{WebPrefsTopicName} ); 
     641    $topicObject->text(<<'THIS'); 
    596642   * Set ALLOWWEBVIEW = MrGreen 
    597643THIS 
    598644    $topicObject->save(); 
     645    $topicObject->finish(); 
    599646 
    600647    # Now build a subweb with view restricted to MrOrange 
    601648    my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 
    602649    $webObject->populateNewWeb(); 
    603     $topicObject = 
    604       Foswiki::Meta->new( $this->{session}, $subweb, 
    605         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     650    $webObject->finish(); 
     651    ($topicObject) = 
     652      Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 
     653    $topicObject->text(<<'THIS'); 
    606654   * Set ALLOWWEBVIEW = MrOrange 
    607655THIS 
    608656    $topicObject->save(); 
    609     $this->{session}->finish(); 
    610     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    611     $this->{session} = Foswiki->new(); 
     657    $topicObject->finish(); 
     658    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     659    $this->createNewFoswikiSession(); 
    612660    $this->DENIED( "VIEW", $MrOrange, $subweb ); 
    613661    $this->DENIED( "VIEW", $MrGreen,  $subweb ); 
     
    628676    # First build a parent web with view restricted to MrGreen, and 
    629677    # finalise the setting 
    630     my $topicObject = 
    631       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    632         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     678    my ($topicObject) = 
     679      Foswiki::Func::readTopic( $this->{test_web}, 
     680        $Foswiki::cfg{WebPrefsTopicName} ); 
     681    $topicObject->text(<<'THIS'); 
    633682   * Set ALLOWWEBVIEW = MrGreen 
    634683   * Set FINALPREFERENCES = ALLOWWEBVIEW 
    635684THIS 
    636685    $topicObject->save(); 
     686    $topicObject->finish(); 
    637687 
    638688    # Now build a subweb with no restrictions 
    639689    my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 
    640690    $webObject->populateNewWeb(); 
    641     $topicObject = 
    642       Foswiki::Meta->new( $this->{session}, $subweb, 
    643         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
    644 THIS 
    645     $topicObject->save(); 
    646     $this->{session}->finish(); 
    647     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    648     $this->{session} = Foswiki->new(); 
     691    $webObject->finish(); 
     692    ($topicObject) = 
     693      Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 
     694    $topicObject->text(<<'THIS'); 
     695THIS 
     696    $topicObject->save(); 
     697    $topicObject->finish(); 
     698    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     699    $this->createNewFoswikiSession(); 
    649700    $this->DENIED( "VIEW", $MrGreen,  $subweb ); 
    650701    $this->DENIED( "VIEW", $MrOrange, $subweb ); 
     
    665716    # First build a parent web with view restricted to MrGreen, and 
    666717    # finalise the setting 
    667     my $topicObject = 
    668       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    669         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     718    my ($topicObject) = 
     719      Foswiki::Func::readTopic( $this->{test_web}, 
     720        $Foswiki::cfg{WebPrefsTopicName} ); 
     721    $topicObject->text(<<'THIS'); 
    670722   * Set ALLOWWEBVIEW = MrGreen 
    671723   * Set FINALPREFERENCES = ALLOWWEBVIEW 
    672724THIS 
    673725    $topicObject->save(); 
     726    $topicObject->finish(); 
    674727 
    675728    # Now build a subweb with view restricted to MrOrange 
    676729    my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 
    677730    $webObject->populateNewWeb(); 
    678     $topicObject = 
    679       Foswiki::Meta->new( $this->{session}, $subweb, 
    680         $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 
     731    $webObject->finish(); 
     732    ($topicObject) = 
     733      Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 
     734    $topicObject->text(<<'THIS'); 
    681735   * Set ALLOWWEBVIEW = MrOrange 
    682736THIS 
    683737    $topicObject->save(); 
    684     $this->{session}->finish(); 
    685     $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
    686     $this->{session} = Foswiki->new(); 
     738    $topicObject->finish(); 
     739    $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 
     740    $this->createNewFoswikiSession(); 
    687741    $this->DENIED( "VIEW", $MrOrange, $subweb ); 
    688742    $this->DENIED( "VIEW", $MrGreen,  $subweb ); 
     
    703757 
    704758    # Create a topic with an anchor, viewable only by MrYellow 
    705     my $topicObject = Foswiki::Meta->new( 
    706         $this->{session}, $this->{test_web}, $test_topic, 
    707         <<'THIS' 
     759    my ($topicObject) = 
     760      Foswiki::Func::readTopic( $this->{test_web}, $test_topic ); 
     761    $topicObject->text( <<'THIS' ); 
    708762If there is an anchor, and some access restrictions, 
    709763anchor is preserved after login. 
     
    711765   * Set ALLOWTOPICVIEW = MrYellow 
    712766THIS 
    713         , undef 
    714     ); 
    715     $topicObject->save(); 
     767    $topicObject->save(); 
     768    $topicObject->finish(); 
    716769 
    717770    # Request the page with the full UI 
     
    727780    my $viewUrl = 
    728781      $this->{session} 
    729       ->getScriptUrl( '0', 'view', $this->{test_web}, $test_topic ); 
     782      ->getScriptUrl( 0, 'view', $this->{test_web}, $test_topic ); 
    730783    $query->uri("$viewUrl"); 
     784    $this->finishFoswikiSession(); 
    731785    my ($text) = $this->capture( 
    732786        sub { 
    733             $Foswiki::Plugins::SESSION->{response} = 
    734               Foswiki::UI::handleRequest($query); 
     787            my $response = Foswiki::UI::handleRequest($query); 
     788            $this->createNewFoswikiSession( undef, $query ); 
     789            $this->{session}{response} = $response; 
    735790        } 
    736791    ); 
     
    739794    my $loginUrl = 
    740795      $this->{session} 
    741       ->getScriptUrl( '0', 'login', $this->{test_web}, $test_topic ); 
     796      ->getScriptUrl( 0, 'login', $this->{test_web}, $test_topic ); 
    742797 
    743798    # Item11121: the test doesn't tolerate ShortURLs, for example. 
     
    755810 
    756811    # Check the redirect contains the login url + view to this topic 
    757     $this->assert_matches( 
    758         qr#^$loginUrl.*/view/$this->{test_web}/$test_topic$#, 
    759         $redirect_to, 
    760         "Login did not redirect to a page with the proper anchor:\n" 
     812    my $regex = qr#^\Q$loginUrl\E.*/view/$this->{test_web}/$test_topic$#; 
     813    $this->assert_matches( $regex, $redirect_to, 
     814            "Login did not redirect to a page with the proper anchor:\n" 
    761815          . "Location: $redirect_to\n" 
    762           . "Expected: ^$loginUrl.*\%23anchor\$" 
    763     ); 
     816          . "Expected: $regex" ); 
    764817 
    765818    # Get the redirected page after login 
  • trunk/UnitTestContrib/test/unit/AttrsTests.pm

    r13730 r13791  
     1package AttrsTests; 
    12use strict; 
    2  
    3 package AttrsTests; 
    4  
    5 use FoswikiTestCase; 
     3use warnings; 
     4 
     5use FoswikiTestCase(); 
    66our @ISA = qw( FoswikiTestCase ); 
    77 
    8 use Foswiki::Attrs; 
     8use Foswiki::Attrs(); 
    99 
    1010sub new { 
  • trunk/UnitTestContrib/test/unit/CacheTests.pm

    r13730 r13791  
    11package CacheTests; 
     2use strict; 
     3use warnings; 
    24 
    3 use FoswikiFnTestCase; 
     5use FoswikiFnTestCase(); 
    46our @ISA = qw( FoswikiFnTestCase ); 
    57 
    6 use strict; 
    7 use Foswiki; 
    8 use Foswiki::Meta; 
     8use Foswiki(); 
     9use Foswiki::Meta(); 
     10use File::Spec(); 
     11use Foswiki::OopsException(); 
     12use Foswiki::PageCache(); 
    913use Error qw( :try ); 
    10 use Foswiki::OopsException; 
    11 use Foswiki::PageCache; 
    1214use Benchmark qw(:hireswallclock); 
    1315 
     
    1719    my $this = shift; 
    1820    my @page; 
     21 
    1922    foreach my $dir (@INC) { 
    20         if ( opendir( D, "$dir/Foswiki/Cache" ) ) { 
    21             foreach my $alg ( readdir D ) { 
     23        if ( opendir( my $D, File::Spec->catdir( $dir, 'Foswiki', 'Cache' ) ) ) 
     24        { 
     25            foreach my $alg ( readdir $D ) { 
    2226                next unless $alg =~ s/^(.*)\.pm$/$1/; 
    23                 next if defined &$alg; 
     27                next if defined &{$alg}; 
    2428                $ENV{PATH} =~ /^(.*)$/ms; 
    25                 $ENV{PATH} = $1; 
     29                local $ENV{PATH} = $1; 
    2630                ($alg) = $alg =~ /^(.*)$/ms; 
    27                 eval "require Foswiki::Cache::$alg"; 
    28                 if ($@) { 
    29                     print STDERR 
    30 "Cannot test Foswiki::Cache::$alg\nCompilation error when trying to 'require' it\n"; 
    31                 } 
    32                 else { 
     31 
     32                if ( eval "require Foswiki::Cache::$alg; 1;" ) { 
    3333                    no strict 'refs'; 
    34                     *$alg = sub { 
     34                    *{$alg} = sub { 
    3535                        my $this = shift; 
    3636                        $Foswiki::cfg{CacheManager} = 'Foswiki::Cache::' . $alg; 
     
    3939                    push( @page, $alg ); 
    4040                } 
     41                else { 
     42                    print STDERR 
     43"Cannot test Foswiki::Cache::$alg\nCompilation error when trying to 'require' it\n"; 
     44                } 
    4145            } 
    42             closedir(D); 
     46            closedir($D); 
    4347        } 
    4448    } 
     
    5054sub DBFileMeta { 
    5155    $Foswiki::cfg{MetaCacheManager} = 'Foswiki::Cache::DB_File'; 
     56 
     57    return; 
    5258} 
    5359 
    5460sub BDBMeta { 
    5561    $Foswiki::cfg{MetaCacheManager} = 'Foswiki::Cache::BDB'; 
     62 
     63    return; 
    5664} 
    5765 
     
    5967    $Foswiki::cfg{HttpCompress} = 1; 
    6068    $Foswiki::cfg{Cache}{Compress} = 1; 
     69 
     70    return; 
    6171} 
    6272 
     
    6474    $Foswiki::cfg{HttpCompress} = 0; 
    6575    $Foswiki::cfg{Cache}{Compress} = 0; 
     76 
     77    return; 
    6678} 
    6779 
     
    90102    $Foswiki::cfg{Cache}{Compress} = 0; 
    91103    $UI_FN ||= $this->getUIFn('view'); 
    92 } 
    93104 
    94 sub tear_down { 
    95     my $this = shift; 
    96     $this->SUPER::tear_down(); 
     105    return; 
    97106} 
    98107 
     
    102111    $UI_FN ||= $this->getUIFn('view'); 
    103112 
    104     my $query = new Unit::Request( { skin => ['none'], } ); 
     113    my $query = Unit::Request->new( { skin => ['none'], } ); 
    105114    $query->path_info("/"); 
    106115    $query->method('POST'); 
    107116 
    108     my $fatwilly = new Foswiki( $this->{test_user_login}, $query ); 
     117    $this->createNewFoswikiSession( $this->{test_user_login}, $query ); 
    109118 
    110119    # This first request should *not* be satisfied from the cache, but 
    111120    # the cache should be populated with the result. 
    112     my $p1start = new Benchmark(); 
     121    my $p1start = Benchmark->new(); 
    113122    my ($one) = $this->capture( 
    114123        sub { 
    115124            no strict 'refs'; 
    116             &$UI_FN($fatwilly); 
     125            &{$UI_FN}( $this->{session} ); 
    117126            use strict 'refs'; 
    118             $Foswiki::engine->finalize( $fatwilly->{response}, 
    119                 $fatwilly->{request} ); 
     127            $Foswiki::engine->finalize( $this->{session}{response}, 
     128                $this->{session}{request} ); 
    120129        } 
    121130    ); 
    122131 
    123     my $p1end = new Benchmark(); 
     132    my $p1end = Benchmark->new(); 
    124133    print STDERR "R1 " . timestr( timediff( $p1end, $p1start ) ) . "\n"; 
    125     $fatwilly->finish(); 
    126134 
    127     $fatwilly = new Foswiki( $this->{test_user_login}, $query ); 
     135    $this->createNewFoswikiSession( $this->{test_user_login}, $query ); 
    128136 
    129137    # This second request should be satisfied from the cache 
    130     my $p2start = new Benchmark(); 
     138    my $p2start = Benchmark->new(); 
    131139    my ($two) = $this->capture( 
    132140        sub { 
    133141            no strict 'refs'; 
    134             &$UI_FN($fatwilly); 
     142            &{$UI_FN}( $this->{session} ); 
    135143            use strict 'refs'; 
    136             $Foswiki::engine->finalize( $fatwilly->{response}, 
    137                 $fatwilly->{request} ); 
     144            $Foswiki::engine->finalize( $this->{session}{response}, 
     145                $this->{session}{request} ); 
    138146        } 
    139147    ); 
    140     my $p2end = new Benchmark(); 
     148    my $p2end = Benchmark->new(); 
    141149    print STDERR "R2 " . timestr( timediff( $p2end, $p2start ) ) . "\n"; 
    142     $fatwilly->finish(); 
    143150 
    144151    # Massage the HTML for comparison 
     
    164171 
    165172    $this->assert_html_equals( $one, $two ); 
     173 
     174    return; 
    166175} 
    167176 
  • trunk/UnitTestContrib/test/unit/ClientTests.pm

    r13730 r13791  
     1package ClientTests; 
    12use strict; 
    2  
    3 package ClientTests; 
     3use warnings; 
    44 
    55# This is woefully incomplete, but it does at least check that 
    66# LoginManager.pm compiles okay. 
    77 
    8 use FoswikiFnTestCase; 
     8use FoswikiFnTestCase(); 
    99our @ISA = qw( FoswikiFnTestCase ); 
    1010 
    11 use Unit::Request; 
     11use Foswiki(); 
     12use Foswiki::LoginManager(); 
     13use Unit::Request(); 
    1214use Error qw( :try ); 
    13  
    14 use Foswiki; 
    15 use Foswiki::LoginManager; 
    1615 
    1716my $agent = $Foswiki::cfg{Register}{RegistrationAgentWikiName}; 
     
    2928    my $topicObject = Foswiki::Meta->new( 
    3029        $this->{session},    $this->{test_web}, 
    31         $this->{test_topic}, <<CONSTRAINT); 
     30        $this->{test_topic}, <<'CONSTRAINT'); 
    3231   * Set ALLOWTOPICCHANGE = AdminGroup 
    3332CONSTRAINT 
    3433    $topicObject->save(); 
     34 
     35    return; 
    3536} 
    3637 
    3738sub TemplateLoginManager { 
    3839    $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin'; 
     40 
     41    return; 
    3942} 
    4043 
    4144sub ApacheLoginManager { 
    4245    $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::ApacheLogin'; 
     46 
     47    return; 
    4348} 
    4449 
    4550sub NoLoginManager { 
    4651    $Foswiki::cfg{LoginManager} = 'none'; 
     52 
     53    return; 
    4754} 
    4855 
     
    5158    $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::BaseUserMapping'; 
    5259    $this->set_up_for_verify(); 
     60 
     61    return; 
    5362} 
    5463 
     
    5766    $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping'; 
    5867    $this->set_up_for_verify(); 
     68 
     69    return; 
    5970} 
    6071 
     
    7081    my $this = shift; 
    7182 
    72     $this->{session}->finish() if $this->{session}; 
    73     $this->{session} = new Foswiki( undef, new Unit::Request() ); 
     83    $this->createNewFoswikiSession( undef, Unit::Request->new() ); 
    7484    $this->assert( $Foswiki::cfg{TempfileDir} 
    7585          && -d $Foswiki::cfg{TempfileDir} ); 
     
    8090    $Foswiki::cfg{Register}{EnableNewUserRegistration} = 1; 
    8191    $Foswiki::cfg{UsersWebName} = $this->{users_web}; 
     92 
     93    return; 
    8294} 
    8395 
     
    101113 
    102114#print STDERR "\n------------- set_up_user (login: $userLogin) (cUID:$user_id) -----------------\n"; 
     115 
     116    return; 
    103117} 
    104118 
    105119sub capture { 
    106     my $this = shift; 
    107     my ( $proc, $session ) = @_; 
     120    my ( $this, $proc, $session, @args ) = @_; 
    108121    $session->getLoginManager()->checkAccess(); 
    109     $this->SUPER::capture(@_); 
     122    $this->SUPER::capture( $proc, $session, @args ); 
     123 
     124    return; 
    110125} 
    111126 
     
    118133 
    119134    #close this Foswiki session - its using the wrong mapper and login 
    120     $this->{session}->finish(); 
    121  
    122     $query = new Unit::Request(); 
     135 
     136    $query = Unit::Request->new(); 
    123137    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    124     $this->{session} = new Foswiki( undef, $query ); 
     138    $this->createNewFoswikiSession( undef, $query ); 
    125139 
    126140    $this->set_up_user(); 
     
    135149    }; 
    136150 
    137     $query = new Unit::Request(); 
     151    $query = Unit::Request->new(); 
    138152    $query->path_info("/$this->{test_web}/$this->{test_topic}?breaklock=1"); 
    139     $this->{session}->finish(); 
    140  
    141     $this->{session} = new Foswiki( undef, $query ); 
     153 
     154    $this->createNewFoswikiSession( undef, $query ); 
    142155 
    143156    try { 
     
    156169    }; 
    157170 
    158     $query = new Unit::Request(); 
     171    $query = Unit::Request->new(); 
    159172    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    160     $this->{session}->finish(); 
    161173 
    162174    $this->annotate("new session using $userLogin\n"); 
    163175 
    164     $this->{session} = new Foswiki( $userLogin, $query ); 
     176    $this->createNewFoswikiSession( $userLogin, $query ); 
    165177 
    166178#clear the lease - one of the previous tests may have different usermapper & thus different user 
    167179    Foswiki::Func::setTopicEditLock( $this->{test_web}, $this->{test_topic}, 
    168180        0 ); 
     181 
     182    return; 
    169183} 
    170184 
     
    175189        return; 
    176190    } 
    177     $this->{session}->finish(); 
    178191    my $secret = "a big mole on my left buttock"; 
    179192    my $crypted = crypt( $secret, "12" ); 
    180193    $Foswiki::cfg{Password} = $crypted; 
    181194 
    182     my $query = new Unit::Request( 
     195    my $query = Unit::Request->new( 
    183196        { 
    184197            username => [ $Foswiki::cfg{AdminUserLogin} ], 
     
    190203    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    191204 
    192     $this->{session} = new Foswiki( undef, $query ); 
     205    $this->createNewFoswikiSession( undef, $query ); 
    193206    $this->{session}->getLoginManager()->login( $query, $this->{session} ); 
    194207    my $script = $Foswiki::cfg{LoginManager} =~ /Apache/ ? 'viewauth' : 'view'; 
     
    199212    $this->assert_matches( qr/^$surly/, 
    200213        $this->{session}->{response}->headers()->{Location} ); 
     214 
     215    return; 
    201216} 
    202217 
  • trunk/UnitTestContrib/test/unit/ConfigureTests.pm

    r13730 r13791  
    44use warnings; 
    55 
    6 use FoswikiTestCase; 
     6use FoswikiTestCase(); 
    77our @ISA = qw( FoswikiTestCase ); 
    88 
    99use Error qw( :try ); 
    10 use File::Temp; 
     10use File::Temp(); 
    1111use FindBin; 
    1212use File::Path qw(mkpath rmtree); 
     
    3232    $root =~ s|\\|/|g; 
    3333 
    34     $this->{rootdir}  = $root; 
    35     $this->{user}     = $Foswiki::cfg{AdminUserLogin}; 
    36     $this->{session}  = Foswiki->new( $this->{user} ); 
     34    $this->{rootdir} = $root; 
     35    $this->{user}    = $Foswiki::cfg{AdminUserLogin}; 
     36    $this->createNewFoswikiSession( $this->{user} ); 
    3737    $this->{test_web} = 'Testsystemweb1234'; 
    3838    my $webObject = Foswiki::Meta->new( $this->{session}, $this->{test_web} ); 
    3939    $webObject->populateNewWeb(); 
     40    $webObject->finish(); 
    4041    $this->{trash_web} = 'Testtrashweb1234'; 
    4142    $webObject = Foswiki::Meta->new( $this->{session}, $this->{trash_web} ); 
    4243    $webObject->populateNewWeb(); 
     44    $webObject->finish(); 
    4345    $this->{sandbox_web} = 'Testsandboxweb1234'; 
    4446    $webObject = Foswiki::Meta->new( $this->{session}, $this->{sandbox_web} ); 
    4547    $webObject->populateNewWeb(); 
     48    $webObject->finish(); 
    4649    $this->{sandbox_subweb} = 'Testsandboxweb1234/Subweb'; 
    4750    $webObject = 
    4851      Foswiki::Meta->new( $this->{session}, $this->{sandbox_subweb} ); 
    4952    $webObject->populateNewWeb(); 
     53    $webObject->finish(); 
    5054    $this->{tempdir} = $Foswiki::cfg{TempfileDir} . '/test_ConfigureTests'; 
    5155    rmtree( $this->{tempdir} ) 
     
    19261930    my ( $result, $err ) = $pkg->loadInstaller(); 
    19271931 
    1928     my $expected = <<HERE; 
     1932    my $expected = <<'HERE'; 
    19291933I can't download http://foswiki.org/pub/Extensions/EmptyPluginx/EmptyPluginx_installer because of the following error: 
    19301934Not Found 
  • trunk/UnitTestContrib/test/unit/EmptyTests.pm

    r6912 r13791  
    1 use strict; 
    2  
    31# Example test case; use this as a basis to build your own 
    42 
    53package EmptyTests; 
     4use strict; 
     5use warnings; 
    66 
    77use FoswikiTestCase; 
     
    1010use Foswiki; 
    1111use Error qw( :try ); 
    12  
    13 my $topicquery; 
    1412 
    1513sub set_up { 
     
    2018    # You can now safely modify $Foswiki::cfg 
    2119 
    22     $topicquery = new Unit::Request(''); 
     20    my $topicquery = Unit::Request->new(''); 
    2321    $topicquery->path_info('/TestCases/WebHome'); 
    2422    try { 
    25         $this->{session} = new Foswiki( 'AdminUser' || '' ); 
     23        $this->createNewFoswikiSession( 'AdminUser' || '' ); 
    2624        my $user = $this->{session}->{user}; 
    2725 
     
    3230          Foswiki::Meta->new( $this->{session}, "Temporarytestweb1" ); 
    3331        $webObject->populateNewWeb("_default"); 
     32        $webObject->finish(); 
    3433 
    3534        # Copy a system web like this: 
     
    3736          Foswiki::Meta->new( $this->{session}, "Temporarysystemweb" ); 
    3837        $webObject->populateNewWeb("System"); 
     38        $webObject->finish(); 
    3939 
    4040        # Create a topic like this: 
     
    5252        $this->assert( 0, shift->stringify() || '' ); 
    5353    }; 
     54 
     55    return; 
    5456} 
    5557 
     
    6163    $this->removeWebFixture( $this->{session}, "Temporarytestweb1" ); 
    6264    $this->removeWebFixture( $this->{session}, "Temporarysystemweb" ); 
    63     $this->{session}->finish() if $this->{session}; 
    6465 
    6566    # Always do this, and always do it last 
    6667    $this->SUPER::tear_down(); 
     68 
     69    return; 
    6770} 
    6871 
     
    7780sub test_ { 
    7881    my $this = shift; 
     82 
     83    return; 
    7984} 
    8085 
  • trunk/UnitTestContrib/test/unit/ExceptionTests.pm

    r13730 r13791  
    11package ExceptionTests; 
    2 use FoswikiFnTestCase; 
     2use strict; 
     3use warnings; 
     4 
     5use FoswikiFnTestCase(); 
    36our @ISA = qw( FoswikiFnTestCase ); 
    47 
    5 use strict; 
    6  
    78use Error qw( :try ); 
    8 use Foswiki::OopsException; 
    9 use Foswiki::AccessControlException; 
     9use Foswiki::OopsException(); 
     10use Foswiki::AccessControlException(); 
    1011 
    1112my $UI_FN; 
     
    1516    $this->SUPER::set_up(); 
    1617    $UI_FN ||= $this->getUIFn('oops'); 
     18 
     19    return; 
    1720} 
    1821 
     
    4447        ); 
    4548    }; 
     49 
     50    return; 
    4651} 
    4752 
     
    7075        ); 
    7176    }; 
     77 
     78    return; 
    7279} 
    7380 
    7481sub upchuck { 
    7582    my $session = shift; 
    76     my $e       = new Foswiki::OopsException( 
     83    my $e       = Foswiki::OopsException->new( 
    7784        'templatename', 
    7885        web    => 'webname', 
     
    8188    ); 
    8289    $e->redirect($session); 
     90 
     91    return; 
    8392} 
    8493 
     
    8695sub deprecated_test_redirectOopsException { 
    8796    my $this = shift; 
    88     my $t    = new Foswiki(); 
    89     my ($output) = $this->capture( \&upchuck, $t ); 
    90     $t->finish(); 
     97    $this->createNewFoswikiSession(); 
     98    my ($output) = $this->capture( \&upchuck, $this->{session} ); 
    9199    $this->assert_matches( qr/^Status: 302.*$/m, $output ); 
    92100    $this->assert_matches( 
     
    94102        $output 
    95103    ); 
     104 
     105    return; 
    96106} 
    97107 
    98108sub test_AccessControlException { 
    99109    my $this = shift; 
    100     my $ace  = new Foswiki::AccessControlException( 'FRY', 'burger', 'Spiders', 
     110    my $ace  = Foswiki::AccessControlException->new( 'FRY', 'burger', 'Spiders', 
    101111        'FlumpNuts', 'Because it was there.' ); 
    102112    $this->assert_str_equals( 
     
    105115    ); 
    106116 
     117    return; 
    107118} 
    108119 
    109120sub test_oopsScript { 
    110121    my $this  = shift; 
    111     my $query = new Unit::Request( 
     122    my $query = Unit::Request->new( 
    112123        { 
    113124            skin     => 'none', 
     
    121132        } 
    122133    ); 
    123     my $session = new Foswiki( undef, $query ); 
     134    $this->createNewFoswikiSession( undef, $query ); 
    124135    my ($output) = 
    125       $this->capture( $UI_FN, $session, "Flum", "DeDum", $query, 0 ); 
     136      $this->capture( $UI_FN, $this->{session}, "Flum", "DeDum", $query, 0 ); 
    126137    $this->assert_matches( qr/^phlegm$/m,           $output ); 
    127138    $this->assert_matches( qr/^&#60;pus&#62;$/m,    $output ); 
     
    132143    $this->assert_matches( qr/^phlegm$/m,           $output ); 
    133144 
    134     $session->finish(); 
     145    return; 
    135146} 
    136147 
  • trunk/UnitTestContrib/test/unit/Fn_GROUPINFO.pm

    r13730 r13791  
     1# tests for the correct expansion of GROUPINFO 
     2 
     3package Fn_GROUPINFO; 
    14use strict; 
    2  
    3 # tests for the correct expansion of GROUPINFO 
    4  
    5 package Fn_GROUPINFO; 
    6  
    7 use FoswikiFnTestCase; 
     5use warnings; 
     6 
     7use FoswikiFnTestCase(); 
    88our @ISA = qw( FoswikiFnTestCase ); 
    99 
    10 use Foswiki; 
     10use Foswiki(); 
     11use Foswiki::Func(); 
    1112use Error qw( :try ); 
    1213 
    1314sub new { 
     15    my ( $class, @args ) = @_; 
     16 
    1417    $Foswiki::cfg{Register}{AllowLoginName} = 1; 
    15     my $self = shift()->SUPER::new( 'GROUPINFO', @_ ); 
    16     return $self; 
     18 
     19    return $class->SUPER::new( 'GROUPINFO', @args ); 
    1720} 
    1821 
     
    2023    my $this = shift; 
    2124    $this->SUPER::set_up(@_); 
    22     my $topicObject = 
    23       Foswiki::Meta->new( $this->{session}, $this->{users_web}, "GropeGroup", 
    24         "   * Set GROUP = ScumBag,WikiGuest\n" ); 
    25     $topicObject->save(); 
    26     $topicObject = 
    27       Foswiki::Meta->new( $this->{session}, $this->{users_web}, "PopGroup", 
    28         "   * Set GROUP = WikiGuest\n" ); 
    29     $topicObject->save(); 
    30     $topicObject = Foswiki::Meta->new( 
    31         $this->{session}, $this->{users_web}, 
    32         "NestingGroup",   "   * Set GROUP = GropeGroup\n" 
    33     ); 
    34     $topicObject->save(); 
    35     $topicObject = 
    36       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    37         "OnlyAdminCanChangeGroup", 
    38         "   * Set GROUP = WikiGuest\n   * Set TOPICCHANGE = AdminGroup\n" ); 
    39     $topicObject->save(); 
    40     $topicObject = 
    41       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    42         "GroupWithHiddenGroup", "   * Set GROUP = HiddenGroup,WikiGuest\n" ); 
    43     $topicObject->save(); 
    44     $topicObject = 
    45       Foswiki::Meta->new( $this->{session}, $this->{users_web}, "HiddenGroup", 
    46         "   * Set GROUP = ScumBag\n   * Set ALLOWTOPICVIEW = AdminUser\n" ); 
    47     $topicObject->save(); 
    48  
    49     $topicObject = 
    50       Foswiki::Meta->new( $this->{session}, $this->{users_web}, 
    51         "HiddenUserGroup", "   * Set GROUP = ScumBag,HidemeGood\n" ); 
    52     $topicObject->save(); 
    53  
    54     $topicObject = 
    55       Foswiki::Meta->load( $this->{session}, $this->{users_web}, "HidemeGood" ); 
     25    my ($topicObject) = 
     26      Foswiki::Func::readTopic( $this->{users_web}, "GropeGroup" ); 
     27    $topicObject->text("   * Set GROUP = ScumBag,WikiGuest\n"); 
     28    $topicObject->save(); 
     29    $topicObject->finish(); 
     30    ($topicObject) = Foswiki::Func::readTopic( $this->{users_web}, "PopGroup" ); 
     31    $topicObject->text("   * Set GROUP = WikiGuest\n"); 
     32    $topicObject->save(); 
     33    $topicObject->finish(); 
     34    ($topicObject) = 
     35      Foswiki::Func::readTopic( $this->{users_web}, "NestingGroup" ); 
     36    $topicObject->text("   * Set GROUP = GropeGroup\n"); 
     37    $topicObject->save(); 
     38    $topicObject->finish(); 
     39    ($topicObject) = 
     40      Foswiki::Func::readTopic( $this->{users_web}, "OnlyAdminCanChangeGroup" ); 
     41    $topicObject->text( 
     42        "   * Set GROUP = WikiGuest\n   * Set TOPICCHANGE = AdminGroup\n"); 
     43    $topicObject->save(); 
     44    $topicObject->finish(); 
     45    ($topicObject) = 
     46      Foswiki::Func::readTopic( $this->{users_web}, "GroupWithHiddenGroup" ); 
     47    $topicObject->text("   * Set GROUP = HiddenGroup,WikiGuest\n"); 
     48    $topicObject->save(); 
     49    $topicObject->finish(); 
     50    ($topicObject) = 
     51      Foswiki::Func::readTopic( $this->{users_web}, "HiddenGroup" ); 
     52    $topicObject->text( 
     53        "   * Set GROUP = ScumBag\n   * Set ALLOWTOPICVIEW = AdminUser\n"); 
     54    $topicObject->save(); 
     55    $topicObject->finish(); 
     56    ($topicObject) = 
     57      Foswiki::Func::readTopic( $this->{users_web}, "HiddenUserGroup" ); 
     58    $topicObject->text("   * Set GROUP = ScumBag,HidemeGood\n"); 
     59    $topicObject->save(); 
     60    $topicObject->finish(); 
     61    ($topicObject) = 
     62      Foswiki::Func::readTopic( $this->{users_web}, "HidemeGood" ); 
    5663    my $topText = $topicObject->text(); 
    5764    $topText .= "   * Set ALLOWTOPICVIEW = AdminUser\n"; 
    5865    $topText = $topicObject->text($topText); 
    5966    $topicObject->save(); 
    60  
     67    $topicObject->finish(); 
     68 
     69    return; 
    6170} 
    6271 
     
    7079    $this->assert_matches( qr/\bGroupWithHiddenGroup\b/, $ui ); 
    7180    $this->assert_does_not_match( qr/\bHiddenGroup\b/, $ui ); 
     81 
     82    return; 
    7283} 
    7384 
     
    7990    $this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/,   $ui ); 
    8091    $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 
    81     my @u = split( ',', $ui ); 
     92    my @u = split( /,/, $ui ); 
    8293    $this->assert( 2, scalar(@u) ); 
     94 
     95    return; 
    8396} 
    8497 
     
    95108    $this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/,   $ui ); 
    96109    $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 
    97     my @u = split( ',', $ui ); 
     110    my @u = split( /,/, $ui ); 
    98111    $this->assert( 2, scalar(@u) ); 
     112 
     113    return; 
    99114} 
    100115 
     
    107122    $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 
    108123    $this->assert_does_not_match( qr/\b$this->{users_web}.HiddenGroup\b/, $ui ); 
    109     my @u = split( ',', $ui ); 
     124    my @u = split( /,/, $ui ); 
    110125    $this->assert( 1, scalar(@u) ); 
     126 
     127    return; 
    111128} 
    112129 
     
    127144        $ui, 'ScumBag revealed' ); 
    128145 
    129     my @u = split( ',', $ui ); 
     146    my @u = split( /,/, $ui ); 
    130147    $this->assert( 1, scalar(@u) ); 
     148 
     149    return; 
    131150} 
    132151 
     
    141160    $this->assert_does_not_match( qr/\b$this->{users_web}.HidemeGood\b/, 
    142161        $ui, 'HidemeGood revealed' ); 
    143     my @u = split( ',', $ui ); 
     162    my @u = split( /,/, $ui ); 
    144163    $this->assert( 1, scalar(@u) ); 
     164 
     165    return; 
    145166} 
    146167 
     
    148169    my $this = shift; 
    149170 
    150     $this->{session}->finish(); 
    151     $this->{session}          = new Foswiki( $Foswiki::cfg{AdminUserLogin} ); 
    152     $this->{test_topicObject} = Foswiki::Meta->new( 
    153         $this->{session},    $this->{test_web}, 
    154         $this->{test_topic}, "BLEEGLE\n" 
    155     ); 
     171    $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin} ); 
     172    $this->{test_topicObject}->finish if $this->{test_topicObject}; 
     173    ( $this->{test_topicObject} ) = 
     174      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     175    $this->{test_topicObject}->text("BLEEGLE\n"); 
    156176    $this->{test_topicObject}->save(); 
    157177 
     
    161181    $this->assert_matches( qr/$this->{users_web}.ScumBag/,    $ui ); 
    162182    $this->assert_matches( qr/$this->{users_web}.HidemeGood/, $ui ); 
    163     my @u = split( ',', $ui ); 
     183    my @u = split( /,/, $ui ); 
    164184    $this->assert( 2, scalar(@u) ); 
     185    $this->{test_topicObject}->finish(); 
     186 
     187    return; 
    165188} 
    166189 
     
    201224      ); 
    202225    $this->assert_matches( qr/^<\w+>LF$/, $ui ); 
     226 
     227    return; 
    203228} 
    204229 
  • trunk/UnitTestContrib/test/unit/Fn_IF.pm

    r13730 r13791  
    22 
    33package Fn_IF; 
    4  
    54use strict; 
    6  
    7 use FoswikiFnTestCase; 
     5use warnings; 
     6 
     7use FoswikiFnTestCase(); 
    88our @ISA = qw( FoswikiFnTestCase ); 
    99 
    10 use Foswiki; 
     10use Foswiki(); 
    1111use Error qw( :try ); 
    1212use Assert; 
     
    1717 
    1818sub new { 
    19     my $self = shift()->SUPER::new( 'IF', @_ ); 
    20     my $dep = new Foswiki::Configure::Dependency( 
     19    my ( $class, @args ) = @_; 
     20    my $dep = Foswiki::Configure::Dependency->new( 
    2121        type    => "perl", 
    2222        module  => "Foswiki", 
     
    2424    ); 
    2525    ( $post11, my $message ) = $dep->check(); 
    26     return $self; 
     26 
     27    return $class->SUPER::new( 'IF', @args ); 
    2728} 
    2829 
     
    3031    my $this = shift; 
    3132    $this->simpleTest( test => "'A'='B'", then => 0, else => 1 ); 
     33 
     34    return; 
    3235} 
    3336 
     
    3538    my $this = shift; 
    3639    $this->simpleTest( test => "'A'!='B'", then => 1, else => 0 ); 
     40 
     41    return; 
    3742} 
    3843 
     
    4045    my $this = shift; 
    4146    $this->simpleTest( test => "'A'='A'", then => 1, else => 0 ); 
     47 
     48    return; 
    4249} 
    4350 
     
    4552    my $this = shift; 
    4653    $this->simpleTest( test => "'A'='B'", then => 0, else => 1 ); 
     54 
     55    return; 
    4756} 
    4857 
     
    5059    my $this = shift; 
    5160    $this->simpleTest( test => 'context test', then => 1, else => 0 ); 
     61 
     62    return; 
    5263} 
    5364 
     
    5566    my $this = shift; 
    5667    $this->simpleTest( test => 'context \'test\'', then => 1, else => 0 ); 
     68 
     69    return; 
    5770} 
    5871 
     
    6073    my $this = shift; 
    6174    $this->simpleTest( test => "{Fnargle}='Fleeble'", then => 1, else => 0 ); 
     75 
     76    return; 
    6277} 
    6378 
     
    6580    my $this = shift; 
    6681    $this->simpleTest( test => "{A}{B}='C'", then => 1, else => 0 ); 
     82 
     83    return; 
    6784} 
    6885 
     
    7592        else => 0 
    7693    ); 
     94 
     95    return; 
    7796} 
    7897 
     
    85104        else => 0 
    86105    ); 
     106 
     107    return; 
    87108} 
    88109 
     
    92113 
    93114    # See test_96* for other 'defined' tests 
     115 
     116    return; 
    94117} 
    95118 
     
    141164        else => 1 
    142165    ); 
     166 
     167    return; 
    143168} 
    144169 
     
    146171    my $this = shift; 
    147172    $this->simpleTest( test => '0>1', then => 0, else => 1 ); 
     173 
     174    return; 
    148175} 
    149176 
     
    151178    my $this = shift; 
    152179    $this->simpleTest( test => '1>0', then => 1, else => 0 ); 
     180 
     181    return; 
    153182} 
    154183 
     
    156185    my $this = shift; 
    157186    $this->simpleTest( test => '1<0', then => 0, else => 1 ); 
     187 
     188    return; 
    158189} 
    159190 
     
    161192    my $this = shift; 
    162193    $this->simpleTest( test => '0<1', then => 1, else => 0 ); 
     194 
     195    return; 
    163196} 
    164197 
     
    166199    my $this = shift; 
    167200    $this->simpleTest( test => "0>=\t1", then => 0, else => 1 ); 
     201 
     202    return; 
    168203} 
    169204 
     
    171206    my $this = shift; 
    172207    $this->simpleTest( test => '1>=0', then => 1, else => 0 ); 
     208 
     209    return; 
    173210} 
    174211 
     
    176213    my $this = shift; 
    177214    $this->simpleTest( test => '1>=1', then => 1, else => 0 ); 
     215 
     216    return; 
    178217} 
    179218 
     
    181220    my $this = shift; 
    182221    $this->simpleTest( test => '1<=0', then => 0, else => 1 ); 
     222 
     223    return; 
    183224} 
    184225 
     
    186227    my $this = shift; 
    187228    $this->simpleTest( test => '0<=1', then => 1, else => 0 ); 
     229 
     230    return; 
    188231} 
    189232 
     
    191234    my $this = shift; 
    192235    $this->simpleTest( test => '1<=1', then => 1, else => 0 ); 
     236 
     237    return; 
    193238} 
    194239 
     
    196241    my $this = shift; 
    197242    $this->simpleTest( test => "not 'A'='B'", then => 1, else => 0 ); 
     243 
     244    return; 
    198245} 
    199246 
     
    201248    my $this = shift; 
    202249    $this->simpleTest( test => "not NOT 'A'='B'", then => 0, else => 1 ); 
     250 
     251    return; 
    203252} 
    204253 
     
    206255    my $this = shift; 
    207256    $this->simpleTest( test => "'A'='A' AND 'B'='B'", then => 1, else => 0 ); 
     257 
     258    return; 
    208259} 
    209260 
     
    211262    my $this = shift; 
    212263    $this->simpleTest( test => "'A'='A' and 'B'='B'", then => 1, else => 0 ); 
     264 
     265    return; 
    213266} 
    214267 
     
    216269    my $this = shift; 
    217270    $this->simpleTest( test => "'A'='A' and 'B'='B'", then => 1, else => 0 ); 
     271 
     272    return; 
    218273} 
    219274 
     
    225280        else => 0 
    226281    ); 
     282 
     283    return; 
    227284} 
    228285 
     
    230287    my $this = shift; 
    231288    $this->simpleTest( test => "'A'='B' or 'B'='B'", then => 1, else => 0 ); 
     289 
     290    return; 
    232291} 
    233292 
     
    235294    my $this = shift; 
    236295    $this->simpleTest( test => "'A'='A' or 'B'='A'", then => 1, else => 0 ); 
     296 
     297    return; 
    237298} 
    238299 
     
    240301    my $this = shift; 
    241302    $this->simpleTest( test => "'A'='B' or 'B'='A'", then => 0, else => 1 ); 
     303 
     304    return; 
    242305} 
    243306