File: pod_renderer_lite_app.t

package info (click to toggle)
libmojolicious-perl 5.54%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,232 kB
  • ctags: 1,223
  • sloc: perl: 9,581; makefile: 10
file content (100 lines) | stat: -rw-r--r-- 3,144 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
use Mojo::Base -strict;

BEGIN {
  $ENV{MOJO_NO_IPV6} = 1;
  $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More;
use Mojolicious::Lite;
use Test::Mojo;

# POD renderer plugin
plugin('PODRenderer')->name('perldoc');
ok app->routes->find('perldoc'), 'route found';

# Default layout
app->defaults(layout => 'gray');

get '/' => sub {
  my $c = shift;
  $c->render('simple', handler => 'pod');
};

post '/' => 'index';

post '/block' => 'block';

get '/empty' => {inline => '', handler => 'pod'};

my $t = Test::Mojo->new;

# Simple POD template
$t->get_ok('/')->status_is(200)
  ->content_like(qr!<h1 id="Test123">Test123</h1>!)
  ->content_like(qr|<p>It <code>works</code>!</p>|);

# POD helper
$t->post_ok('/')->status_is(200)->content_like(qr!test123<h1 id="A">A</h1>!)
  ->content_like(qr!<h1 id="B">B</h1>!)
  ->content_like(qr!\s+<p><code>test</code></p>!)->content_like(qr/Gray/);

# POD filter
$t->post_ok('/block')->status_is(200)
  ->content_like(qr!test321<h2 id="lalala">lalala</h2>!)
  ->content_like(qr!<p><code>test</code></p>!)->content_like(qr/Gray/);

# Empty
$t->get_ok('/empty')->status_is(200)->content_is('');

# Perldoc browser (Welcome)
$t->get_ok('/perldoc')->status_is(200)->text_is('h1 a[id="NAME"]', 'NAME')
  ->text_is('a[id="TUTORIAL"]', 'TUTORIAL')
  ->text_is('a[id="GUIDES"]',   'GUIDES')->content_like(qr/galaxy/);

# Perldoc browser (Welcome with slash)
$t->get_ok('/perldoc/')->status_is(200)->text_is('h1 a[id="NAME"]', 'NAME')
  ->text_is('a[id="TUTORIAL"]', 'TUTORIAL')
  ->text_is('a[id="GUIDES"]',   'GUIDES')->content_like(qr/galaxy/)
  ->content_unlike(qr/Gray/);

# Perldoc browser (Mojolicious documentation)
$t->get_ok('/perldoc/Mojolicious')->status_is(200)
  ->text_is('h1 a[id="NAME"]', 'NAME')->text_is('a[id="handler"]', 'handler')
  ->text_like('p', qr/Mojolicious/)->content_like(qr/Sebastian Riedel/);

# Perldoc browser (Mojolicious documentation with format)
$t->get_ok('/perldoc/Mojolicious.html')->status_is(200)
  ->text_is('h1 a[id="NAME"]', 'NAME')->text_is('a[id="handler"]', 'handler')
  ->text_like('p', qr/Mojolicious/)->content_like(qr/Sebastian Riedel/);

# Perldoc browser (negotiated Mojolicious documentation)
$t->get_ok('/perldoc/Mojolicious' => {Accept => 'text/html'})->status_is(200)
  ->text_is('h1 a[id="NAME"]', 'NAME')->text_is('a[id="handler"]', 'handler')
  ->text_like('p', qr/Mojolicious/)->content_like(qr/Sebastian Riedel/);

# Perldoc browser (Mojolicious source with format)
$t->get_ok('/perldoc/Mojolicious.txt')->status_is(200)
  ->content_type_is('text/plain;charset=UTF-8')->content_like(qr/\$VERSION/);

# Perldoc browser (negotiated Mojolicious source again)
$t->get_ok('/perldoc/Mojolicious' => {Accept => 'text/plain'})->status_is(200)
  ->content_type_is('text/plain;charset=UTF-8')->content_like(qr/\$VERSION/);

# Perldoc browser (unsupported format)
$t->get_ok('/perldoc/Mojolicious.json')->status_is(204);

done_testing();

__DATA__

@@ layouts/gray.html.ep
Gray <%= content %>

@@ index.html.ep
test123<%= pod_to_html "=head1 A\n\n=head1 B\n\nC<test>"%>

@@ block.html.ep
test321<%= pod_to_html begin %>=head2 lalala

C<test><% end %>