Skip to content

Commit

Permalink
Item2042: TablePlugin: Add a new initialiseWhenRender() API
Browse files Browse the repository at this point in the history
Adding the unit test for the new API call
Also adding test for ID incrementing


git-svn-id: http://svn.foswiki.org/branches/Release01x00@5173 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Sep 29, 2009
1 parent 211f9ed commit 1404d7f
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions TablePlugin/test/unit/TablePlugin/TablePluginTests.pm
Expand Up @@ -476,4 +476,134 @@ EXPECTED
$this->do_test( $expected, $actual );
}


=pod
Tests that two tables have IDs suffixed by 1 and 2
=cut

sub test_tableIdNumbering {
my $this = shift;

my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<table cellspacing="0" id="table1" cellpadding="0" class="foswikiTable" rules="rows" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol0 foswikiFirstCol"> a </td>
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol1 foswikiLastCol"> b </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol0 foswikiFirstCol foswikiLast"> 2 </td>
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol1 foswikiLastCol foswikiLast"> 3 </td>
</tr>
</tbody>
</table>
<p />
<nop>
<nop>
<nop>
<table cellspacing="0" id="table2" cellpadding="0" class="foswikiTable" rules="rows" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol0 foswikiFirstCol"> a </td>
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol1 foswikiLastCol"> b </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol0 foswikiFirstCol foswikiLast"> 2 </td>
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol1 foswikiLastCol foswikiLast"> 3 </td>
</tr>
</tbody>
</table>
EXPECTED
my $actual = <<ACTUAL;
%TABLE{headerrows="0" footerrows="0"}%
| a | b |
| 2 | 3 |
%TABLE{headerrows="0" footerrows="0"}%
| a | b |
| 2 | 3 |
ACTUAL
$this->do_test( $expected, $actual );
}


=pod
Tests that two tables have IDs suffixed by 1 and 1 if the
initialiseWhenRender is called between two calls to Foswiki::Func::renderText
(as used by rdiff and CompareRevisionsAddOn) where two revisions of same topic
is called twice.
This test also tests the initialiseWhenRender API call
=cut

sub test_tableIdNumberingInitialiseWhenRender {
my $this = shift;

my $webName = $this->{test_web};
my $topicName = $this->{test_topic};
my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<table cellspacing="0" id="table1" cellpadding="0" class="foswikiTable" rules="rows" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol0 foswikiFirstCol"> a </td>
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol1 foswikiLastCol"> b </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol0 foswikiFirstCol foswikiLast"> 2 </td>
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol1 foswikiLastCol foswikiLast"> 3 </td>
</tr>
</tbody>
</table>
<nop>
<nop>
<nop>
<table cellspacing="0" id="table1" cellpadding="0" class="foswikiTable" rules="rows" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol0 foswikiFirstCol"> a </td>
<td bgcolor="#ffffff" valign="top" class="foswikiTableCol1 foswikiLastCol"> b </td>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted1 foswikiTableRowdataBg1">
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol0 foswikiFirstCol foswikiLast"> 2 </td>
<td bgcolor="#edf4f9" valign="top" class="foswikiTableCol1 foswikiLastCol foswikiLast"> 3 </td>
</tr>
</tbody>
</table>
EXPECTED
my $actual = <<ACTUAL;
%TABLE{headerrows="0" footerrows="0"}%
| a | b |
| 2 | 3 |
ACTUAL

# We render the same table twice and append the result
my $actual1 =
Foswiki::Func::expandCommonVariables( $actual, $topicName, $webName );

$actual1 = Foswiki::Func::renderText( $actual1, $webName, $topicName );

# Resetting the table counter (the objective of this test)
Foswiki::Plugins::TablePlugin::initialiseWhenRender();

my $actual2 =
Foswiki::Func::expandCommonVariables( $actual, $topicName, $webName );

$actual2 = Foswiki::Func::renderText( $actual2, $webName, $topicName );

$this->assert_html_equals( $expected, $actual1 . $actual2 );
}

1;

0 comments on commit 1404d7f

Please sign in to comment.