Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item8438: allow users to define a parent for the child topic; added s…
…ome basic unit tests for %TOPICCREATE% git-svn-id: http://svn.foswiki.org/trunk/TopicCreatePlugin@6183 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
- Loading branch information
AndrewJones
authored and
AndrewJones
committed
Jan 28, 2010
1 parent
1069d09
commit 9de9fad
Showing
6 changed files
with
224 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Tests %TOPICATTACH% | ||
# TODO: this is just a stub... | ||
use strict; | ||
|
||
package TopicAttachTests; | ||
|
||
use base qw(FoswikiFnTestCase); | ||
|
||
use strict; | ||
use Foswiki; | ||
use Foswiki::Func; | ||
use Foswiki::Plugins::TopicCreatePlugin; | ||
|
||
sub new { | ||
my $self = shift()->SUPER::new(@_); | ||
return $self; | ||
} | ||
|
||
# Set up the test fixture | ||
sub set_up { | ||
my $this = shift; | ||
|
||
$this->SUPER::set_up(); | ||
} | ||
|
||
sub tear_down { | ||
my $this = shift; | ||
$this->SUPER::tear_down(); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package TopicCreatePluginSuite; | ||
|
||
use base qw(Unit::TestSuite); | ||
|
||
sub name { 'TopicCreatePluginSuite' } | ||
|
||
sub include_tests { qw(TopicCreateTests) } | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
# Tests %TOPICCREATE% | ||
# still more that could be written, including: | ||
# - recursive %TOPICCREATE%'s | ||
package TopicCreateTests; | ||
|
||
use base qw( FoswikiFnTestCase ); | ||
|
||
use strict; | ||
use Foswiki; | ||
use Foswiki::Func; | ||
use Foswiki::Plugins::TopicCreatePlugin; | ||
|
||
my $simpleTemplate = "SimpleTemplateTopic"; | ||
|
||
sub new { | ||
my $self = shift()->SUPER::new(@_); | ||
return $self; | ||
} | ||
|
||
# Set up the test fixture | ||
sub set_up { | ||
my $this = shift; | ||
|
||
$this->SUPER::set_up(); | ||
|
||
# create a simple template topic | ||
Foswiki::Func::saveTopic( $this->{test_web}, $simpleTemplate, undef, | ||
<<'HERE'); | ||
---++ Template Topic | ||
A simple template topic | ||
HERE | ||
|
||
} | ||
|
||
sub tear_down { | ||
my $this = shift; | ||
$this->SUPER::tear_down(); | ||
} | ||
|
||
# test the simplest use of %TOPICCREATE% | ||
sub test_simple_create { | ||
my $this = shift; | ||
|
||
my $testTopic = "SimpleCreateTest"; | ||
|
||
my $sampleText = <<"HERE"; | ||
%META:TOPICINFO{author="guest" date="1053267450" format="1.0" version="1.35"}% | ||
%META:TOPICPARENT{name="WebHome"}% | ||
%TOPICCREATE{template="$simpleTemplate" topic="$testTopic"}% | ||
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" ); | ||
|
||
my ( $meta, $text ) = | ||
Foswiki::Func::readTopic( $this->{test_web}, $testTopic ); | ||
|
||
# check the text from the template has been copied | ||
$this->assert_matches( "simple template topic", | ||
$text, "Template text does not appear in the new topic" ); | ||
|
||
# parent of newly created topic should be same as the topic it was created from | ||
$this->assert_equals( $this->{test_topic}, $meta->getParent(), | ||
"Parent of new child topic is incorrect" ); | ||
} | ||
|
||
# test the use of %TOPICCREATE{ parent="WebHome" }% | ||
sub test_parent { | ||
my $this = shift; | ||
|
||
my $testTopic = "ParentTest"; | ||
|
||
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="WebHome"}% | ||
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" ); | ||
} | ||
|
||
# test the use of %TOPICCREATE{ disable="ThisTopic" }% | ||
sub test_disable { | ||
my $this = shift; | ||
|
||
my $testTopic = "DisableTest"; | ||
|
||
# WebHome is the current topic when running tests | ||
my $sampleText = <<"HERE"; | ||
%META:TOPICINFO{author="guest" date="1053267450" format="1.0" version="1.35"}% | ||
%META:TOPICPARENT{name="WebHome"}% | ||
%TOPICCREATE{template="$simpleTemplate" topic="$testTopic" disable="WebHome"}% | ||
HERE | ||
|
||
Foswiki::Plugins::TopicCreatePlugin::beforeSaveHandler( $sampleText, | ||
$this->{test_topic}, $this->{test_web} ); | ||
|
||
# child topic should not exist | ||
$this->assert( | ||
!Foswiki::Func::topicExists( $this->{test_web}, $testTopic ), | ||
"$testTopic was created, when it should not have been" | ||
); | ||
} | ||
|
||
# test creating a topic with parameters | ||
sub test_parameters { | ||
my $this = shift; | ||
|
||
my $template = "ParamsTemplateTopic"; | ||
my $testTopic = "ParamsTest"; | ||
|
||
# create a simple template topic | ||
Foswiki::Func::saveTopic( $this->{test_web}, $template, undef, <<'HERE'); | ||
---++ Template Topic | ||
A template topic with parameters | ||
* Param1: %URLPARAM{"param1"}% | ||
* Param2: %URLPARAM{"param2"}% | ||
HERE | ||
|
||
my $sampleText = <<"HERE"; | ||
%META:TOPICINFO{author="guest" date="1053267450" format="1.0" version="1.35"}% | ||
%META:TOPICPARENT{name="WebHome"}% | ||
%TOPICCREATE{template="$template" topic="$testTopic" parameters="param1=Bergkamp¶m2=Henry"}% | ||
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 same as the topic it was created from | ||
my ( undef, $text ) = | ||
Foswiki::Func::readTopic( $this->{test_web}, $testTopic ); | ||
|
||
$this->assert_matches( "Bergkamp", $text, | ||
"param1 does not appear in the new topic" ); | ||
$this->assert_matches( "Henry", $text, | ||
"param2 does not appear in the new topic" ); | ||
} | ||
|
||
1; |