Show
Ignore:
Timestamp:
04/11/08 20:29:15 (4 years ago)
Author:
kake
Message:

Made Test::MockObject? optional.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • wiki-toolkit-formatter-usemod/trunk/t/usemod.t

    r239 r401  
    33 
    44use Test::More tests => 25; 
    5 use Test::MockObject; 
    65 
    76use_ok( "Wiki::Toolkit::Formatter::UseMod" ); 
     
    8887WIKITEXT 
    8988 
    90 my $wiki = Test::MockObject->new; 
    91 $wiki->mock( "node_exists", 
    92             sub { my ($self, $node) = @_; 
    93                   if ( $node eq "Extended Link" or $node eq "Extended Link Two" 
    94                        or $node eq "Another Link" ) { 
    95                       return 1; 
    96                   } else { 
    97                       return 0; 
    98                   } 
    99                 } 
    100 ); 
     89my $have_mockobject; 
     90eval { require Test::MockObject; }; 
     91if ( !$@ ) { 
     92    $have_mockobject = 1; 
     93} 
    10194 
    102 # Test with munged URLs. 
    103 $formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1, 
    104                                                 munge_urls     => 1 ); 
    105 $html = $formatter->format($wikitext, $wiki); 
     95SKIP: { 
     96    skip "Can't find Test::MockObject", 11 unless $have_mockobject; 
    10697 
    107 like( $html, qr|<a href="wiki.pl\?Extended_Link">Extended Link</a>|, 
    108       "extended links work" ); 
    109 like( $html, qr|<a href="wiki.pl\?Extended_Link">extended link</a>|, 
    110       "...and are forced ucfirst" ); 
    111 like( $html, qr|<a href="wiki.pl\?Extended_Link">titled extended link</a>|, 
    112       "...and titles work" ); 
    113 like( $html, qr|[^ ]title with leading whitespace|, 
    114       "...and don't show leading whitespace" ); 
    115 like( $html, qr|<a href="wiki.pl\?Extended_Link_Two">|, 
    116       "...and titled nodes with trailing whitespace are munged correctly before formatting" ); 
     98    my $wiki = Test::MockObject->new; 
     99    $wiki->mock( "node_exists", 
     100                  sub { 
     101                        my ($self, $node) = @_; 
     102                        if ( $node eq "Extended Link" 
     103                             or $node eq "Extended Link Two" 
     104                             or $node eq "Another Link" ) { 
     105                            return 1; 
     106                        } else { 
     107                            return 0; 
     108                        } 
     109                      } 
     110    ); 
    117111 
    118 # Test with unmunged URLs. 
    119 $formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1 ); 
    120 $html = $formatter->format($wikitext, $wiki); 
     112    # Test with munged URLs. 
     113    $formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1, 
     114                                                        munge_urls     => 1 ); 
     115    $html = $formatter->format($wikitext, $wiki); 
    121116 
    122 like( $html, qr|<a href="wiki.pl\?Extended%20Link">Extended Link</a>|, 
    123       "extended links work with unmunged URLs" ); 
    124 like( $html, qr|<a href="wiki.pl\?Extended%20Link">extended link</a>|, 
    125       "...and are forced ucfirst" ); 
    126 like( $html, qr|<a href="wiki.pl\?Extended%20Link">titled extended link</a>|, 
    127       "...and titles work" ); 
     117    like( $html, qr|<a href="wiki.pl\?Extended_Link">Extended Link</a>|, 
     118          "extended links work" ); 
     119    like( $html, qr|<a href="wiki.pl\?Extended_Link">extended link</a>|, 
     120          "...and are forced ucfirst" ); 
     121    like( $html, qr|<a href="wiki.pl\?Extended_Link">titled extended link</a>|, 
     122          "...and titles work" ); 
     123    like( $html, qr|[^ ]title with leading whitespace|, 
     124          "...and don't show leading whitespace" ); 
     125    like( $html, qr|<a href="wiki.pl\?Extended_Link_Two">|, 
     126          "...and titled nodes with trailing whitespace are munged correctly " 
     127          . "before formatting" ); 
    128128 
    129 @links = $formatter->find_internal_links($wikitext); 
    130 print "# Found links: " . join(", ", @links) . "\n"; 
    131 my %linkhash = map { $_ => 1 } @links; 
    132 ok( ! defined $linkhash{"extended link"}, 
    133     "find_internal_links respects ucfirst" ); 
    134 ok( ! defined $linkhash{"Extended Link "}, 
    135     "...and drops trailing whitespace" ); 
    136 is_deeply( \@links, [ "Extended Link", "Extended Link", "Extended Link", "Extended Link Two", "Another Link" ], "...and gets the right order" ); 
     129    # Test with unmunged URLs. 
     130    $formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1 ); 
     131    $html = $formatter->format($wikitext, $wiki); 
     132 
     133    like( $html, qr|<a href="wiki.pl\?Extended%20Link">Extended Link</a>|, 
     134          "extended links work with unmunged URLs" ); 
     135    like( $html, qr|<a href="wiki.pl\?Extended%20Link">extended link</a>|, 
     136          "...and are forced ucfirst" ); 
     137    like( $html, 
     138          qr|<a href="wiki.pl\?Extended%20Link">titled extended link</a>|, 
     139          "...and titles work" ); 
     140 
     141    @links = $formatter->find_internal_links($wikitext); 
     142    print "# Found links: " . join(", ", @links) . "\n"; 
     143    my %linkhash = map { $_ => 1 } @links; 
     144    ok( ! defined $linkhash{"extended link"}, 
     145        "find_internal_links respects ucfirst" ); 
     146    ok( ! defined $linkhash{"Extended Link "}, 
     147        "...and drops trailing whitespace" ); 
     148    is_deeply( \@links, 
     149               [ "Extended Link", "Extended Link", "Extended Link", 
     150                  "Extended Link Two", "Another Link" ], 
     151               "...and gets the right order" ); 
     152}