~ubuntu-branches/ubuntu/vivid/libwiki-toolkit-formatter-usemod-perl/vivid

« back to all changes in this revision

Viewing changes to t/usemod.t

  • Committer: Bazaar Package Importer
  • Author(s): Dominic Hargreaves
  • Date: 2008-05-05 16:32:42 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080505163242-2mhz2xh17hd0d7ap
Tags: 0.22-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
local $^W = 1;
3
3
 
4
4
use Test::More tests => 25;
5
 
use Test::MockObject;
6
5
 
7
6
use_ok( "Wiki::Toolkit::Formatter::UseMod" );
8
7
 
87
86
 
88
87
WIKITEXT
89
88
 
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
 
);
101
 
 
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);
106
 
 
107
 
TODO: {
108
 
    local $TODO = 'Broken by newer Text::WikiFormat changes, fix pending';
109
 
like( $html, qr|<a href="wiki.pl\?Extended_Link">Extended Link</a>|,
110
 
      "extended links work" );
111
 
like( $html, qr|<a href="wiki.pl\?Extended_Link">extended link</a>|,
112
 
      "...and are forced ucfirst" );
113
 
like( $html, qr|<a href="wiki.pl\?Extended_Link">titled extended link</a>|,
114
 
      "...and titles work" );
115
 
}
116
 
like( $html, qr|[^ ]title with leading whitespace|,
117
 
      "...and don't show leading whitespace" );
118
 
TODO: {
119
 
    local $TODO = 'Broken by newer Text::WikiFormat changes, fix pending';
120
 
like( $html, qr|<a href="wiki.pl\?Extended_Link_Two">|,
121
 
      "...and titled nodes with trailing whitespace are munged correctly before formatting" );
122
 
}
123
 
 
124
 
# Test with unmunged URLs.
125
 
$formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1 );
126
 
$html = $formatter->format($wikitext, $wiki);
127
 
 
128
 
like( $html, qr|<a href="wiki.pl\?Extended%20Link">Extended Link</a>|,
129
 
      "extended links work with unmunged URLs" );
130
 
like( $html, qr|<a href="wiki.pl\?Extended%20Link">extended link</a>|,
131
 
      "...and are forced ucfirst" );
132
 
like( $html, qr|<a href="wiki.pl\?Extended%20Link">titled extended link</a>|,
133
 
      "...and titles work" );
134
 
 
135
 
@links = $formatter->find_internal_links($wikitext);
136
 
print "# Found links: " . join(", ", @links) . "\n";
137
 
my %linkhash = map { $_ => 1 } @links;
138
 
ok( ! defined $linkhash{"extended link"},
139
 
    "find_internal_links respects ucfirst" );
140
 
ok( ! defined $linkhash{"Extended Link "},
141
 
    "...and drops trailing whitespace" );
142
 
is_deeply( \@links, [ "Extended Link", "Extended Link", "Extended Link", "Extended Link Two", "Another Link" ], "...and gets the right order" );
 
89
my $have_mockobject;
 
90
eval { require Test::MockObject; };
 
91
if ( !$@ ) {
 
92
    $have_mockobject = 1;
 
93
}
 
94
 
 
95
SKIP: {
 
96
    skip "Can't find Test::MockObject", 11 unless $have_mockobject;
 
97
 
 
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
    );
 
111
 
 
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);
 
116
 
 
117
    SKIP: {
 
118
        skip "Broken by Text::WikiFormat bug http://rt.cpan.org/Public/Bug/Display.html?id=34402", 5;
 
119
 
 
120
    like( $html, qr|<a href="wiki.pl\?Extended_Link">Extended Link</a>|,
 
121
          "extended links work" );
 
122
    like( $html, qr|<a href="wiki.pl\?Extended_Link">extended link</a>|,
 
123
          "...and are forced ucfirst" );
 
124
    like( $html, qr|<a href="wiki.pl\?Extended_Link">titled extended link</a>|,
 
125
          "...and titles work" );
 
126
    like( $html, qr|[^ ]title with leading whitespace|,
 
127
          "...and don't show leading whitespace" );
 
128
    like( $html, qr|<a href="wiki.pl\?Extended_Link_Two">|,
 
129
          "...and titled nodes with trailing whitespace are munged correctly "
 
130
          . "before formatting" );
 
131
    
 
132
    } # end SKIP
 
133
 
 
134
    # Test with unmunged URLs.
 
135
    $formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1 );
 
136
    $html = $formatter->format($wikitext, $wiki);
 
137
 
 
138
    like( $html, qr|<a href="wiki.pl\?Extended%20Link">Extended Link</a>|,
 
139
          "extended links work with unmunged URLs" );
 
140
    like( $html, qr|<a href="wiki.pl\?Extended%20Link">extended link</a>|,
 
141
          "...and are forced ucfirst" );
 
142
    like( $html,
 
143
          qr|<a href="wiki.pl\?Extended%20Link">titled extended link</a>|,
 
144
          "...and titles work" );
 
145
 
 
146
    @links = $formatter->find_internal_links($wikitext);
 
147
    print "# Found links: " . join(", ", @links) . "\n";
 
148
    my %linkhash = map { $_ => 1 } @links;
 
149
    ok( ! defined $linkhash{"extended link"},
 
150
        "find_internal_links respects ucfirst" );
 
151
    ok( ! defined $linkhash{"Extended Link "},
 
152
        "...and drops trailing whitespace" );
 
153
    is_deeply( \@links,
 
154
               [ "Extended Link", "Extended Link", "Extended Link",
 
155
                  "Extended Link Two", "Another Link" ],
 
156
               "...and gets the right order" );
 
157
}