Skip to content

Commit

Permalink
Item8480: Fix for setting the parent
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/TopicCreatePlugin@6247 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AndrewJones authored and AndrewJones committed Feb 8, 2010
1 parent 9de9fad commit e66714e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions data/System/TopicCreatePlugin.txt
Expand Up @@ -67,6 +67,7 @@ Plugin settings are stored as preferences variables. To reference a plugin setti
| Plugin Release: | %$RELEASE% |
| Plugin Version: | %$VERSION% |
| Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
| 08 Feb 2010: | v1.3: Foswikitask:Item8480 - Fix for setting the parent; Fix for using Macros as the parent in =%<nop>TOPICCREATE%= -- Foswiki:Main.AndrewJones |
| 28 Jan 2010: | v1.2: Foswikitask:Item8438 - =%<nop>TOPICCREATE%= now allows you to define a parent for the new topic -- Foswiki:Main.AndrewJones |
| 29 Sep 2009: | v1.1: Foswikitask:Item4757 - Fixed warning when using =%<nop>TOPICATTACH%= -- Foswiki:Main.AndrewJones |
| 31 Mar 2009: | v1.0: Foswikitask:Item1262 - Ported to Foswiki and released as 1.0; Removed dependency on Unix utilities =cp= and =mkdir=, should now work on any OS that Foswiki does; Improved code to make it cleaner and use more of the official API; Removed depreciated API calls -- Foswiki:Main.AndrewJones |
Expand Down
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/TopicCreatePlugin.pm
Expand Up @@ -25,7 +25,7 @@ use vars qw(
);

our $VERSION = '$Rev$';
our $RELEASE = '1.2';
our $RELEASE = '1.3';
our $SHORTDESCRIPTION =
'Automatically create a set of topics and attachments at topic save time';
our $NO_PREFS_IN_TOPIC = 0;
Expand Down
4 changes: 3 additions & 1 deletion lib/Foswiki/Plugins/TopicCreatePlugin/Func.pm
Expand Up @@ -77,6 +77,8 @@ sub handleTopicCreate {
# expand relevant Foswiki Macros
$topicName =
Foswiki::Func::expandCommonVariables( $topicName, $theTopic, $theWeb );
$parent =
Foswiki::Func::expandCommonVariables( $parent, $theTopic, $theWeb );
$template =
Foswiki::Func::expandCommonVariables( $template, $theTopic, $theWeb );

Expand Down Expand Up @@ -108,7 +110,7 @@ sub handleTopicCreate {
my ( $meta, $text ) = &Foswiki::Func::readTopic( $templateWeb, $template );

# Set topic parent
$meta->putKeyed( 'TOPICPARENT', { name => $parent } );
$meta->putAll( 'TOPICPARENT', { name => $parent } );

# SMELL: replace with expandVariablesOnTopicCreation( $text );
# but then we seem to loose our parameters... Leaving it as it is for now
Expand Down
35 changes: 32 additions & 3 deletions test/unit/TopicCreatePlugin/TopicCreateTests.pm
Expand Up @@ -70,7 +70,7 @@ HERE
"Parent of new child topic is incorrect" );
}

# test the use of %TOPICCREATE{ parent="WebHome" }%
# test the use of %TOPICCREATE{ parent="FooBar" }%
sub test_parent {
my $this = shift;

Expand All @@ -80,7 +80,7 @@ sub test_parent {
%META:TOPICINFO{author="guest" date="1053267450" format="1.0" version="1.35"}%
%META:TOPICPARENT{name="WebHome"}%
%TOPICCREATE{template="$simpleTemplate" topic="$testTopic" parent="WebHome"}%
%TOPICCREATE{template="$simpleTemplate" topic="$testTopic" parent="FooBar"}%
HERE

Expand All @@ -94,10 +94,39 @@ HERE
# parent of newly created topic should be WebHome
my ( $meta, undef ) =
Foswiki::Func::readTopic( $this->{test_web}, $testTopic );
$this->assert_equals( "WebHome", $meta->getParent(),
$this->assert_equals( "FooBar", $meta->getParent(),
"Parent of new child topic is incorrect" );
}

# test the use of %TOPICCREATE{ parent="%HOMETOPIC%" }%
sub test_parent_as_macro {
my $this = shift;

my $testTopic = "ParentTest2";

my $sampleText = <<"HERE";
%META:TOPICINFO{author="guest" date="1053267450" format="1.0" version="1.35"}%
%META:TOPICPARENT{name="WebHome"}%
%TOPICCREATE{template="$simpleTemplate" topic="$testTopic" parent="%HOMETOPIC%"}%
HERE

Foswiki::Plugins::TopicCreatePlugin::beforeSaveHandler( $sampleText,
$this->{test_topic}, $this->{test_web} );

# child topic should now exist
$this->assert( Foswiki::Func::topicExists( $this->{test_web}, $testTopic ),
"$testTopic was not created" );

# parent of newly created topic should be WebHome
my ( $meta, undef ) =
Foswiki::Func::readTopic( $this->{test_web}, $testTopic );
$this->assert_equals( "WebHome", $meta->getParent(),
"Parent of new child topic is incorrect. Should be the same as the current topic."
);
}

# test the use of %TOPICCREATE{ disable="ThisTopic" }%
sub test_disable {
my $this = shift;
Expand Down

0 comments on commit e66714e

Please sign in to comment.