File: 002_view_rendering.t

package info (click to toggle)
libdancer-perl 1.3521%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,460 kB
  • sloc: perl: 7,436; xml: 2,211; sh: 54; makefile: 32; sql: 5
file content (74 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download | duplicates (6)
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
use Dancer ':tests';
use Test::More;
use Dancer::Test;

my $views = path(dirname(__FILE__), 'views');
set views => $views;

my $time = time();

set show_errors => 1;

my @tests = (
    { path => '/',
      expected => "in view index.tt: number=\"\"\n" },
    { path => '/number/42',
      expected => "in view index.tt: number=\"42\"\n" },
    { path => '/clock',
      expected => "$time\n"},
    { path => '/request',
      expected => "/request\n" },
    { path => '/vars',
      expected => "bar\n" },
);

plan tests => 2 + scalar(@tests);

# 1. Check setting variables
{
    is setting("views") => $views, "Views setting was correctly set";

    ok !defined(setting("layout")), 'layout is not defined';
}

# 2. Check views
# test simple rendering

get '/' => sub {
    template 'index';
};

get '/with_fh' => sub {
    my $fh;

    die "TODO";
};

# test params.foo in view
get '/number/:number' => sub {
    template 'index'
};

# test token interpolation
get '/clock' => sub {
    template clock => { time => $time };
};

# test request.foo in view
get '/request' => sub {
    template 'request';
};

# test vars in view
get '/vars' => sub {
    var foo => 'bar';
    template 'vars';
};

foreach my $test (@tests) {
    my $path = $test->{path};
    my $expected = $test->{expected};

    response_content_is [GET => $path] => $expected;

}