Create branch register_actions.
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_detach.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../lib";
8
9 our $iters;
10
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
12
13 use Test::More tests => 18*$iters;
14 use Catalyst::Test 'TestApp';
15
16 if ( $ENV{CAT_BENCHMARK} ) {
17     require Benchmark;
18     Benchmark::timethis( $iters, \&run_tests );
19 }
20 else {
21     for ( 1 .. $iters ) {
22         run_tests();
23     }
24 }
25
26 sub run_tests {
27     {
28         my @expected = qw[
29           TestApp::Controller::Action::Detach->begin
30           TestApp::Controller::Action::Detach->one
31           TestApp::Controller::Action::Detach->two
32           TestApp::View::Dump::Request->process
33           TestApp->end
34         ];
35
36         my $expected = join( ", ", @expected );
37
38         # Test detach to chain of actions.
39         ok( my $response = request('http://localhost/action/detach/one'),
40             'Request' );
41         ok( $response->is_success, 'Response Successful 2xx' );
42         is( $response->content_type, 'text/plain', 'Response Content-Type' );
43         is( $response->header('X-Catalyst-Action'),
44             'action/detach/one', 'Test Action' );
45         is(
46             $response->header('X-Test-Class'),
47             'TestApp::Controller::Action::Detach',
48             'Test Class'
49         );
50         is( $response->header('X-Catalyst-Executed'),
51             $expected, 'Executed actions' );
52     }
53
54     {
55         my @expected = qw[
56           TestApp::Controller::Action::Detach->begin
57           TestApp::Controller::Action::Detach->path
58           TestApp::Controller::Action::Detach->two
59           TestApp::View::Dump::Request->process
60           TestApp->end
61         ];
62
63         my $expected = join( ", ", @expected );
64
65         # Test detach to chain of actions.
66         ok( my $response = request('http://localhost/action/detach/path'),
67             'Request' );
68         ok( $response->is_success, 'Response Successful 2xx' );
69         is( $response->content_type, 'text/plain', 'Response Content-Type' );
70         is( $response->header('X-Catalyst-Action'),
71             'action/detach/path', 'Test Action' );
72         is(
73             $response->header('X-Test-Class'),
74             'TestApp::Controller::Action::Detach',
75             'Test Class'
76         );
77         is( $response->header('X-Catalyst-Executed'),
78             $expected, 'Executed actions' );
79     }
80
81     {
82         ok(
83             my $response =
84               request('http://localhost/action/detach/with_args/old'),
85             'Request with args'
86         );
87         ok( $response->is_success, 'Response Successful 2xx' );
88         is( $response->content, 'new' );
89     }
90
91     {
92         ok(
93             my $response = request(
94                 'http://localhost/action/detach/with_method_and_args/old'),
95             'Request with args and method'
96         );
97         ok( $response->is_success, 'Response Successful 2xx' );
98         is( $response->content, 'new' );
99     }
100 }