/
10.main.t
66 lines (57 loc) · 2.82 KB
/
10.main.t
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
use strict;
use warnings;
use Test::More;
use Plack::Test;
use HTTP::Request::Common;
use lib 't/lib';
use MyApp;
use File::Copy;
use WebNano::Renderer::TTiny;
use WebNano::Controller;
my $c = WebNano::Controller->new( self_path => '', template_search_path => [] );
my $renderer = WebNano::Renderer::TTiny->new( root => 't/data/templates', application => WebNano->new() );
my $rendered = $renderer->render( c => $c, template => 'dummy_template', some_var => 'some value' );
ok( $rendered =~ /some_var: some value/, 'vars' );
ok( $rendered =~ /^Some text/, 'Slurping template file' );
test_psgi(
app => MyApp->new()->psgi_callback,
client => sub {
my $cb = shift;
my $res = $cb->(GET "/");
like( $res->content, qr/This is the home page/ );
$res = $cb->(GET "/mapped url");
like( $res->content, qr/This is the mapped url page/ );
$res = $cb->(GET "NestedController/some_method");
like( $res->content, qr/This is a method with _action postfix/ );
$res = $cb->(GET "NestedController/safe_method");
like( $res->content, qr/This is the safe_method page/ );
$res = $cb->(GET "NestedController/with_template");
like( $res->content, qr/This is a NestedController page rendered with a template/ );
$res = $cb->(GET "NestedController2/some_method");
like( $res->content, qr/This is a method with _action postfix in MyApp::Controller::NestedController2/ );
$res = $cb->(GET "NestedController2/with_template");
like( $res->content, qr/This is a MyApp::Controller::NestedController2 page rendered with a template/ );
$res = $cb->(GET "Product/some");
like( $res->content, qr/This is the example template for ControllerWithTemplates/ );
$res = $cb->(GET "Product/another");
like( $res->content, qr/This is template for Product/ );
$res = $cb->(GET "Product/third");
like( $res->content, qr/This is template for Product/ );
$res = $cb->(GET "Book/some");
like( $res->content, qr/This is the example template for ControllerWithTemplates/ );
$res = $cb->(GET "Book/another");
like( $res->content, qr/This is template for Product/ );
$res = $cb->(GET "Book/third");
like( $res->content, qr/This is template for Book/ );
$res = $cb->(GET "/there_is_no_such_page");
is( $res->code, 404 , '404 for non existing controller' );
$res = $cb->(GET "/ThisIsNotController/");
is( $res->code, 404 , '404 for a non controller' );
$res = $cb->(GET "/streaming?who=zby");
like( $res->content, qr/Hello, zby/ );
# $res = $cb->(GET "/DoesNotCompile/");
# is( $res->code, 500, '500 for controller that does not compile' );
# in some circumstances the above code dies instead of issuing a 500
}
);
done_testing();