File: renderer.t

package info (click to toggle)
libmojolicious-perl 0.999926-1%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,672 kB
  • ctags: 949
  • sloc: perl: 17,391; makefile: 4
file content (51 lines) | stat: -rw-r--r-- 1,464 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
#!/usr/bin/env perl

# Copyright (C) 2008-2010, Sebastian Riedel.

use strict;
use warnings;

use Test::More tests => 5;

use Mojo;
use MojoX::Dispatcher::Routes::Controller;
use MojoX::Renderer;

# Actually, she wasn't really my girlfriend,
# she just lived nextdoor and never closed her curtains.
my $c = MojoX::Dispatcher::Routes::Controller->new(app => Mojo->new);
$c->app->log->path(undef);
$c->app->log->level('fatal');
my $r = MojoX::Renderer->new(default_format => 'debug');
$r->add_handler(
    debug => sub {
        my ($self, $c, $output) = @_;
        $$output .= 'Hello Mojo!';
    }
);
$c->stash->{format} = 'something';

# Normal rendering
$c->stash->{partial}  = 1;
$c->stash->{template} = 'something';
$c->stash->{handler}  = 'debug';
is($r->render($c), 'Hello Mojo!', 'normal rendering');

# Normal rendering with layout
$c->stash->{partial}  = 1;
$c->stash->{template} = 'something';
$c->stash->{layout}   = 'something';
$c->stash->{handler}  = 'debug';
is($r->render($c), 'Hello Mojo!Hello Mojo!', 'normal rendering with layout');
is(delete $c->stash->{layout}, 'something');

# Rendering a path with dots
$c->stash->{partial}  = 1;
$c->stash->{template} = 'some.path.with.dots/template';
$c->stash->{handler}  = 'debug';
is($r->render($c), 'Hello Mojo!', 'rendering a path with dots');

# Unrecognized handler
$c->stash->{partial} = 1;
$c->stash->{handler} = 'not_defined';
is($r->render($c), undef, 'return undef for unrecognized handler');