Permalink
Browse files

YouTube formatter correctly outputs '&'s in links now. Added test aga…

…inst Defang interference.


http://htmlhelp.com/tools/validator/problems.html#amp explains why ampersands must be encoded in HTML element attributes.
  • Loading branch information...
1 parent 79bd333 commit 650e034ee524b76000f818ba41e1508c1539d692 @dandv dandv committed Dec 1, 2009
Showing with 34 additions and 16 deletions.
  1. +1 −1 lib/MojoMojo/Formatter/YouTube.pm
  2. 0 root/base/page/search_inline.tt
  3. +33 −15 t/formatter_youtube.t
@@ -75,7 +75,7 @@ sub process {
if ( ($c->action->reverse eq 'pageadmin/edit') || ($c->action->reverse eq 'jsrpc/render') ){
$line =~ s!$re!<div style='width: 425px;height: 344px; border: 1px black dotted;'>$youtube<br /><a href="$url">$url</a></div>!;
} else {
- $line =~ s!$re!<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/$video_id&hl=$lang"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$video_id&hl=$lang" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>!;
+ $line =~ s!$re!<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/$video_id&amp;hl=$lang"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$video_id&amp;hl=$lang" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>!;
}
return $line;
}
View
0 root/base/page/search_inline.tt 100755 → 100644
No changes.
View
@@ -1,38 +1,56 @@
#!/usr/bin/env perl
use strict;
use warnings;
-use MojoMojo::Formatter::YouTube;
-use Test::More tests => 5;
+use Test::More tests => 8;
use lib 't/lib';
+use HTTP::Request::Common;
use FakeCatalystObject;
-my $content;
+BEGIN {
+ $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
+ use_ok 'MojoMojo::Formatter::YouTube';
+ use_ok 'Catalyst::Test', 'MojoMojo';
+}
+
+my ($content, $got, $expected);
my $fake_c = FakeCatalystObject->new;
$content = " youtube http://www.youtube.com/abc";
MojoMojo::Formatter::YouTube->format_content(\$content, $fake_c, undef);
-#warn("Content is $content");
-is($content, " youtube http://www.youtube.com/abc\n", "no youtube formatter line");
+is($content, " youtube http://www.youtube.com/abc\n", "formatter directly / not a {{YouTube ...}} tag");
$fake_c->set_reverse('pageadmin/edit');
$content = "{{youtube http://www.youtube.com/v=abcABC0}}\n";
MojoMojo::Formatter::YouTube->format_content(\$content, $fake_c, undef);
-#warn("Content is $content");
-is($content, qq(<div style='width: 425px;height: 344px; border: 1px black dotted;'>Faking localization... YouTube Video ...fake complete.<br /><a href="http://www.youtube.com/v=abcABC0">http://www.youtube.com/v=abcABC0</a></div>\n));
+is( $content,
+ qq(<div style='width: 425px;height: 344px; border: 1px black dotted;'>Faking localization... YouTube Video ...fake complete.<br /><a href="http://www.youtube.com/v=abcABC0">http://www.youtube.com/v=abcABC0</a></div>\n),
+ 'formatter directly / preview / valid tag'
+);
$fake_c->set_reverse('jsrpc/render');
$content = "{{youtube http://www.youtube.com/v=abcABC0}} xx\n";
MojoMojo::Formatter::YouTube->format_content(\$content, $fake_c, undef);
-#warn("Content is $content");
-is($content, qq(<div style='width: 425px;height: 344px; border: 1px black dotted;'>Faking localization... YouTube Video ...fake complete.<br /><a href="http://www.youtube.com/v=abcABC0">http://www.youtube.com/v=abcABC0</a></div> xx\n));
+is( $content,
+ qq(<div style='width: 425px;height: 344px; border: 1px black dotted;'>Faking localization... YouTube Video ...fake complete.<br /><a href="http://www.youtube.com/v=abcABC0">http://www.youtube.com/v=abcABC0</a></div> xx\n),
+ 'formatter directly / preview / valid tag followed by text'
+);
$content = "{{youtube http://wwwwwwww.youtube.com/abc}}";
MojoMojo::Formatter::YouTube->format_content(\$content, $fake_c, undef);
-#warn("Content is $content");
-is($content, "Faking localization... YouTube Video ...fake complete.: http://wwwwwwww.youtube.com/abc Faking localization... is not a valid link to youtube video ...fake complete.\n", "no youtube link");
+is( $content,
+ "Faking localization... YouTube Video ...fake complete.: http://wwwwwwww.youtube.com/abc Faking localization... is not a valid link to youtube video ...fake complete.\n",
+ 'formatter directly / invalid YouTube link'
+);
$fake_c->set_reverse('');
-$content = "{{youtube http://www.youtube.com/watch?v=ABC_abc_09}}";
-MojoMojo::Formatter::YouTube->format_content(\$content, $fake_c, undef);
-#warn("Content is $content");
-is($content, qq(<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/ABC_abc_09&hl=en"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ABC_abc_09&hl=en" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>\n));
+$got = $content = "{{youtube http://www.youtube.com/watch?v=ABC_abc_09}}";
+$expected = qq(<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/ABC_abc_09&amp;hl=en"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ABC_abc_09&amp;hl=en" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>);
+MojoMojo::Formatter::YouTube->format_content(\$got, $fake_c, undef);
+is( $got, "$expected\n", 'formatter directly / final page rendering' );
+# tests are closer to reality if they call the JSRPC renderer, so that
+# the entire formatter chain gets exercised, as in actual wiki usage
+TODO: {
+ local $TODO = "Defang interferes with the YouTube formatter - see http://n2.nabble.com/Defang-issues-td4078508.html";
+ $got = get( POST '/.jsrpc/render', [ content => $content ] );
+ is( $got, "<p>$expected</p>\n", 'full formatter chain / final page rendering' );
+}

0 comments on commit 650e034

Please sign in to comment.