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" ) {
102
# Test with munged URLs.
103
$formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1,
105
$html = $formatter->format($wikitext, $wiki);
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" );
116
like( $html, qr|[^ ]title with leading whitespace|,
117
"...and don't show leading whitespace" );
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" );
124
# Test with unmunged URLs.
125
$formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1 );
126
$html = $formatter->format($wikitext, $wiki);
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" );
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" );
90
eval { require Test::MockObject; };
96
skip "Can't find Test::MockObject", 11 unless $have_mockobject;
98
my $wiki = Test::MockObject->new;
99
$wiki->mock( "node_exists",
101
my ($self, $node) = @_;
102
if ( $node eq "Extended Link"
103
or $node eq "Extended Link Two"
104
or $node eq "Another Link" ) {
112
# Test with munged URLs.
113
$formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1,
115
$html = $formatter->format($wikitext, $wiki);
118
skip "Broken by Text::WikiFormat bug http://rt.cpan.org/Public/Bug/Display.html?id=34402", 5;
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" );
134
# Test with unmunged URLs.
135
$formatter = Wiki::Toolkit::Formatter::UseMod->new( extended_links => 1 );
136
$html = $formatter->format($wikitext, $wiki);
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" );
143
qr|<a href="wiki.pl\?Extended%20Link">titled extended link</a>|,
144
"...and titles work" );
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" );
154
[ "Extended Link", "Extended Link", "Extended Link",
155
"Extended Link Two", "Another Link" ],
156
"...and gets the right order" );