MojoMojo
view release on metacpan or search on metacpan
t/formatter_all_markdown.t view on Meta::CPAN
#!/usr/bin/env perl
# Comprehensive/chained test of formatters, with the main formatter set to MultiMarkdown
use strict;
use warnings;
use Test::More tests => 27;
use HTTP::Request::Common;
use Test::Differences;
my $original_formatter; # used to save/restore the existing formatter set up in mojomojo.db
my $c; # the Catalyst object of this live server
my $test; # test description
my $content; # the markup content that is being rendered
my $got; # the rendered result
my $expected; # the expected rendered result
BEGIN {
$ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
use_ok 'MojoMojo::Formatter::Markdown';
use_ok 'Catalyst::Test', 'MojoMojo';
}
END {
ok( $c->pref( main_formatter => $original_formatter ),
'restore original formatter' );
done_testing;
}
( undef, $c ) = ctx_request('/');
ok( $original_formatter = $c->pref('main_formatter'),
'save original formatter' );
ok( $c->pref( main_formatter => 'MojoMojo::Formatter::Markdown' ),
'set preferred formatter to Markdown' );
#-------------------------------------------------------------------------------
$test = "empty body";
$content = '';
$got = get( POST '/.jsrpc/render', [ content => $content ] );
is( $got, 'Please type something', $test );
#-------------------------------------------------------------------------------
$test = 'headings';
$content = <<'MARKDOWN';
# Heading 1
paragraph
## Heading 2
MARKDOWN
$got = get( POST '/.jsrpc/render', [ content => $content ] );
eq_or_diff( $got, <<'HTML', $test );
<h1>Heading 1</h1>
<p>paragraph</p>
<h2>Heading 2</h2>
HTML
#-------------------------------------------------------------------------------
$test = 'direct <http://url.com> hyperlinks';
$content = <<'MARKDOWN';
This should be linked: <http://mojomojo.org>.
MARKDOWN
$got = get( POST '/.jsrpc/render', [ content => $content ] );
eq_or_diff( $got, <<'HTML', $test );
<p>This should be linked: <a href="http://mojomojo.org">http://mojomojo.org</a>.</p>
( run in 0.860 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )