Changeset 13689
- Timestamp:
- 01/17/12 23:36:06 (17 months ago)
- Location:
- trunk/UnitTestContrib/test/unit
- Files:
-
- 2 edited
-
FoswikiFnTestCase.pm (modified) (4 diffs)
-
FoswikiTestCase.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/FoswikiFnTestCase.pm
r13632 r13689 2 2 3 3 package FoswikiFnTestCase; 4 use strict; 5 use warnings; 4 6 5 7 =begin TML … … 25 27 =cut 26 28 27 use FoswikiTestCase ;29 use FoswikiTestCase(); 28 30 our @ISA = qw( FoswikiTestCase ); 29 31 30 use strict; 31 32 use Foswiki; 33 use Unit::Request; 34 use Unit::Response; 35 use Foswiki::UI::Register; 32 use Foswiki(); 33 use Unit::Request(); 34 use Unit::Response(); 35 use Foswiki::UI::Register(); 36 36 use Error qw( :try ); 37 37 … … 85 85 $query->path_info("/$this->{test_web}/$this->{test_topic}"); 86 86 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 = (); 92 91 $this->{session}->net->setMailHandler( \&FoswikiFnTestCase::sentMail ); 93 92 my $webObject = Foswiki::Meta->new( $this->{session}, $this->{test_web} ); … … 108 107 $this->{test_user_cuid} = 109 108 $this->{session}->{users}->getCanonicalUserID( $this->{test_user_login} ); 109 $this->{test_topicObject}->finish() if $this->{test_topicObject}; 110 110 $this->{test_topicObject} = Foswiki::Meta->new( 111 111 $this->{session}, $this->{test_web}, -
trunk/UnitTestContrib/test/unit/FoswikiTestCase.pm
r13632 r13689 19 19 use strict; 20 20 use warnings; 21 22 use Assert; 21 23 use Unit::TestCase; 22 24 our @ISA = qw( Unit::TestCase ); … … 30 32 use Unit::Response; 31 33 use Error qw( :try ); 34 35 sub SINGLE_SINGLETONS { 0 } 32 36 33 37 BEGIN { … … 437 441 close(F); 438 442 443 ASSERT( !defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 444 439 445 # Force completion of %Foswiki::cfg 440 446 # This must be done before moving the logging. 441 447 my $query = new Unit::Request(); 442 448 my $tmp = new Foswiki( undef, $query ); 449 ASSERT( defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 443 450 $tmp->finish(); 451 ASSERT( !defined $Foswiki::Plugins::SESSION ) if SINGLE_SINGLETONS; 444 452 445 453 my %tempDirOptions = ( CLEANUP => 1 ); … … 477 485 sub tear_down { 478 486 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 } 480 492 eval { File::Path::rmtree( $Foswiki::cfg{WorkingDir} ); }; 481 493 %Foswiki::cfg = eval $this->{__FoswikiSafe}; … … 566 578 567 579 sub 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) ); 573 589 my $response = 574 UNIVERSAL::isa( $ _[0], 'Foswiki' )575 ? $ _[0]->{response}590 UNIVERSAL::isa( $session, 'Foswiki' ) 591 ? $session->{response} 576 592 : $Foswiki::Plugins::SESSION->{response}; 577 593 … … 708 724 my ( $this, $user, $query, @args ) = @_; 709 725 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; 717 732 ( $this->{test_topicObject} ) = 718 733 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 719 734 720 735 return $this->{session}; 736 } 737 738 sub 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; 721 746 } 722 747
Note: See TracChangeset
for help on using the changeset viewer.
