Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 56 lines (49 sloc) 3.002 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 8;
use lib 't/lib';
use HTTP::Request::Common;
use FakeCatalystObject;

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);
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);
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);
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);
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('');
$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' );
}
Something went wrong with that request. Please try again.