Changeset 401

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

Made Test::MockObject? optional.

Location:
wiki-toolkit-formatter-usemod/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • wiki-toolkit-formatter-usemod/trunk/Changes

    r325 r401  
     10.21 
     2        Made Test::MockObject optional. 
     3 
    140.20    6 June 2006 
    25        Update copyright notice. 
  • wiki-toolkit-formatter-usemod/trunk/Makefile.PL

    r239 r401  
    66                                 'HTML::PullParser' => 0, 
    77                                 'Test::More'       => 0, 
    8                                  'Test::MockObject' => '0.07', #earlier no mock 
    98                                 'URI::Escape'      => 0, 
    109                                 'URI::Find::Delimited' => '0.02'#earlier buggy 
  • wiki-toolkit-formatter-usemod/trunk/t/links.t

    r239 r401  
    11use strict; 
    2 use Test::MockObject; 
    3 use Test::More tests => 4; 
     2use Test::More; 
     3 
     4eval { require Test::MockObject; }; 
     5if ( $@ ) { 
     6    plan skip_all => "Can't find Test::MockObject"; 
     7} 
     8 
     9plan tests => 4; 
    410 
    511my $wikitext = <<WIKITEXT; 
  • wiki-toolkit-formatter-usemod/trunk/t/node-suffix.t

    r239 r401  
    11use strict; 
    2 use Test::More tests => 2; 
     2use Test::More; 
    33use Wiki::Toolkit::Formatter::UseMod; 
    4 use Test::MockObject; 
     4 
     5eval { require Test::MockObject; }; 
     6if ( $@ ) { 
     7    plan skip_all => "Can't find Test::MockObject"; 
     8} 
     9 
     10plan tests => 2; 
    511 
    612my $wikitext = <<WIKITEXT; 
  • 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}