#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 32; use HTTP::Request::Common; use Test::Differences; use FindBin '$Bin'; use lib "$Bin/../lib"; use Data::Dumper; 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::Textile') and note('Comprehensive/chained test of formatters, with the main formatter set to Textile'); use_ok('Catalyst::Test', 'MojoMojo'); } END { ok($c->pref(main_formatter => $original_formatter), 'restore original formatter'); } (undef, $c) = ctx_request('/'); #warn Dumper $c->config; ok($original_formatter = $c->pref('main_formatter'), 'save original formatter'); ok($c->pref(main_formatter => 'MojoMojo::Formatter::Textile'), 'set preferred formatter to Textile'); $content = ''; $got = get(POST '/.jsrpc/render', [ content => $content ]); is($got, 'Please type something', 'empty body'); #---------------------------------------------------------------------------- $test = 'headings'; $content = <<'TEXTILE'; h1. Welcome to MojoMojo! This is your front page. Create a [[New Page]] or edit this one through the edit link at the bottom. h2. Need some assistance? Check out our [[Help]] section. TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, <<'HTML', $test);

Welcome to MojoMojo!

This is your front page. Create
a New Page? or edit this one
through the edit link at the bottom.

Need some assistance?

Check out our Help section.

HTML #---------------------------------------------------------------------------- $test = 'syntax highlight, Perl'; $content = <<'TEXTILE';
    say "Hola Cabrón";
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML';
    say "Hola Cabrón";
HTML } else { $expected = <<'HTML';
    say "Hola Cabrón";
HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #---------------------------------------------------------------------------- $test = 'Test > in
 section.';

$content = <<'TEXTILE';
if (1 > 2) {
  print "test";
}
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML';
if (1 > 2) {
  print "test";
}
HTML } else { $expected = <<'HTML';
if (1 > 2) {
  print "test";
}
HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #---------------------------------------------------------------------------- $test = 'Only a
 section - no attribute';
$content = <<'TEXTILE';
Hopen, Norway
TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $content, $test); #$TODO = 'something before a pre adds defang_lang attribute to pre'; # This test is passing now (November 15, 2009, but requires some extra line returns. # in order to get input and output matched up $test = 'pre tag - no attribute and some text before pre'; $content = <<'TEXTILE'; Jeg har familie i
Hopen, Norway
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML';

Jeg har familie i

Hopen, Norway
HTML } else { $expected = <<'HTML';

Jeg har familie i

Hopen, Norway
HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); $test = 'pre tag - no attribute and some text after pre'; $content = <<'HTML';
Hopen, Norway
er et sted langt mot nord. HTML $expected = '
Hopen, Norway

er et sted langt mot nord.

'; $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #---------------------------------------------------------------------------- $test = "HTML tags inside
 sections should be preserved. Also test for GIGO: a stray '<'.";

$content = <<'TEXTILE';

if (1 < 2) {
  print "pre section & no lang specified";
}

TEXTILE $expected = <<'HTML';

if (1  2) {
  print "pre section & no lang specified";
}

HTML $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #---------------------------------------------------------------------------- $test = 'Is
preserved?'; # NOTE: Textile turns \n in to
so you don't need or want to do # blab #
blah because you'll end up with: # blab #

blah $content = <<'TEXTILE'; Roses are red
Violets are blue TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, <<'HTML', $test);

Roses are red
Violets are blue

HTML # This test is asking for a bit much perhaps. Use
 
instead. #---------------------------------------------------------------------------- $test = ' behave like normal wrt to - Use textile escape =='; $content = <<'TEXTILE'; ==alguna cosa == TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, <<'HTML', $test); alguna cosa HTML # Check that @ transforms to #---------------------------------------------------------------------------- $test = '@word@ behavior'; $content = <<'TEXTILE'; @mot@ TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, <<'HTML', $test);

mot

HTML #---------------------------------------------------------------------------- $test = 'blockquotes'; #---------------------------------------------------------------------------- $content = <<'TEXTILE'; Below is a blockquote: bq. quoted text A quote is above. TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, <<'HTML', $test);

Below is a blockquote:

quoted text

A quote is above.

HTML #---------------------------------------------------------------------------- $test = 'Syntax highlight, Perl - handle "#" at start of line as comment, not heading'; # TODO: This test demonstrates that Syntax Highlight is adding an empty span. # Investigate further and clean it up. $content = <<'TEXTILE';
# comment
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML'
# comment
HTML } else { $expected = <<'HTML'
# comment
HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #---------------------------------------------------------------------------- $test = 'Simple html table tags. Use textile escape =='; # NOTE: The opening escape string '==' turns into a \n when textile # is applied. colgroup was moved as it confused Defang. $content = <<'TEXTILE'; ==
Vegetable
Mr Potato
== TEXTILE $expected = <<'HTML';
Vegetable
Mr Potato
HTML # We expect textile to leave this table as is, EXCPEPT for the escape lines (==). $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #---------------------------------------------------------------------------- $test = 'Maintain complete set of html table tags. Use textile escape =='; # NOTE: The opening escape string '==' turns into a \n when textile # is applied. colgroup was removed as it confused Defang. $content = <<'TEXTILE'; ==
Vegetable Price List
Vegetable Cost per kilo
Lettuce $1
Silver carrots $10.50
Golden turnips $108.00
== TEXTILE $expected = <<'HTML';
Vegetable Price List
Vegetable Cost per kilo
Lettuce $1
Silver carrots $10.50
Golden turnips $108.00
HTML # We expect textile to leave this table as is, EXCPEPT for the escape lines (==). $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #------------------------------------------------------------------------------- $test = 'POD while Textile is the main formatter'; $content = <<'TEXTILE'; {{pod}} =head1 NAME Some POD here =cut {{end}} TEXTILE $got = get(POST '/.jsrpc/render', [ content => $content ]); like($got, qr'

's, "POD: there is an h1 NAME"); #------------------------------------------------------------------------------- $test = 'Syntax highlight, SQL'; $content = < select * from foo

SQL if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML'
select * from foo
HTML } else { $expected = <<'HTML'
select * from foo
HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #------------------------------------------------------------------------------- $test = 'Syntax highlight, XML'; $content = < some text here
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML';
<foo>
some text here
</foo>
HTML } else { $expected = <<'HTML';

some text here

HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #------------------------------------------------------------------------------- $test = 'Syntax highlight, HTML'; $content = <
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML';
<textarea>
some text here
</textarea>
HTML } else { $expected = <<'HTML';

HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #------------------------------------------------------------------------------- TODO: { local $TODO = "Textile processes '' tags specially; even '<code>' gets converted to ''"; $test = ' tag in
 run through the JSRPC renderer';

    $content = <

some text here

TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML'
<code>
some text here
</code>
HTML } else { $expected = <<'HTML'

some text here

HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); #------------------------------------------------------------------------------- $test = 'For comparison, "" and "" strings in
 run through the JSRPC renderer';

    $content = <
"Monotype: use .";
"Source code: .";
TEXTILE if (MojoMojo::Formatter::SyntaxHighlight->module_loaded) { $expected = <<'HTML'
"Monotype: use <tt>.";
"Source code: <code>.";
HTML } else { $expected = <<'HTML'
"Monotype: use .";
"Source code: .";
HTML } $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); } #------------------------------------------------------------------------------- $test = 'img src http not allowed'; $content = <<'HTML'; HTML $expected = '

'; $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); $test = 'img src https not allowed'; $content = <<'HTML'; HTML $expected = '

'; $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); $test = 'img src with bypass protocol not allowed'; $content = <<'HTML'; HTML $expected = '

'; $got = get(POST '/.jsrpc/render', [ content => $content ]); eq_or_diff($got, $expected, $test); $test = 'remote img src allowed in .conf'; $content = <<'HTML';

HTML $expected = $content; $got = get(POST '/.jsrpc/render', [ content => $content ]); is($got, $expected, $test); $test = 'relative local img src'; $content = ''; $expected = '

' . $content . '

'; $got = get(POST '/.jsrpc/render', [ content => $content ]); is($got, $expected, $test); $test = 'code'; $content = q(is some code, "isn't it".); $expected = '

' . $content . '

'; $got = get(POST '/.jsrpc/render', [ content => $content ]); is($got, $expected, $test);