Changeset 8309


Ignore:
Timestamp:
07/26/10 06:54:54 (22 months ago)
Author:
PaulHarvey
Message:

Item9317: Alias body to head zone wasn't good enough

Instead, we keep both zones, but if {OptimizePageLayout} not set, then
do special things to check the opposite zone when trying to walk the
requirements and when building the list of ZoneIDs to iterate over (for
applying the format param) we actually append the body records to the head
list before visiting

Added some stuff to the tests to stress this a little more. Also, test
that multiple ADDTOZONE calls to the same id will in fact overwrite instead
of add.

Changed the way we report missing requirements; they are pushed to an array
for any ZoneID whose requirements are being visited

Location:
trunk
Files:
2 edited

Legend:

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

    r8308 r8309  
    331331    my $tml = <<'HERE'; 
    332332%ADDTOHEAD{               "head1" text="text1" requires="head2"}% 
     333%ADDTOZONE{zone="head" id="head2" text="this-text-will-be-ignored"}% 
    333334%ADDTOZONE{zone="head" id="head2" text="text2"}% 
    334335%ADDTOZONE{"body"      id="body3" text="text3" requires="body4"}% 
    335336%ADDTOZONE{zone="body" id="body4" text="text4" requires="head2"}% 
    336 %ADDTOHEAD{               "head5" text="text5" requires="body4"}% 
     337%ADDTOHEAD{               "head5" text="text5" requires="body4,body3,body6"}% 
     338%ADDTOZONE{zone="body" id="body6" text="text6" requires="head2,something-missing"}% 
     339%ADDTOZONE{zone="head" id="misc7" text="head::misc7"}% 
     340%ADDTOZONE{zone="body" id="misc7" text="body::misc7"}% 
    337341HERE 
    338342    my $expect = <<'HERE'; 
    339343HEAD: 
     344head::misc7 <!-- misc7 --> 
    340345text2 <!-- head2 --> 
    341346text1 <!-- head1 --> 
    342347text4 <!-- body4 --> 
    343348text3 <!-- body3 --> 
     349text6 <!-- body6 required id(s) that were missing from body zone: something-missing --> 
    344350text5 <!-- head5 --> 
     351body::misc7 <!-- misc7 --> 
    345352BODY: 
    346353HERE 
     
    367374    my $tml = <<'HERE'; 
    368375%ADDTOHEAD{               "head1" text="text1" requires="head2"}% 
     376%ADDTOZONE{zone="head" id="head2" text="this-text-will-be-ignored"}% 
    369377%ADDTOZONE{zone="head" id="head2" text="text2"}% 
    370378%ADDTOZONE{"body"      id="body3" text="text3" requires="body4"}% 
    371379%ADDTOZONE{zone="body" id="body4" text="text4" requires="head2"}% 
    372 %ADDTOHEAD{               "head5" text="text5" requires="body4"}% 
     380%ADDTOHEAD{               "head5" text="text5" requires="body4,body3,body6"}% 
     381%ADDTOZONE{zone="body" id="body6" text="text6" requires="head2,something-missing"}% 
     382%ADDTOZONE{zone="head" id="misc7" text="head::misc7"}% 
     383%ADDTOZONE{zone="body" id="misc7" text="body::misc7"}% 
    373384HERE 
    374385    my $expect = <<'HERE'; 
    375386HEAD: 
     387head::misc7 <!-- misc7 --> 
    376388text2 <!-- head2 --> 
    377389text1 <!-- head1 --> 
    378 text5 <!-- head5 required id(s) that were missing from head zone: body4 --> 
     390text5 <!-- head5 required id(s) that were missing from head zone: body4, body3, body6 --> 
    379391BODY: 
     392body::misc7 <!-- misc7 --> 
    380393text4 <!-- body4 required id(s) that were missing from body zone: head2 --> 
    381394text3 <!-- body3 --> 
     395text6 <!-- body6 required id(s) that were missing from body zone: head2, something-missing --> 
    382396HERE 
    383397    chomp($expect); 
     
    401415    my $tml = <<'HERE'; 
    402416%ADDTOHEAD{                "head1" text="text1" requires="head2"}% 
     417%ADDTOZONE{zone="head" id="head2" text="this-text-will-be-ignored"}% 
    403418%ADDTOZONE{zone="head" tag="head2" text="text2"}% 
    404419%ADDTOZONE{"body"      tag="body3" text="text3" requires="body4"}% 
    405420%ADDTOZONE{zone="body" tag="body4" text="text4" requires="head2"}% 
    406421%ADDTOHEAD{                "head5" text="text5" requires="body4"}% 
     422%ADDTOZONE{zone="head" id="misc7" text="head::misc7"}% 
     423%ADDTOZONE{zone="body" id="misc7" text="body::misc7"}% 
    407424HERE 
    408425    my $expect = <<'HERE'; 
    409426HEAD: 
     427head::misc7 <!-- misc7 --> 
    410428text2 <!-- head2 --> 
    411429text1 <!-- head1 --> 
    412430text5 <!-- head5 required id(s) that were missing from head zone: body4 --> 
    413431BODY: 
     432body::misc7 <!-- misc7 --> 
    414433text4 <!-- body4 required id(s) that were missing from body zone: head2 --> 
    415434text3 <!-- body3 --> 
  • trunk/core/lib/Foswiki.pm

    r8308 r8309  
    32363236      # to head zone instead for compatibility with ADDTOHEAD usage that has 
    32373237      # requirements that exist in the body zone. See ZoneTests/Item9317 
    3238     if ( $zone eq 'body' and not $Foswiki::cfg{OptimizePageLayout} ) { 
    3239         $zone = 'head'; 
    3240     } 
    32413238    $requires ||= ''; 
    32423239    $this->{$zone} ||= {}; 
     
    32573254        unless ( $thisZone->{$req} ) { 
    32583255            $thisZone->{$req} = { 
    3259                 id        => $req, 
    3260                 requires  => [], 
    3261                 text      => '', 
    3262                 populated => 0 
     3256                id              => $req, 
     3257                zone            => $zone, 
     3258                requires        => [], 
     3259                missingrequires => [], 
     3260                text            => '', 
     3261                populated       => 0 
    32633262            }; 
    32643263        } 
     
    32743273 
    32753274    # override previous properties 
    3276     $zoneID->{requires}  = \@requires; 
    3277     $zoneID->{text}      = $data; 
    3278     $zoneID->{populated} = 1; 
     3275    $zoneID->{zone}            = $zone; 
     3276    $zoneID->{requires}        = \@requires; 
     3277    $zoneID->{missingrequires} = []; 
     3278    $zoneID->{text}            = $data; 
     3279    $zoneID->{populated}       = 1; 
    32793280 
    32803281    return; 
     
    33003301sub _getMissingRequiredZoneIDs { 
    33013302    my ($zoneID) = @_; 
    3302     my @missingIDs; 
    3303  
    3304     foreach my $requiredZoneID ( @{ $zoneID->{requires} } ) { 
    3305         if ( not $requiredZoneID->{populated} ) { 
    3306             push( @missingIDs, $requiredZoneID->{id} ); 
    3307         } 
    3308     } 
    3309  
    3310     return join( ', ', @missingIDs ); 
     3303 
     3304    return join( ', ', @{ $zoneID->{missingrequires} } ); 
    33113305} 
    33123306 
     
    33413335    my %visited; 
    33423336    my @total; 
    3343     foreach my $zoneID ( values %{ $this->{_zones}{$zone} } ) { 
    3344         _visitZoneID( $zoneID, \%visited, \@total ); 
    3345     } 
    3346  
    3347     # kill a zone once it has been rendered 
    3348     undef $this->{_zones}{$zone}; 
     3337    my @zoneIDs = values %{ $this->{_zones}{$zone} }; 
     3338 
     3339    # When {OptimizePageLayout} is NOT set, try to treat head and body 
     3340    # zones as merged for compatibility with ADDTOHEAD usage where requirements 
     3341    # have been moved to the body zone. See ZoneTests/Item9317 
     3342    if ( not $Foswiki::cfg{OptimizePageLayout} and $zone eq 'head' ) { 
     3343        @zoneIDs = ( @zoneIDs, values %{ $this->{_zones}{body} } ); 
     3344        foreach my $zoneID (@zoneIDs) { 
     3345            $this->_visitZoneID( $zoneID, \%visited, \@total ); 
     3346        } 
     3347        undef $this->{_zones}{'head'}; 
     3348        undef $this->{_zones}{'body'}; 
     3349    } 
     3350    else { 
     3351        foreach my $zoneID (@zoneIDs) { 
     3352            $this->_visitZoneID( $zoneID, \%visited, \@total ); 
     3353        } 
     3354 
     3355        # kill a zone once it has been rendered 
     3356        undef $this->{_zones}{$zone}; 
     3357    } 
     3358 
    33493359    my @result        = (); 
    33503360    my $missingformat = $params->{missingformat}; 
     
    33603370            $text =~ s/\s+$//g; 
    33613371        } 
     3372 
    33623373        # ASSERT($text, "No content for zone id $item->{id} in zone $zone") 
    33633374        # if DEBUG; 
     
    33703381        $line =~ s/\$missing\b/$missingformat/g; 
    33713382        $line =~ s/\$missingids\b/$missingids/g; 
    3372         $line =~ s/\$zone\b/$zone/g; 
     3383        $line =~ s/\$zone\b/$item->{zone}/g; 
    33733384        $line = expandStandardEscapes($line); 
    33743385        next unless $line; 
     
    33913402 
    33923403sub _visitZoneID { 
    3393     my ( $zoneID, $visited, $list ) = @_; 
     3404    my ( $this, $zoneID, $visited, $list ) = @_; 
     3405 
    33943406    return if $visited->{$zoneID}; 
     3407 
    33953408    $visited->{$zoneID} = 1; 
     3409 
    33963410    foreach my $requiredZoneID ( @{ $zoneID->{requires} } ) { 
    3397         _visitZoneID( $requiredZoneID, $visited, $list ); 
     3411        my $zoneIDToVisit; 
     3412 
     3413        if (    not $Foswiki::cfg{OptimizePageLayout} 
     3414            and not $requiredZoneID->{populated} ) 
     3415        { 
     3416 
     3417            # Compatibility mode, where we are trying to treat head and body 
     3418            # zones as merged, and a required ZoneID isn't populated. Try 
     3419            # opposite zone to see if it exists there instead. Item9317 
     3420            if ( $requiredZoneID->{zone} eq 'head' ) { 
     3421                $zoneIDToVisit = $this->{_zones}{body}{ $requiredZoneID->{id} }; 
     3422            } 
     3423            else { 
     3424                $zoneIDToVisit = $this->{_zones}{head}{ $requiredZoneID->{id} }; 
     3425            } 
     3426            if ( not $zoneIDToVisit->{populated} ) { 
     3427 
     3428                # Oops, the required ZoneID doesn't exist there either; reset 
     3429                $zoneIDToVisit = $requiredZoneID; 
     3430            } 
     3431        } 
     3432        else { 
     3433            $zoneIDToVisit = $requiredZoneID; 
     3434        } 
     3435        $this->_visitZoneID( $zoneIDToVisit, $visited, $list ); 
     3436 
     3437        if ( not $zoneIDToVisit->{populated} ) { 
     3438 
     3439            # Finally, we got to here and the required ZoneID just cannot be 
     3440            # found in either head or body (or other) zones, so record it for 
     3441            # diagnostic purposes ($missingids format token) 
     3442            push( @{ $zoneID->{missingrequires} }, $zoneIDToVisit->{id} ); 
     3443        } 
    33983444    } 
    33993445    push( @{$list}, $zoneID ); 
Note: See TracChangeset for help on using the changeset viewer.