Skip to content

Commit

Permalink
Item8592: unit test to verify behaviour of encoding ! in the middle o…
Browse files Browse the repository at this point in the history
…f a heading

git-svn-id: http://svn.foswiki.org/trunk@7214 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Apr 18, 2010
1 parent aad5888 commit e53ded5
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions UnitTestContrib/test/unit/TOCTests.pm
Expand Up @@ -10,7 +10,8 @@ propagated into the TOC.
=cut

use FoswikiTestCase;
our @ISA = qw( FoswikiTestCase );
use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );

use strict;
use Foswiki;
Expand All @@ -21,13 +22,6 @@ use Unit::Request;
use Unit::Response;
use Error qw( :try );

my $testweb = "TestWeb";
my $testtopic1 = "TestTopic1";

my $fatwilly;
my $user;
my $testuser1 = "TestUser1";

my $setup_failure = '';

my $aurl; # Holds the %ATTACHURL%
Expand All @@ -50,43 +44,15 @@ With a few words of text.
HERE

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 setup_TOCtests {
my ( $this, $text, $params, $tocparams ) = @_;

my $query = new Unit::Request();
$fatwilly = new Foswiki( undef, $query );
$this->{request} = $query;
$this->{response} = new Unit::Response;
$user = $fatwilly->{user};

$surl = $fatwilly->getScriptUrl(1);

my $webObject = Foswiki::Meta->new( $fatwilly, $testweb );
$webObject->populateNewWeb();
$surl = $this->{session}->getScriptUrl(1);

$Foswiki::Plugins::SESSION = $fatwilly;
}

sub tear_down {
my $this = shift;
$this->removeWebFixture( $fatwilly, $testweb );
eval { $fatwilly->finish() };
$this->SUPER::tear_down();
}

sub setup_TOCtests {
my ( $this, $text, $web, $topic, $params, $tocparams ) = @_;

$fatwilly->{webName} = $web;
$fatwilly->{topicName} = $topic;
my $render = $fatwilly->renderer;
$this->{session}->{webName} = $this->{test_web};
$this->{session}->{topicName} = $this->{test_topic};

use Foswiki::Attrs;
my $attr = new Foswiki::Attrs($params);
Expand All @@ -96,8 +62,9 @@ sub setup_TOCtests {
}

# Now generate the TOC
my $topicObject = Foswiki::Meta->new( $fatwilly, $web, $topic );
my $res = $fatwilly->TOC( $text, $topicObject, $tocparams );
my $topicObject = Foswiki::Meta->new(
$this->{session}, $this->{test_web}, $this->{test_topic} );
my $res = $this->{session}->TOC( $text, $topicObject, $tocparams );

eval 'use HTML::TreeBuilder; use HTML::Element;';
if ($@) {
Expand Down Expand Up @@ -129,7 +96,7 @@ sub setup_TOCtests {
sub test_parameters {
my $this = shift;

my @children = setup_TOCtests( $this, $testtext1, $testtopic1, $testweb,
my @children = $this->setup_TOCtests( $testtext1,
'param1="a little luck" param2="no luck"', '' );

# @children will have alternating ' * ' and an href
Expand All @@ -147,7 +114,7 @@ sub test_no_parameters {
my $this = shift;

my @children =
setup_TOCtests( $this, $testtext1, $testtopic1, $testweb, '', '' );
$this->setup_TOCtests( $testtext1, '', '' );

# @children will have alternating ' * ' and an href
foreach my $c (@children) {
Expand All @@ -158,4 +125,39 @@ sub test_no_parameters {
}
}

sub test_Item8592 {
my $this = shift;
my $text = <<'HERE';
%TOC%
---+ A level 1 head!line
---++ Followed by a level 2! headline
---++!! Another level 2 headline
HERE
my $topicObject = Foswiki::Meta->new(
$this->{session}, $this->{test_web}, $this->{test_topic}, $text );
$topicObject->save();
my $res = $topicObject->expandMacros($text );
$res = $topicObject->renderTML( $res );

$this->assert_html_equals(<<HTML, $res);
<a name="foswikiTOC"></a>
<div class="foswikiToc">
<ul>
<li> <a href="#A_level_1_head_33line">A level 1 head!line</a>
<ul>
<li> <a href="#Followed_by_a_level_2_33_headline">
Followed by a level 2! headline</a>
</li>
</ul>
</li>
</ul>
</div>
<nop><h1><a name="A_level_1_head_33line"></a> A level 1 head!line </h1>
<nop><h2><a name="Followed_by_a_level_2_33_headline"></a>
Followed by a level 2! headline </h2>
<nop><h2><a name="Another_level_2_headline"></a>
Another level 2 headline </h2>
HTML
}

1;

0 comments on commit e53ded5

Please sign in to comment.