Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 73 lines (63 sloc) 3.001 kB
de3e165 kwalitee
Zbigniew Lukasiak authored
1 use strict;
2 use warnings;
3
fab1865 Subclassing application
Zbigniew Lukasiak authored
4 use Test::More;
5 use Plack::Test;
6 use HTTP::Request::Common;
7 use lib 't/lib';
8 use SubClassApp;
9 use File::Copy;
791c604 renamed WebNano::TTTRenderer to WebNano::Renderer::TTiny
Zbigniew Lukasiak authored
10 use WebNano::Renderer::TTiny;
fab1865 Subclassing application
Zbigniew Lukasiak authored
11
12 test_psgi(
b4b804a psgi_callback to psgi_app
Zbigniew Lukasiak authored
13 app => SubClassApp->new()->psgi_app,
fab1865 Subclassing application
Zbigniew Lukasiak authored
14 client => sub {
15 my $cb = shift;
16 my $res = $cb->(GET "/");
17 like( $res->content, qr/This is the home page/ );
18 $res = $cb->(GET "/mapped url");
19 like( $res->content, qr/This is the mapped url page/ );
20
21 $res = $cb->(GET "NestedController/some_method");
22 like( $res->content, qr/This is a method with _action postfix/ );
23 $res = $cb->(GET "NestedController/safe_method");
24 like( $res->content, qr/This is the safe_method page/ );
25 $res = $cb->(GET "NestedController/with_template");
26 like( $res->content, qr/This is a NestedController page rendered with a template/ );
27
28 $res = $cb->(GET "NestedController2/some_method");
29 like( $res->content, qr/This is a method with _action postfix in MyApp::Controller::NestedController2/ );
30 $res = $cb->(GET "NestedController2/with_template");
31 like( $res->content, qr/This is a SubClassApp::Controller::NestedController2 page rendered with a template/ );
32
33 $res = $cb->(GET "Product/some");
34 like( $res->content, qr/This is the example template for ControllerWithTemplates/ );
35 $res = $cb->(GET "Product/another");
36 like( $res->content, qr/This is template for Product/ );
37 $res = $cb->(GET "Product/third");
38 like( $res->content, qr/This is template for Product/ );
39
40 $res = $cb->(GET "Book/some");
41 like( $res->content, qr/This is the example template for ControllerWithTemplates/ );
42 $res = $cb->(GET "Book/another");
43 like( $res->content, qr/This is template for Product/ );
44 $res = $cb->(GET "Book/third");
45 like( $res->content, qr/This is template for Book/ );
46
47 $res = $cb->(GET "/there_is_no_such_page");
48 is( $res->code, 404 , '404 for non existing controller' );
49 $res = $cb->(GET "/ThisIsNotController/");
50 is( $res->code, 404 , '404 for a non controller' );
51 $res = $cb->(GET "/streaming?who=zby");
52 like( $res->content, qr/Hello, zby/ );
53 # $res = $cb->(GET "/DoesNotCompile/");
54 # is( $res->code, 500, '500 for controller that does not compile' );
55 # in some circumstances the above code dies instead of issuing a 500
56 }
57 );
58
5bd0954 tests for overriding controllers
Zbigniew Lukasiak authored
59 test_psgi(
b4b804a psgi_callback to psgi_app
Zbigniew Lukasiak authored
60 app => SubClassApp->new()->psgi_app,
5bd0954 tests for overriding controllers
Zbigniew Lukasiak authored
61 client => sub {
62 my $cb = shift;
63 my $res = $cb->(GET "ToBeOverridden/some");
64 is( $res->content, 'SubClassApp::Controller::ToBeOverridden', 'overridden controller' );
65 $res = $cb->(GET "ToBeOverridden/other");
66 is( $res->code, 404 , 'actions are not merged' );
67 $res = $cb->(GET "ToBeOverridden/templated");
68 is( $res->content, "t/data/templates/ToBeOverridden/templated\n", 'templates are independent' );
69 }
70 );
71
fab1865 Subclassing application
Zbigniew Lukasiak authored
72 done_testing();
Something went wrong with that request. Please try again.