MojoMojo

 view release on metacpan or  search on metacpan

t/formatter_syntax_highlight.t  view on Meta::CPAN

#!/usr/bin/env perl
use strict;
use warnings;
use MojoMojo::Formatter::SyntaxHighlight;
use HTTP::Request::Common;
use Test::More;
use Test::Differences;
my ( $content, $got, $expected, $test, $c, $original_formatter );

BEGIN {
    plan skip_all => 'Requirements not installed for the Syntax Highlighter formatter'
        unless MojoMojo::Formatter::SyntaxHighlight->module_loaded;
    plan tests => 15;
    use_ok('MojoMojo::Formatter::Textile');
    $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
    use_ok( 'Catalyst::Test', 'MojoMojo' );
}

END {
    ok( $c->pref( main_formatter => $original_formatter ),
        'restore original formatter' );
}

( undef, $c ) = ctx_request('/');
ok( $original_formatter = $c->pref('main_formatter'),
    'save original formatter' );

ok( $c->pref( main_formatter => 'MojoMojo::Formatter::Textile' ),
    'set preferred formatter to Textile' );

$test .= 'single word run through all formatters';
$content = 'palabra';

# We expect to get the word back surrounded with <p> tag and \n added.
$expected = '<p>' . $content . '</p>
';
$got = get( POST '/.jsrpc/render', [ content => $content ] );
is( $got, $expected, $test );

$test = 'single word run through all formatters with textile off';
$content = '==palabra==';

# We expect to get the word back surrounded with only \n added.
$expected = 'palabra
';
$got = get( POST '/.jsrpc/render', [ content => $content ] );
is( $got, $expected, $test );

$test    = 'two words run through all formatters';
$content = 'dues palabres';

# We expect to get the two words back surrounded with <p> tag and \n added.
$expected = '<p>' . $content . '</p>
';
$got = get( POST '/.jsrpc/render', [ content => $content ] );
is( $got, $expected, $test );

{
    $test = 'Single <code>';

    $content = <<HTML;
<pre lang="HTML">
<code>
Ha en god dag
</code>
</pre>
HTML



( run in 0.906 second using v1.01-cache-2.11-cpan-437f7b0c052 )