Skip to content

Commit

Permalink
Item9576: update unit test
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@8925 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Sep 6, 2010
1 parent 8d5fb79 commit c0dfa25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions TwistyPlugin/data/System/TwistyPlugin.txt
Expand Up @@ -145,7 +145,7 @@ my twisty content
%GREEN% my twisty content %ENDCOLOR%
%ENDTWISTY%

*NOTE:* Twisty ids are generated automatically. If you need control over exactly _which_ Twisty should be remembered, add the parameter =id=:
*NOTE:* Twisty ids are generated automatically. If you need control over exactly _which_ Twisty should be remembered, add the parameter =id=.

<verbatim class="tml">
%TWISTY{
Expand All @@ -158,7 +158,7 @@ my customer list
%ENDTWISTY%
</verbatim>

Note that =id= sets a sitewide cookie. To create a unique id, add topic or web macros:
Note that =id= sets a site wide cookie. To create a unique id, add topic or web macros:
<verbatim class="tml">
id="%WEB%_%TOPIC%_currentCustomerList"
</verbatim>
Expand Down
7 changes: 7 additions & 0 deletions TwistyPlugin/lib/Foswiki/Plugins/TwistyPlugin.pm
Expand Up @@ -177,13 +177,20 @@ sub _TWISTYBUTTON {
_wrapInButtonHtml( $btn, $mode ) );
}

=pod
If no ID is passed, creates a new unique id based on web and topic. Adds a random number for cases the twisty is loaded through AJAX.
=cut

sub _TWISTY {
my ( $session, $params, $theTopic, $theWeb ) = @_;

_addHeader();
my $id = $params->{'id'};
if ( !defined $id || $id eq '' ) {
$params->{'id'} = _createId( $params->{'id'}, $theWeb, $theTopic );
# randomize this id in case the twisty is loaded through AJAX
$params->{'id'} .= int( rand(10000) ) + 1;
}
return _TWISTYBUTTON( $session, $params, $theTopic, $theWeb )
Expand Down
2 changes: 1 addition & 1 deletion TwistyPlugin/test/unit/TwistyPlugin/TwistyPluginTests.pm
Expand Up @@ -101,7 +101,7 @@ sub test_TWISTY_mode_default_with_id {
SOURCE

my $expected = <<'EXPECTED';
<div class="twistyPlugin foswikiMakeVisibleBlock"><span id="myid1show" class="twistyTrigger foswikiUnvisited twistyHidden twistyInited"><a href="#" class=""><span class="foswikiLinkLabel foswikiUnvisited">More...</span></a></span><span id="myid1hide" class="twistyTrigger foswikiUnvisited twistyHidden twistyInited"><a href="#" class=""><span class="foswikiLinkLabel foswikiUnvisited">Close</span></a></span></div><div class="twistyPlugin"><div id="myid1toggle" class="twistyContent foswikiMakeHidden twistyInited">content</div></div>
<div class="twistyPlugin foswikiMakeVisibleBlock"><span id="myidshow" class="twistyTrigger foswikiUnvisited twistyHidden twistyInited"><a href="#" class=""><span class="foswikiLinkLabel foswikiUnvisited">More...</span></a></span><span id="myidhide" class="twistyTrigger foswikiUnvisited twistyHidden twistyInited"><a href="#" class=""><span class="foswikiLinkLabel foswikiUnvisited">Close</span></a></span></div><div class="twistyPlugin"><div id="myidtoggle" class="twistyContent foswikiMakeHidden twistyInited">content</div></div>
EXPECTED

$this->do_test( $expected, $source );
Expand Down

0 comments on commit c0dfa25

Please sign in to comment.