1#!/usr/bin/env perl
2# Unicode tests: Unicode text in page content, wiki links, tags etc.
3use strict;
4use warnings;
5use Test::More tests => 9;
6use HTTP::Request::Common;
7use Test::Differences;
8use utf8;
9
10my $original_formatter;    # current formatter set up in mojomojo.db
11my $c;                     # the Catalyst object of this live server
12my $test;                  # test description
13my $content;               # source markup
14my $body;                  # # the MojoMojo page body as fetched by get()
15my $mech = Test::WWW::Mechanize::Catalyst->new;
16
17BEGIN {
18    $ENV{CATALYST_CONFIG} = 't/var/mojomojo.yml';
19    use_ok 'MojoMojo::Formatter::Markdown';
20
21    use_ok 'Catalyst::Test', 'MojoMojo';
22    # We should only use Catalyst::Test here, but we can't until it fixes this Unicode-related bug:
23    # http://dev.catalyst.perl.org/wiki/bugs/Catalyst_Test_get_does_not_encode_the_content
24    use_ok 'Test::WWW::Mechanize::Catalyst', 'MojoMojo';
25}
26
27END {
28    ok( $c->pref( main_formatter => $original_formatter ),
29        'restore original formatter' );
30}
31
32# Prepare the test environment by setting the primary formatter to Markdown
33( undef, $c ) = ctx_request('/');
34ok( $original_formatter = $c->pref('main_formatter'),
35    'save original formatter' );
36
37ok( $c->pref( main_formatter => 'MojoMojo::Formatter::Markdown' ),
38    'set preferred formatter to Markdown' );
39
40#-------------------------------------------------------------------------------
41$test = "basic Unicode: page content";
42$content = 'ებრაული ენა (עברית, ივრით), განეკუთვნება სემიტურ ენათა ქანაანურ ჯგუფს.';
43$mech->post_ok('/.jsrpc/render', { content => $content });
44$mech->content_is('<p>ებრაული ენა (עברית, ივრით), განეკუთვნება სემიტურ ენათა ქანაანურ ჯგუფს.</p>' . "\n", $test);
45
46
47#-------------------------------------------------------------------------------
48$test = 'Unicode wikilinks';
49my $unicode_string = 'განეკუთვნება';
50$content = "[[$unicode_string]]";
51$mech->post('/.jsrpc/render', { content => $content });
52$mech->content_is(<<"HTML", $test);
53<p><span class="newWikiWord"><a title="Not found. Click to create this page." href="/$unicode_string.edit">$unicode_string?</a></span></p>
54HTML
55