Changeset 13689


Ignore:
Timestamp:
01/17/12 23:36:06 (17 months ago)
Author:
PaulHarvey
Message:

Item11431: Add finish..session, SINGLE_SINGLETONS

Location:
trunk/UnitTestContrib/test/unit
Files:
2 edited

Legend:

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

    r13632 r13689  
    22 
    33package FoswikiFnTestCase; 
     4use strict; 
     5use warnings; 
    46 
    57=begin TML 
     
    2527=cut 
    2628 
    27 use FoswikiTestCase; 
     29use FoswikiTestCase(); 
    2830our @ISA = qw( FoswikiTestCase ); 
    2931 
    30 use strict; 
    31  
    32 use Foswiki; 
    33 use Unit::Request; 
    34 use Unit::Response; 
    35 use Foswiki::UI::Register; 
     32use Foswiki(); 
     33use Unit::Request(); 
     34use Unit::Response(); 
     35use Foswiki::UI::Register(); 
    3636use Error qw( :try ); 
    3737 
     
    8585    $query->path_info("/$this->{test_web}/$this->{test_topic}"); 
    8686 
    87     $this->{session}           = new Foswiki( undef, $query ); 
    88     $this->{request}           = $query; 
    89     $this->{response}          = new Unit::Response(); 
    90     $Foswiki::Plugins::SESSION = $this->{session}; 
    91     @mails                     = (); 
     87    # Note: some tests are testing Foswiki::UI which also creates a session 
     88    $this->createNewFoswikiSession( undef, $query ); 
     89    $this->{response} = new Unit::Response(); 
     90    @mails = (); 
    9291    $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); 
    9392    my $webObject = Foswiki::Meta->new( $this->{session}, $this->{test_web} ); 
     
    108107    $this->{test_user_cuid} = 
    109108      $this->{session}->{users}->getCanonicalUserID( $this->{test_user_login} ); 
     109    $this->{test_topicObject}->finish() if $this->{test_topicObject}; 
    110110    $this->{test_topicObject} = Foswiki::Meta->new( 
    111111        $this->{session},    $this->{test_web}, 
  • trunk/UnitTestContrib/test/unit/FoswikiTestCase.pm

    r13632 r13689  
    1919use strict; 
    2020use warnings; 
     21 
     22use Assert; 
    2123use Unit::TestCase; 
    2224our @ISA = qw( Unit::TestCase ); 
     
    3032use Unit::Response; 
    3133use Error qw( :try ); 
     34 
     35sub SINGLE_SINGLETONS { 0 } 
    3236 
    3337BEGIN { 
     
    437441    close(F); 
    438442 
     443    ASSERT( !defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 
     444 
    439445    # Force completion of %Foswiki::cfg 
    440446    # This must be done before moving the logging. 
    441447    my $query = new Unit::Request(); 
    442448    my $tmp = new Foswiki( undef, $query ); 
     449    ASSERT( defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 
    443450    $tmp->finish(); 
     451    ASSERT( !defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 
    444452 
    445453    my %tempDirOptions = ( CLEANUP => 1 ); 
     
    477485sub tear_down { 
    478486    my $this = shift; 
    479     $this->{session}->finish() if $this->{session}; 
     487 
     488    if ( $this->{session} ) { 
     489        ASSERT( $this->{session}->isa('Foswiki') ) if SINGLE_SINGLETONS; 
     490        $this->finishFoswikiSession(); 
     491    } 
    480492    eval { File::Path::rmtree( $Foswiki::cfg{WorkingDir} ); }; 
    481493    %Foswiki::cfg = eval $this->{__FoswikiSafe}; 
     
    566578 
    567579sub capture { 
    568     my $this = shift; 
    569  
    570     my ( $stdout, $stderr, $result ) = $this->captureSTD(@_); 
    571     my $fn = shift; 
    572  
     580    my ( $this, $fn, $session, @args ) = @_; 
     581 
     582    # $fn may create a new Foswiki singleton, so it should take care to avoid 
     583    # stomping on the existing one without $this->finishFoswikiSession() or 
     584    # createNewFoswikiSession() 
     585    my ( $stdout, $stderr, $result ) = 
     586      $this->captureSTD( $fn, $session, @args ); 
     587 
     588    ASSERT( ref($session) || ref($Foswiki::Plugins::SESSION) ); 
    573589    my $response = 
    574       UNIVERSAL::isa( $_[0], 'Foswiki' ) 
    575       ? $_[0]->{response} 
     590      UNIVERSAL::isa( $session, 'Foswiki' ) 
     591      ? $session->{response} 
    576592      : $Foswiki::Plugins::SESSION->{response}; 
    577593 
     
    708724    my ( $this, $user, $query, @args ) = @_; 
    709725 
    710     $this->{session}->finish() if $this->{session}; 
    711     $this->{request}->finish() 
    712       if ( $this->{request} && $this->{request}->can('finish') ); 
    713     $this->{session}           = Foswiki->new( $user, $query, @args ); 
    714     $this->{request}           = $this->{session}{request}; 
    715     $Foswiki::Plugins::SESSION = $this->{session}; 
    716     $this->{test_topicObject}->finish() if $this->{test_topicObject}; 
     726    $this->{test_topicObject}->finish()           if $this->{test_topicObject}; 
     727    $this->{session}->finish()                    if $this->{session}; 
     728    ASSERT( !defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 
     729    $this->{session} = Foswiki->new( $user, $query, @args ); 
     730    $this->{request} = $this->{session}{request}; 
     731    ASSERT( defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 
    717732    ( $this->{test_topicObject} ) = 
    718733      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
    719734 
    720735    return $this->{session}; 
     736} 
     737 
     738sub finishFoswikiSession { 
     739    my ($this) = @_; 
     740 
     741    $this->{session}->finish() if defined $this->{session}; 
     742    ASSERT( !$Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 
     743    $this->{session} = undef; 
     744 
     745    return; 
    721746} 
    722747 
Note: See TracChangeset for help on using the changeset viewer.