Skip to content

Commit

Permalink
Item2039: fixing table count in unit tests
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@4853 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Sep 12, 2009
1 parent a79444d commit 7861445
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 49 deletions.
8 changes: 5 additions & 3 deletions TablePlugin/lib/Foswiki/Plugins/TablePlugin.pm
Expand Up @@ -47,6 +47,8 @@ sub initPlugin {
my ( $web, $user );
( $topic, $web, $user, $installWeb ) = @_;

debug("TablePlugin initPlugin");

# check for Plugins.pm versions
if ( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning(
Expand All @@ -64,7 +66,7 @@ sub initPlugin {

sub preRenderingHandler {
### my ( $text, $removed ) = @_;

debug("TablePlugin preRenderingHandler");
my $sort = Foswiki::Func::getPreferencesValue('TABLEPLUGIN_SORT')
|| 'all';
return
Expand Down Expand Up @@ -116,18 +118,18 @@ sub initialiseWhenRender {
}

sub _readPluginSettings {
debug("TablePlugin _readPluginSettings");
my $configureAttrStr =
$Foswiki::cfg{Plugins}{TablePlugin}{DefaultAttributes};
my $pluginAttrStr =
Foswiki::Func::getPreferencesValue('TABLEPLUGIN_TABLEATTRIBUTES');
my $prefsAttrStr = Foswiki::Func::getPreferencesValue('TABLEATTRIBUTES');

debug("_readPluginSettings");
debug("\t configureAttrStr=$configureAttrStr") if $configureAttrStr;
debug("\t pluginAttrStr=$pluginAttrStr") if $pluginAttrStr;
debug("\t prefsAttrStr=$prefsAttrStr") if $prefsAttrStr;

debug("no configureAttrStr found; using default values") if !$configureAttrStr;
debug("no settings from configure could be read; using default values") if !$configureAttrStr;
$configureAttrStr ||= $DEFAULT_TABLE_SETTINGS;

$configureAttrStr = Foswiki::Func::expandCommonVariables($configureAttrStr, $topic, $web, undef) if $configureAttrStr;
Expand Down
6 changes: 2 additions & 4 deletions TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm
Expand Up @@ -29,14 +29,14 @@ use Error qw(:try);
my @curTable;
my $translationToken;
my $insideTABLE;
my $tableCount;
my $currTablePre;
my $didWriteDefaultStyle;
my $defaultAttrs; # to write generic table CSS
my $tableSpecificAttrs; # to write table specific table CSS
my $combinedTableAttrs; # default and specific table attributes

# not yet refactored:
my $tableCount;
my $sortCol;
my $maxSortCols;
my $requestedTable;
Expand All @@ -48,7 +48,6 @@ my $sortAllTables;
my $url;
my $currentSortDirection;
my @rowspan;
my $unsortEnabled; # SMELL: is always true
my $initDirection;

my $URL_ICON =
Expand Down Expand Up @@ -114,13 +113,12 @@ BEGIN {

# the maximum number of columns we will handle
$maxSortCols = 10000;
$unsortEnabled = 1; # if true, table columns can be unsorted
$didWriteDefaultStyle = 0;
$tableCount = 0;
}

sub _setDefaults {
_debug("_setDefaults");
$tableCount = 0;
$initDirection = $SORT_DIRECTION->{'ASCENDING'};
$sortAllTables = $sortTablesInText;
$currTablePre = '';
Expand Down
82 changes: 40 additions & 42 deletions TablePlugin/test/unit/TablePlugin/TablePluginTests.pm
Expand Up @@ -9,22 +9,18 @@ use base qw( FoswikiFnTestCase );
use Foswiki;
use Error qw( :try );
my $TEST_WEB_NAME = 'TemporaryTableFormattingTestWebTableFormatting';
my $tableCount = 0;

sub new {
my $self = shift()->SUPER::new( 'TableFormatting', @_ );
return $self;
}

sub set_up {
sub loadExtraConfig {
my $this = shift;
$this->SUPER::loadExtraConfig();

$this->SUPER::set_up();

# $this->{sup} = $this->{session}->getScriptUrl(0, 'view');
$Foswiki::cfg{AntiSpam}{RobotsAreWelcome} = 1;
$Foswiki::cfg{AntiSpam}{EmailPadding} = 'STUFFED';
$Foswiki::cfg{AllowInlineScript} = 1;
$ENV{SCRIPT_NAME} = ''; # required by fake sort URLs in expected text
$Foswiki::cfg{Plugins}{TablePlugin}{Enabled} = 1;
}

# This formats the text up to immediately before <nop>s are removed, so we
Expand All @@ -48,11 +44,12 @@ sub do_test {

sub test_simpleTableusing {
my $this = shift;
$tableCount++;
my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<table id="table1" class="foswikiTable" rules="rows" border="1">
<table id="table$tableCount" class="foswikiTable" rules="rows" border="1">
<tbody>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<td class="foswikiTableCol0 foswikiFirstCol"> a </td>
Expand Down Expand Up @@ -83,19 +80,19 @@ ACTUAL

sub test_simpleTheadTableUsingTablePlugin {
my $this = shift;

$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );

my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<table id="table1" class="foswikiTable" rules="rows" border="1">
<table id="table$tableCount" class="foswikiTable" rules="rows" border="1">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" title="Sort by this column">b</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">b</a> </th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -124,18 +121,19 @@ ACTUAL

sub test_simpleTfootTableusingTablePlugin {
my $this = shift;
$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $expected = <<EXPECTED;
<nop>
<nop>
<nop>
<nop>
<table id="table1" class="foswikiTable" rules="rows" border="1">
<table id="table$tableCount" class="foswikiTable" rules="rows" border="1">
<tfoot>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol foswikiLast"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" title="Sort by this column">ok</a> </th>
<th class="foswikiTableCol1 foswikiLastCol foswikiLast"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" title="Sort by this column">bad</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol foswikiLast"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">ok</a> </th>
<th class="foswikiTableCol1 foswikiLastCol foswikiLast"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">bad</a> </th>
</tr>
</tfoot>
<tbody>
Expand Down Expand Up @@ -165,7 +163,7 @@ ACTUAL

sub test_doubleTheadTableUsingTablePlugin {
my $this = shift;

$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );

Expand All @@ -174,11 +172,11 @@ sub test_doubleTheadTableUsingTablePlugin {
<nop>
<nop>
<nop>
<table id="table1" class="foswikiTable" rules="rows" border="1">
<table id="table$tableCount" class="foswikiTable" rules="rows" border="1">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" title="Sort by this column">b</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">b</a> </th>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> c </th>
Expand Down Expand Up @@ -212,7 +210,7 @@ ACTUAL

sub test_doubleTheadandTfootTableusingTablePlugin {
my $this = shift;

$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );

Expand All @@ -222,11 +220,11 @@ sub test_doubleTheadandTfootTableusingTablePlugin {
<nop>
<nop>
<nop>
<table id="table1" class="foswikiTable" rules="rows" border="1">
<table id="table$tableCount" class="foswikiTable" rules="rows" border="1">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" title="Sort by this column">b</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" title="Sort by this column">a</a> </th>
<th class="foswikiTableCol1 foswikiLastCol"> <a rel="nofollow" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" title="Sort by this column">b</a> </th>
</tr>
<tr class="foswikiTableEven foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> c </th>
Expand Down Expand Up @@ -265,7 +263,7 @@ Test sorting of Size column (format: '1.1 K')

sub test_sort_size {
my $this = shift;

$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $pubUrlSystemWeb = Foswiki::Func::getPubUrlPath() . '/System';
Expand All @@ -288,13 +286,13 @@ ACTUAL
<nop>
<nop>
<nop>
<table rules="rows" border="1" class="foswikiTable" id="table1">
<table rules="rows" border="1" class="foswikiTable" id="table$tableCount">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=1;up=1#sorted_table" rel="nofollow">Size</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
<th class="foswikiTableCol3 foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=1;up=0#sorted_table" rel="nofollow">Span date</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=$tableCount;up=1#sorted_table" rel="nofollow">Size</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
<th class="foswikiTableCol3 foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=$tableCount;up=0#sorted_table" rel="nofollow">Span date</a> </th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -342,7 +340,7 @@ Test sorting of a numbers column

sub test_sort_numbers {
my $this = shift;

$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $pubUrlSystemWeb = Foswiki::Func::getPubUrlPath() . '/System';
Expand All @@ -365,13 +363,13 @@ ACTUAL
<nop>
<nop>
<nop>
<table rules="rows" border="1" class="foswikiTable" id="table1">
<table rules="rows" border="1" class="foswikiTable" id="table$tableCount">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=1;up=1#sorted_table" rel="nofollow">Size</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
<th class="foswikiTableCol3 foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=1;up=0#sorted_table" rel="nofollow">Span date</a> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2 foswikiSortedAscendingCol foswikiSortedCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=$tableCount;up=1#sorted_table" rel="nofollow">Size</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
<th class="foswikiTableCol3 foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=$tableCount;up=0#sorted_table" rel="nofollow">Span date</a> </th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -419,7 +417,7 @@ Test sorting of Date column with HTML tags before the date

sub test_sort_dateWithHtml {
my $this = shift;

$tableCount++;
my $cgi = $this->{request};
my $url = $cgi->url( -absolute => 1 );
my $pubUrlSystemWeb = Foswiki::Func::getPubUrlPath() . '/System';
Expand All @@ -442,13 +440,13 @@ ACTUAL
<nop>
<nop>
<nop>
<table rules="rows" border="1" class="foswikiTable" id="table1">
<table rules="rows" border="1" class="foswikiTable" id="table$tableCount">
<thead>
<tr class="foswikiTableOdd foswikiTableRowdataBgSorted0 foswikiTableRowdataBg0">
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=1;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=1;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=1;up=0#sorted_table" rel="nofollow">Size</a> </th>
<th class="foswikiTableCol3 foswikiSortedAscendingCol foswikiSortedCol foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=1;up=1#sorted_table" rel="nofollow">Span date</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
<th class="foswikiTableCol0 foswikiFirstCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=0;table=$tableCount;up=0#sorted_table" rel="nofollow">Title</a> </th>
<th class="foswikiTableCol1"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=1;table=$tableCount;up=0#sorted_table" rel="nofollow">Date</a> </th>
<th class="foswikiTableCol2"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=2;table=$tableCount;up=0#sorted_table" rel="nofollow">Size</a> </th>
<th class="foswikiTableCol3 foswikiSortedAscendingCol foswikiSortedCol foswikiLastCol"> <a title="Sort by this column" href="$url/$TEST_WEB_NAME/TestTopicTableFormatting?sortcol=3;table=$tableCount;up=1#sorted_table" rel="nofollow">Span date</a><span class="tableSortIcon tableSortUp"><img width="11" height="13" border="0" title="Sorted ascending" src="$pubUrlSystemWeb/DocumentGraphics/tablesortup.gif" alt="Sorted ascending"/></span> </th>
</tr>
</thead>
<tbody>
Expand Down

0 comments on commit 7861445

Please sign in to comment.