Skip to content

Commit

Permalink
Item1847: robust fix for pushTopicContext and internal prefs, and uni…
Browse files Browse the repository at this point in the history
…t tested too

git-svn-id: http://svn.foswiki.org/trunk@4541 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jul 23, 2009
1 parent a5460d1 commit 2b624dc
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
70 changes: 70 additions & 0 deletions UnitTestContrib/test/unit/FuncTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1050,4 +1050,74 @@ sub test_searchInWebContent {
my $this = shift;
}

sub test_pushPopContext {
my $this = shift;
my $topic1 = "DanTien";
my $topic2 = "SandWich";

Foswiki::Func::saveTopicText(
$this->{test_web}, $topic1, <<SETS );
* Set ICE = COLD
SETS

# Force re-read of prefs
$Foswiki::Plugins::SESSION = $this->{session} =
new Foswiki( undef,
new Unit::Request( { topic => "$this->{test_web}.$topic1" } ) );

Foswiki::Func::saveTopicText(
$this->{test_web}, $topic2, <<SETS );
* Set ICE = SLIPPERY
SETS

$this->assert_equals($this->{test_web},
$this->{session}->{webName});
$this->assert_equals($topic1,
$this->{session}->{topicName});
$this->assert_equals($this->{test_web},
Foswiki::Func::getPreferencesValue('BASEWEB'));
$this->assert_equals($topic1,
Foswiki::Func::getPreferencesValue('BASETOPIC'));
$this->assert_equals($this->{test_web},
Foswiki::Func::getPreferencesValue('INCLUDINGWEB'));
$this->assert_equals($topic1,
Foswiki::Func::getPreferencesValue('INCLUDINGTOPIC'));
$this->assert_equals("COLD",
Foswiki::Func::getPreferencesValue('ICE'));

Foswiki::Func::pushTopicContext($this->{test_web}, $topic2);

$this->assert_equals($this->{test_web},
$this->{session}->{webName});
$this->assert_equals($topic2,
$this->{session}->{topicName});
$this->assert_equals(
$this->{test_web}, Foswiki::Func::getPreferencesValue('BASEWEB'));
$this->assert_equals(
$topic2, Foswiki::Func::getPreferencesValue('BASETOPIC'));
$this->assert_equals(
$this->{test_web}, Foswiki::Func::getPreferencesValue('INCLUDINGWEB'));
$this->assert_equals(
$topic2, Foswiki::Func::getPreferencesValue('INCLUDINGTOPIC'));
$this->assert_equals("SLIPPERY",
Foswiki::Func::getPreferencesValue('ICE'));

Foswiki::Func::popTopicContext();

$this->assert_equals($this->{test_web},
$this->{session}->{webName});
$this->assert_equals($topic1,
$this->{session}->{topicName});
$this->assert_equals($this->{test_web},
Foswiki::Func::getPreferencesValue('BASEWEB'));
$this->assert_equals($topic1,
Foswiki::Func::getPreferencesValue('BASETOPIC'));
$this->assert_equals($this->{test_web},
Foswiki::Func::getPreferencesValue('INCLUDINGWEB'));
$this->assert_equals($topic1,
Foswiki::Func::getPreferencesValue('INCLUDINGTOPIC'));
$this->assert_equals("COLD",
Foswiki::Func::getPreferencesValue('ICE'));
}

1;
5 changes: 5 additions & 0 deletions core/lib/Foswiki/Func.pm
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ sub pushTopicContext {
$session->{prefs}->pushTopicContext( $web, $topic );
$session->{webName} = $web;
$session->{topicName} = $topic;
$session->{prefs}->setInternalPreferences(
BASEWEB => $web,
BASETOPIC => $topic,
INCLUDINGWEB => $web,
INCLUDINGTOPIC => $topic);
}

=begin TML
Expand Down
18 changes: 16 additions & 2 deletions core/lib/Foswiki/Prefs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ sub pushTopicContext {
my ( $this, $web, $topic ) = @_;

my $stack = $this->{main};
push @{ $this->{contexts} }, $stack->size() - 1;
my %internals;
while (my ($k, $v) = each %{$this->{internals}}) {
$internals{$k} = $v;
}
push( @{ $this->{contexts} },
{ internals => \%internals, level => $stack->size() - 1 });
my @webPath = split( /[\/\.]+/, $web );
my $subWeb = '';
my $back;
Expand All @@ -269,6 +274,11 @@ sub pushTopicContext {
$back = $this->_getBackend( $web, $topic );
$stack->newLevel($back);
$stack->newLevel( Foswiki::Prefs::HASH->new() );

while ( my ( $k, $v ) = each %{$this->{internals}} ) {
$stack->insert( 'Set', $k, $v );
}

}

=begin TML
Expand All @@ -283,7 +293,11 @@ Returns the context to the state it was in before the
sub popTopicContext {
my $this = shift;
my $stack = $this->{main};
my $level = pop @{ $this->{contexts} };
my $context = pop( @{ $this->{contexts} });
my $level = $context->{level};
while (my ($k, $v) = each %{$context->{internals}}) {
$this->{internals}{$k} = $v;
}
$stack->restore($level);
splice @{ $this->{prefix} }, $level + 1 if @{ $this->{prefix} } > $level;
return (
Expand Down

0 comments on commit 2b624dc

Please sign in to comment.