Changeset 8309
- Timestamp:
- 07/26/10 06:54:54 (22 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
UnitTestContrib/test/unit/ZoneTests.pm (modified) (3 diffs)
-
core/lib/Foswiki.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/ZoneTests.pm
r8308 r8309 331 331 my $tml = <<'HERE'; 332 332 %ADDTOHEAD{ "head1" text="text1" requires="head2"}% 333 %ADDTOZONE{zone="head" id="head2" text="this-text-will-be-ignored"}% 333 334 %ADDTOZONE{zone="head" id="head2" text="text2"}% 334 335 %ADDTOZONE{"body" id="body3" text="text3" requires="body4"}% 335 336 %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"}% 337 341 HERE 338 342 my $expect = <<'HERE'; 339 343 HEAD: 344 head::misc7 <!-- misc7 --> 340 345 text2 <!-- head2 --> 341 346 text1 <!-- head1 --> 342 347 text4 <!-- body4 --> 343 348 text3 <!-- body3 --> 349 text6 <!-- body6 required id(s) that were missing from body zone: something-missing --> 344 350 text5 <!-- head5 --> 351 body::misc7 <!-- misc7 --> 345 352 BODY: 346 353 HERE … … 367 374 my $tml = <<'HERE'; 368 375 %ADDTOHEAD{ "head1" text="text1" requires="head2"}% 376 %ADDTOZONE{zone="head" id="head2" text="this-text-will-be-ignored"}% 369 377 %ADDTOZONE{zone="head" id="head2" text="text2"}% 370 378 %ADDTOZONE{"body" id="body3" text="text3" requires="body4"}% 371 379 %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"}% 373 384 HERE 374 385 my $expect = <<'HERE'; 375 386 HEAD: 387 head::misc7 <!-- misc7 --> 376 388 text2 <!-- head2 --> 377 389 text1 <!-- head1 --> 378 text5 <!-- head5 required id(s) that were missing from head zone: body4 -->390 text5 <!-- head5 required id(s) that were missing from head zone: body4, body3, body6 --> 379 391 BODY: 392 body::misc7 <!-- misc7 --> 380 393 text4 <!-- body4 required id(s) that were missing from body zone: head2 --> 381 394 text3 <!-- body3 --> 395 text6 <!-- body6 required id(s) that were missing from body zone: head2, something-missing --> 382 396 HERE 383 397 chomp($expect); … … 401 415 my $tml = <<'HERE'; 402 416 %ADDTOHEAD{ "head1" text="text1" requires="head2"}% 417 %ADDTOZONE{zone="head" id="head2" text="this-text-will-be-ignored"}% 403 418 %ADDTOZONE{zone="head" tag="head2" text="text2"}% 404 419 %ADDTOZONE{"body" tag="body3" text="text3" requires="body4"}% 405 420 %ADDTOZONE{zone="body" tag="body4" text="text4" requires="head2"}% 406 421 %ADDTOHEAD{ "head5" text="text5" requires="body4"}% 422 %ADDTOZONE{zone="head" id="misc7" text="head::misc7"}% 423 %ADDTOZONE{zone="body" id="misc7" text="body::misc7"}% 407 424 HERE 408 425 my $expect = <<'HERE'; 409 426 HEAD: 427 head::misc7 <!-- misc7 --> 410 428 text2 <!-- head2 --> 411 429 text1 <!-- head1 --> 412 430 text5 <!-- head5 required id(s) that were missing from head zone: body4 --> 413 431 BODY: 432 body::misc7 <!-- misc7 --> 414 433 text4 <!-- body4 required id(s) that were missing from body zone: head2 --> 415 434 text3 <!-- body3 --> -
trunk/core/lib/Foswiki.pm
r8308 r8309 3236 3236 # to head zone instead for compatibility with ADDTOHEAD usage that has 3237 3237 # requirements that exist in the body zone. See ZoneTests/Item9317 3238 if ( $zone eq 'body' and not $Foswiki::cfg{OptimizePageLayout} ) {3239 $zone = 'head';3240 }3241 3238 $requires ||= ''; 3242 3239 $this->{$zone} ||= {}; … … 3257 3254 unless ( $thisZone->{$req} ) { 3258 3255 $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 3263 3262 }; 3264 3263 } … … 3274 3273 3275 3274 # 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; 3279 3280 3280 3281 return; … … 3300 3301 sub _getMissingRequiredZoneIDs { 3301 3302 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} } ); 3311 3305 } 3312 3306 … … 3341 3335 my %visited; 3342 3336 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 3349 3359 my @result = (); 3350 3360 my $missingformat = $params->{missingformat}; … … 3360 3370 $text =~ s/\s+$//g; 3361 3371 } 3372 3362 3373 # ASSERT($text, "No content for zone id $item->{id} in zone $zone") 3363 3374 # if DEBUG; … … 3370 3381 $line =~ s/\$missing\b/$missingformat/g; 3371 3382 $line =~ s/\$missingids\b/$missingids/g; 3372 $line =~ s/\$zone\b/$ zone/g;3383 $line =~ s/\$zone\b/$item->{zone}/g; 3373 3384 $line = expandStandardEscapes($line); 3374 3385 next unless $line; … … 3391 3402 3392 3403 sub _visitZoneID { 3393 my ( $zoneID, $visited, $list ) = @_; 3404 my ( $this, $zoneID, $visited, $list ) = @_; 3405 3394 3406 return if $visited->{$zoneID}; 3407 3395 3408 $visited->{$zoneID} = 1; 3409 3396 3410 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 } 3398 3444 } 3399 3445 push( @{$list}, $zoneID );
Note: See TracChangeset
for help on using the changeset viewer.
