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

Item11431: Clean UnitTests of Foswiki->new/finish

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

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

The recipe was:

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UnitTestContrib/test/unit/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 
Note: See TracChangeset for help on using the changeset viewer.