source: cgi-wiki-formatter-usemod/trunk/t/usemod.t @ 111

Last change on this file since 111 was 111, checked in by kake, 18 years ago

0.06 1 August 2003

Changes for compatibility with Text::WikiFormat? 0.7 - we now have

nested lists!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1use strict;
2local $^W = 1;
3
4use Test::More tests => 25;
5use Test::MockObject;
6
7use_ok( "CGI::Wiki::Formatter::UseMod" );
8
9print "#\n#### Testing default configuration\n#\n";
10my $wikitext = <<WIKITEXT;
11
12==== Welcome ====
13
14This is some WikiText.
15
16: This should be a
17: definition list with data
18: but no terms
19
20==== LinkInAHeader ====
21
22 pig
23 pig
24
25==== Header with an = in ====
26
27 spaces  are significant
28
29Another WikiWord.
30
31WIKITEXT
32
33my $formatter = CGI::Wiki::Formatter::UseMod->new;
34isa_ok( $formatter, "CGI::Wiki::Formatter::UseMod" );
35my $html = $formatter->format($wikitext);
36
37like( $html, qr|<a href="wiki.pl\?WikiText">WikiText</a>|,
38      "WikiWords made into links" );
39like( $html, qr|<h4>Welcome</h4>|, "headings work" );
40like( $html,
41      qr|<h4><a href="wiki.pl\?LinkInAHeader">LinkInAHeader</a></h4>|,
42      "...links work in headers" );
43like( $html, qr|<h4>Header with an = in</h4>|, "...headers may contain =" );
44like( $html, qr|<dl>\s*<dt><dd>This should be a\s*<dt><dd>definition list with data\s*<dt><dd>but no terms\s*</dl>|,
45      "leading : made into <dl>" );
46SKIP: {
47        skip "TODO", 1;
48        like( $html, qr|<pre>\n pig\n pig\n</pre>|,
49              "leading space makes <pre>" );
50      }
51
52my @links = $formatter->find_internal_links($wikitext);
53is_deeply( [ sort @links ], [ "LinkInAHeader", "WikiText", "WikiWord" ],
54           "find_internal_links seems to work" );
55print "# Found internal links: " . join(", ", sort @links) . "\n";
56
57print "#\n#### Testing HTML escaping\n#\n";
58$wikitext = <<WIKITEXT;
59
60&pound;
61
62<i>
63<strike>
64
65WIKITEXT
66
67$formatter = CGI::Wiki::Formatter::UseMod->new;
68$html = $formatter->format($wikitext);
69like( $html, qr|&pound;|, "Entities preserved by default." );
70unlike( $html, qr|<strike>|, "HTML tags escaped by default" );
71
72$formatter = CGI::Wiki::Formatter::UseMod->new( allowed_tags => [ "strike" ] );
73$html = $formatter->format($wikitext);
74like( $html, qr|<strike>|, "...but not when we allow them" );
75unlike( $html, qr|<i>|, "...and ones we don't explicitly allow are escaped" );
76like( $html, qr|&pound;|, "Entities still preserved." );
77
78print "#\n#### Testing extended links\n#\n";
79$wikitext = <<WIKITEXT;
80
81This is an [[Extended Link]].
82
83This is a lower-case [[extended link]].
84
85This is a [[Extended Link|titled extended link]].
86
87This is a [[Extended Link Two | title with leading whitespace]].
88
89This is [[Another Link|another titled link]].
90
91WIKITEXT
92
93my $wiki = Test::MockObject->new;
94$wiki->mock( "node_exists",
95            sub { my ($self, $node) = @_;
96                  if ( $node eq "Extended Link" or $node eq "Extended Link Two"
97                       or $node eq "Another Link" ) {
98                      return 1;
99                  } else {
100                      return 0;
101                  }
102                }
103);
104
105# Test with munged URLs.
106$formatter = CGI::Wiki::Formatter::UseMod->new( extended_links => 1,
107                                                munge_urls     => 1 );
108$html = $formatter->format($wikitext, $wiki);
109
110like( $html, qr|<a href="wiki.pl\?Extended_Link">Extended Link</a>|,
111      "extended links work" );
112like( $html, qr|<a href="wiki.pl\?Extended_Link">extended link</a>|,
113      "...and are forced ucfirst" );
114like( $html, qr|<a href="wiki.pl\?Extended_Link">titled extended link</a>|,
115      "...and titles work" );
116like( $html, qr|[^ ]title with leading whitespace|,
117      "...and don't show leading whitespace" );
118like( $html, qr|<a href="wiki.pl\?Extended_Link_Two">|,
119      "...and titled nodes with trailing whitespace are munged correctly before formatting" );
120
121# Test with unmunged URLs.
122$formatter = CGI::Wiki::Formatter::UseMod->new( extended_links => 1 );
123$html = $formatter->format($wikitext, $wiki);
124
125like( $html, qr|<a href="wiki.pl\?Extended%20Link">Extended Link</a>|,
126      "extended links work with unmunged URLs" );
127like( $html, qr|<a href="wiki.pl\?Extended%20Link">extended link</a>|,
128      "...and are forced ucfirst" );
129like( $html, qr|<a href="wiki.pl\?Extended%20Link">titled extended link</a>|,
130      "...and titles work" );
131
132@links = $formatter->find_internal_links($wikitext);
133print "# Found links: " . join(", ", @links) . "\n";
134my %linkhash = map { $_ => 1 } @links;
135ok( ! defined $linkhash{"extended link"},
136    "find_internal_links respects ucfirst" );
137ok( ! defined $linkhash{"Extended Link "},
138    "...and drops trailing whitespace" );
139is_deeply( \@links, [ "Extended Link", "Extended Link", "Extended Link", "Extended Link Two", "Another Link" ], "...and gets the right order" );
Note: See TracBrowser for help on using the repository browser.