Changeset 13108


Ignore:
Timestamp:
11/18/11 05:26:10 (6 months ago)
Author:
PaulHarvey
Message:

Item11259: Fix inappropriate Foswiki::Meta->new()

  • MongoDBPlugin failed miserably in UploadScriptTests because of the incorrect Foswiki::Meta->new() call. Replaced with Foswiki::Func::readTopic()
  • When LocalLib has ASSERTS=1, doing $this->assert() failure from set_up crashes test runner.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Release01x01/UnitTestContrib/test/unit/UploadScriptTests.pm

    r12508 r13108  
    2828    $this->SUPER::set_up(); 
    2929    $UI_FN ||= $this->getUIFn('upload'); 
    30     my $topicObject = 
    31       Foswiki::Meta->new( $this->{session}, $this->{test_web}, 
    32         $this->{test_topic}, "   * Set ATTACHFILESIZELIMIT = 511\n", undef ); 
    33     $topicObject->put( 'FORM', $FORM ); 
     30    my ($topicObject) = 
     31      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     32    $topicObject->text("   * Set ATTACHFILESIZELIMIT = 511\n"); 
     33    $topicObject->putAll( 'FORM', $FORM ); 
    3434    $topicObject->putAll( 'FIELD', @FIELDS ); 
    3535    $topicObject->save( forcenewrevision => 1 ); 
    36     $this->_assert_meta_stillgood(); 
     36    $this->_assert_meta_stillgood(0); 
    3737 
    3838    return; 
     
    406406# Assert that we've still got good meta 
    407407sub _assert_meta_stillgood { 
    408     my ($this) = @_; 
     408    my ( $this, $assert ) = @_; 
    409409    my ($topicObj) = 
    410410      Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 
     
    413413    my %tFIELDShash = map { $_->{name} => $_ } @tFIELDS; 
    414414 
    415     $this->assert($tFORM); 
    416     $this->assert( exists $tFORM->{name} ); 
    417     $this->assert( $tFORM->{name} eq $FORM->{name} ); 
    418     $this->assert( scalar(@tFIELDS) ); 
    419     $this->assert( scalar(@tFIELDS) == scalar(@FIELDS) ); 
     415    return unless $this->_assert_( $assert, $tFORM ); 
     416    return unless $this->_assert_( $assert, exists $tFORM->{name} ); 
     417    return unless $this->_assert_( $assert, $tFORM->{name} eq $FORM->{name} ); 
     418    return unless $this->_assert_( $assert, scalar(@tFIELDS) ); 
     419    return 
     420      unless $this->_assert_( $assert, scalar(@tFIELDS) == scalar(@FIELDS) ); 
    420421    foreach my $name ( keys %FIELDShash ) { 
    421         $this->assert( 
     422        return 
     423          unless $this->_assert_( 
     424            $assert, 
    422425            exists $tFIELDShash{$name}, 
    423426"$this->{test_web}.$this->{test_topic} did not contain META:FIELD[name='$name']" 
    424         ); 
    425         $this->assert( 
     427          ); 
     428        return 
     429          unless $this->_assert_( 
     430            $assert, 
    426431            exists $tFIELDShash{$name}->{value}, 
    427432"$this->{test_web}.$this->{test_topic} did not contain a value key in META:FIELD[name='$name']" 
    428         ); 
    429         $this->assert( 
     433          ); 
     434        return 
     435          unless $this->_assert_( 
     436            $assert, 
    430437            $tFIELDShash{$name}->{value} eq $FIELDShash{$name}->{value}, 
    431438"'$this->{test_web}.$this->{test_topic}'/META:FIELD[name='$name'].value = '$tFIELDShash{$name}->{value}' but expected '$FIELDShash{$name}->{value}'" 
    432         ); 
    433     } 
    434  
    435     return; 
     439          ); 
     440    } 
     441 
     442    return; 
     443} 
     444 
     445# ->assert() from set_up crashes TestRunner if LocalLib has ASSERTS=1, so die 
     446# differently inside set_up 
     447sub _assert_ { 
     448    my ( $this, $assert, $condition, $message ) = @_; 
     449 
     450    if ( !defined $assert || $assert ) { 
     451        $this->assert( $condition, $message ); 
     452    } 
     453    elsif ( !$condition ) { 
     454        print STDERR 'ASSERT FAILED during set_up: ' . ( $message || '' ); 
     455    } 
     456 
     457    return $condition; 
    436458} 
    437459 
Note: See TracChangeset for help on using the changeset viewer.