convert to Distar
[catagits/Catalyst-Runtime.git] / t / state.t
1 use warnings;
2 use strict;
3 use Test::More;
4 use HTTP::Request::Common;
5
6 {
7   package MyApp::Controller::Root;
8   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
9
10   use base 'Catalyst::Controller';
11
12   MyApp::Controller::Root->config(namespace=>'');
13
14   sub begin :Action {
15     my ($self, $c) = @_;
16     Test::More::is($c->state, 0);
17     return 'begin';
18   }
19
20   sub auto :Action {
21     my ($self, $c) = @_;
22     # Even if a begin returns something, we kill it.  Need to
23     # do this since there's actually people doing detach in
24     # auto and expect that to work the same as 0.
25     Test::More::is($c->state, '0');
26     return 'auto';
27
28   }
29
30   sub base :Chained('/') PathPrefix CaptureArgs(0) {
31     my ($self, $c) = @_;
32     Test::More::is($c->state, 'auto');
33     return 10;
34   }
35
36     sub one :Chained('base') PathPart('') CaptureArgs(0) {
37       my ($self, $c) = @_;
38       Test::More::is($c->state, 10);
39       return 20;
40     }
41
42       sub two :Chained('one') PathPart('') Args(1) {
43         my ($self, $c, $arg) = @_;
44         Test::More::is($c->state, 20);
45         my $ret = $c->forward('forward2');
46         Test::More::is($ret, 25);
47         Test::More::is($c->state, 25);
48         return 30;
49       }
50
51   sub end :Action {
52     my ($self, $c) = @_;
53     Test::More::is($c->state, 30);
54     my $ret = $c->forward('forward1');
55     Test::More::is($ret, 100);
56     Test::More::is($c->state, 100);
57     $c->detach('detach1');
58   }
59
60   sub forward1 :Action {
61     my ($self, $c) = @_;
62     Test::More::is($c->state, 30);
63     return 100;
64   }
65
66   sub forward2 :Action {
67     my ($self, $c) = @_;
68     Test::More::is($c->state, 20);
69     return 25;
70   }
71
72   sub detach1 :Action {
73     my ($self, $c) = @_;
74     Test::More::is($c->state, 100);
75   }
76
77   package MyApp;
78   use Catalyst;
79
80   MyApp->config(show_internal_actions=>1);
81   MyApp->setup;
82 }
83
84 use Catalyst::Test 'MyApp';
85
86 {
87   ok my $res = request "/100";
88 }
89
90 done_testing;