merge rafl's test
[catagits/Catalyst-Runtime.git] / t / live_component_controller_action_chained.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 => 138*$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     my ($run_number) = @_;
28
29     #
30     #   This is a simple test where the parent and child actions are
31     #   within the same controller.
32     #
33     {
34         my @expected = qw[
35           TestApp::Controller::Action::Chained->begin
36           TestApp::Controller::Action::Chained->foo
37           TestApp::Controller::Action::Chained->endpoint
38           TestApp::Controller::Action::Chained->end
39         ];
40
41         my $expected = join( ", ", @expected );
42
43         ok( my $response = request('http://localhost/chained/foo/1/end/2'), 'chained + local endpoint' );
44         is( $response->header('X-Catalyst-Executed'),
45             $expected, 'Executed actions' );
46         is( $response->content, '1; 2', 'Content OK' );
47     }
48
49     #
50     #   This makes sure the above isn't found if the argument for the
51     #   end action isn't supplied.
52     #
53     {
54         my $expected = undef;
55
56         ok( my $response = request('http://localhost/chained/foo/1/end'), 
57             'chained + local endpoint; missing last argument' );
58         is( $response->header('X-Catalyst-Executed'),
59             $expected, 'Executed actions' );
60         is( $response->code, 500, 'Status OK' );
61     }
62
63     #
64     #   Tests the case when the child action is placed in a subcontroller.
65     #
66     {
67         my @expected = qw[
68           TestApp::Controller::Action::Chained->begin
69           TestApp::Controller::Action::Chained->foo
70           TestApp::Controller::Action::Chained::Foo->spoon
71           TestApp::Controller::Action::Chained->end
72         ];
73
74         my $expected = join( ", ", @expected );
75
76         ok( my $response = request('http://localhost/chained/foo/1/spoon'), 'chained + subcontroller endpoint' );
77         is( $response->header('X-Catalyst-Executed'),
78             $expected, 'Executed actions' );
79         is( $response->content, '1; ', 'Content OK' );
80     }
81
82     #
83     #   Tests if the relative specification (e.g.: Chained('bar') ) works
84     #   as expected.
85     #
86     {
87         my @expected = qw[
88           TestApp::Controller::Action::Chained->begin
89           TestApp::Controller::Action::Chained->bar
90           TestApp::Controller::Action::Chained->finale
91           TestApp::Controller::Action::Chained->end
92         ];
93
94         my $expected = join( ", ", @expected );
95
96         ok( my $response = request('http://localhost/chained/bar/1/spoon'), 'chained + relative endpoint' );
97         is( $response->header('X-Catalyst-Executed'),
98             $expected, 'Executed actions' );
99         is( $response->content, '; 1, spoon', 'Content OK' );
100     }
101
102     #
103     #   Just a test for multiple arguments.
104     #
105     {
106         my @expected = qw[
107           TestApp::Controller::Action::Chained->begin
108           TestApp::Controller::Action::Chained->foo2
109           TestApp::Controller::Action::Chained->endpoint2
110           TestApp::Controller::Action::Chained->end
111         ];
112
113         my $expected = join( ", ", @expected );
114
115         ok( my $response = request('http://localhost/chained/foo2/10/20/end2/15/25'), 
116             'chained + local (2 args each)' );
117         is( $response->header('X-Catalyst-Executed'),
118             $expected, 'Executed actions' );
119         is( $response->content, '10, 20; 15, 25', 'Content OK' );
120     }
121
122     #
123     #   The first three-chain test tries to call the action with :Args(1)
124     #   specification. There's also a one action with a :CaptureArgs(1)
125     #   attribute, that should not be dispatched to.
126     #
127     {
128         my @expected = qw[
129           TestApp::Controller::Action::Chained->begin
130           TestApp::Controller::Action::Chained->one_end
131           TestApp::Controller::Action::Chained->end
132         ];
133
134         my $expected = join( ", ", @expected );
135
136         ok( my $response = request('http://localhost/chained/one/23'),
137             'three-chain (only first)' );
138         is( $response->header('X-Catalyst-Executed'),
139             $expected, 'Executed actions' );
140         is( $response->content, '; 23', 'Content OK' );
141     }
142
143     #
144     #   This is the second three-chain test, it goes for the action that
145     #   handles "/one/$cap/two/$arg1/$arg2" paths. Should be the two action
146     #   having :Args(2), not the one having :CaptureArgs(2).
147     #
148     {
149         my @expected = qw[
150           TestApp::Controller::Action::Chained->begin
151           TestApp::Controller::Action::Chained->one
152           TestApp::Controller::Action::Chained->two_end
153           TestApp::Controller::Action::Chained->end
154         ];
155
156         my $expected = join( ", ", @expected );
157
158         ok( my $response = request('http://localhost/chained/one/23/two/23/46'),
159             'three-chain (up to second)' );
160         is( $response->header('X-Catalyst-Executed'),
161             $expected, 'Executed actions' );
162         is( $response->content, '23; 23, 46', 'Content OK' );
163     }
164
165     #
166     #   Last of the three-chain tests. Has no concurrent action with :CaptureArgs
167     #   and is more thought to simply test the chain as a whole and the 'two'
168     #   action specifying :CaptureArgs.
169     #
170     {
171         my @expected = qw[
172           TestApp::Controller::Action::Chained->begin
173           TestApp::Controller::Action::Chained->one
174           TestApp::Controller::Action::Chained->two
175           TestApp::Controller::Action::Chained->three_end
176           TestApp::Controller::Action::Chained->end
177         ];
178
179         my $expected = join( ", ", @expected );
180
181         ok( my $response = request('http://localhost/chained/one/23/two/23/46/three/1/2/3'),
182             'three-chain (all three)' );
183         is( $response->header('X-Catalyst-Executed'),
184             $expected, 'Executed actions' );
185         is( $response->content, '23, 23, 46; 1, 2, 3', 'Content OK' );
186     }
187
188     #
189     #   Tests dispatching on number of arguments for :Args. This should be
190     #   dispatched to the action expecting one argument.
191     #
192     {
193         my @expected = qw[
194           TestApp::Controller::Action::Chained->begin
195           TestApp::Controller::Action::Chained->multi1
196           TestApp::Controller::Action::Chained->end
197         ];
198
199         my $expected = join( ", ", @expected );
200
201         ok( my $response = request('http://localhost/chained/multi/23'),
202             'multi-action (one arg)' );
203         is( $response->header('X-Catalyst-Executed'),
204             $expected, 'Executed actions' );
205         is( $response->content, '; 23', 'Content OK' );
206     }
207
208     #
209     #   Belongs to the former test and goes for the action expecting two arguments.
210     #
211     {
212         my @expected = qw[
213           TestApp::Controller::Action::Chained->begin
214           TestApp::Controller::Action::Chained->multi2
215           TestApp::Controller::Action::Chained->end
216         ];
217
218         my $expected = join( ", ", @expected );
219
220         ok( my $response = request('http://localhost/chained/multi/23/46'),
221             'multi-action (two args)' );
222         is( $response->header('X-Catalyst-Executed'),
223             $expected, 'Executed actions' );
224         is( $response->content, '; 23, 46', 'Content OK' );
225     }
226
227     #
228     #   Dispatching on argument count again, this time we provide too many
229     #   arguments, so dispatching should fail.
230     #
231     {
232         my $expected = undef;
233
234         ok( my $response = request('http://localhost/chained/multi/23/46/67'),
235             'multi-action (three args, should lead to error)' );
236         is( $response->header('X-Catalyst-Executed'),
237             $expected, 'Executed actions' );
238         is( $response->code, 500, 'Status OK' );
239     }
240
241     #
242     #   This tests the case when an action says it's the child of an action in
243     #   a subcontroller.
244     #
245     {
246         my @expected = qw[
247           TestApp::Controller::Action::Chained->begin
248           TestApp::Controller::Action::Chained::Foo->higher_root
249           TestApp::Controller::Action::Chained->higher_root
250           TestApp::Controller::Action::Chained->end
251         ];
252
253         my $expected = join( ", ", @expected );
254
255         ok( my $response = request('http://localhost/chained/higher_root/23/bar/11'),
256             'root higher than child' );
257         is( $response->header('X-Catalyst-Executed'),
258             $expected, 'Executed actions' );
259         is( $response->content, '23; 11', 'Content OK' );
260     }
261
262     #
263     #   Just a more complex version of the former test. It tests if a controller ->
264     #   subcontroller -> controller dispatch works.
265     #
266     {
267         my @expected = qw[
268           TestApp::Controller::Action::Chained->begin
269           TestApp::Controller::Action::Chained->pcp1
270           TestApp::Controller::Action::Chained::Foo->pcp2
271           TestApp::Controller::Action::Chained->pcp3
272           TestApp::Controller::Action::Chained->end
273         ];
274
275         my $expected = join( ", ", @expected );
276
277         ok( my $response = request('http://localhost/chained/pcp1/1/pcp2/2/pcp3/3'),
278             'parent -> child -> parent' );
279         is( $response->header('X-Catalyst-Executed'),
280             $expected, 'Executed actions' );
281         is( $response->content, '1, 2; 3', 'Content OK' );
282     }
283
284     #
285     #   Tests dispatch on capture number. This test is for a one capture action.
286     #
287     {
288         my @expected = qw[
289           TestApp::Controller::Action::Chained->begin
290           TestApp::Controller::Action::Chained->multi_cap1
291           TestApp::Controller::Action::Chained->multi_cap_end1
292           TestApp::Controller::Action::Chained->end
293         ];
294
295         my $expected = join( ", ", @expected );
296
297         ok( my $response = request('http://localhost/chained/multi_cap/1/baz'),
298             'dispatch on capture num 1' );
299         is( $response->header('X-Catalyst-Executed'),
300             $expected, 'Executed actions' );
301         is( $response->content, '1; ', 'Content OK' );
302     }
303
304     #
305     #   Belongs to the former test. This one goes for the action expecting two
306     #   captures.
307     #
308     {
309         my @expected = qw[
310           TestApp::Controller::Action::Chained->begin
311           TestApp::Controller::Action::Chained->multi_cap2
312           TestApp::Controller::Action::Chained->multi_cap_end2
313           TestApp::Controller::Action::Chained->end
314         ];
315
316         my $expected = join( ", ", @expected );
317
318         ok( my $response = request('http://localhost/chained/multi_cap/1/2/baz'),
319             'dispatch on capture num 2' );
320         is( $response->header('X-Catalyst-Executed'),
321             $expected, 'Executed actions' );
322         is( $response->content, '1, 2; ', 'Content OK' );
323     }
324
325     #
326     #   Tests the priority of a slurpy arguments action (with :Args) against
327     #   two actions chained together. The two actions should win.
328     #
329     {
330         my @expected = qw[
331           TestApp::Controller::Action::Chained->begin
332           TestApp::Controller::Action::Chained->priority_a2
333           TestApp::Controller::Action::Chained->priority_a2_end
334           TestApp::Controller::Action::Chained->end
335         ];
336
337         my $expected = join( ", ", @expected );
338
339         ok( my $response = request('http://localhost/chained/priority_a/1/end/2'),
340             'priority - slurpy args vs. parent/child' );
341         is( $response->header('X-Catalyst-Executed'),
342             $expected, 'Executed actions' );
343         is( $response->content, '1; 2', 'Content OK' );
344     }
345
346     #
347     #   This belongs to the former test but tests if two chained actions have
348     #   priority over an action with the exact arguments.
349     #
350     {
351         my @expected = qw[
352           TestApp::Controller::Action::Chained->begin
353           TestApp::Controller::Action::Chained->priority_b2
354           TestApp::Controller::Action::Chained->priority_b2_end
355           TestApp::Controller::Action::Chained->end
356         ];
357
358         my $expected = join( ", ", @expected );
359
360         ok( my $response = request('http://localhost/chained/priority_b/1/end/2'),
361             'priority - fixed args vs. parent/child' );
362         is( $response->header('X-Catalyst-Executed'),
363             $expected, 'Executed actions' );
364         is( $response->content, '1; 2', 'Content OK' );
365     }
366
367     #
368     #   This belongs to the former test but tests if two chained actions have
369     #   priority over an action with one child action not having the Args() attr set.
370     #
371     {
372         my @expected = qw[
373           TestApp::Controller::Action::Chained->begin
374           TestApp::Controller::Action::Chained->priority_c1
375           TestApp::Controller::Action::Chained->priority_c2_xyz
376           TestApp::Controller::Action::Chained->end
377         ];
378
379         my $expected = join( ", ", @expected );
380
381         ok( my $response = request('http://localhost/chained/priority_c/1/xyz/'),
382             'priority - no Args() order mismatch' );
383         is( $response->header('X-Catalyst-Executed'),
384             $expected, 'Executed actions' );
385         is( $response->content, '1; ', 'Content OK' );
386     }
387
388     #
389     #   Test dispatching between two controllers that are on the same level and
390     #   therefor have no parent/child relationship.
391     #
392     {
393         my @expected = qw[
394           TestApp::Controller::Action::Chained->begin
395           TestApp::Controller::Action::Chained::Bar->cross1
396           TestApp::Controller::Action::Chained::Foo->cross2
397           TestApp::Controller::Action::Chained->end
398         ];
399
400         my $expected = join( ", ", @expected );
401
402         ok( my $response = request('http://localhost/chained/cross/1/end/2'),
403             'cross controller w/o par/child relation' );
404         is( $response->header('X-Catalyst-Executed'),
405             $expected, 'Executed actions' );
406         is( $response->content, '1; 2', 'Content OK' );
407     }
408
409     #
410     #   This is for testing if the arguments got passed to the actions 
411     #   correctly.
412     #
413     {
414         my @expected = qw[
415           TestApp::Controller::Action::Chained->begin
416           TestApp::Controller::Action::Chained::PassedArgs->first
417           TestApp::Controller::Action::Chained::PassedArgs->second
418           TestApp::Controller::Action::Chained::PassedArgs->third
419           TestApp::Controller::Action::Chained::PassedArgs->end
420         ];
421
422         my $expected = join( ", ", @expected );
423
424         ok( my $response = request('http://localhost/chained/passedargs/a/1/b/2/c/3'),
425             'Correct arguments passed to actions' );
426         is( $response->header('X-Catalyst-Executed'),
427             $expected, 'Executed actions' );
428         is( $response->content, '1; 2; 3', 'Content OK' );
429     }
430
431     #
432     #   The :Args attribute is optional, we check the action not specifying
433     #   it with these tests.
434     #
435     {
436         my @expected = qw[
437           TestApp::Controller::Action::Chained->begin
438           TestApp::Controller::Action::Chained->opt_args
439           TestApp::Controller::Action::Chained->end
440         ];
441
442         my $expected = join( ", ", @expected );
443
444         ok( my $response = request('http://localhost/chained/opt_args/1/2/3'),
445             'Optional :Args attribute working' );
446         is( $response->header('X-Catalyst-Executed'),
447             $expected, 'Executed actions' );
448         is( $response->content, '; 1, 2, 3', 'Content OK' );
449     }
450
451     #
452     #   Tests for optional PathPart attribute.
453     #
454     {
455         my @expected = qw[
456           TestApp::Controller::Action::Chained->begin
457           TestApp::Controller::Action::Chained->opt_pp_start
458           TestApp::Controller::Action::Chained->opt_pathpart
459           TestApp::Controller::Action::Chained->end
460         ];
461
462         my $expected = join( ", ", @expected );
463
464         ok( my $response = request('http://localhost/chained/optpp/1/opt_pathpart/2'),
465             'Optional :PathName attribute working' );
466         is( $response->header('X-Catalyst-Executed'),
467             $expected, 'Executed actions' );
468         is( $response->content, '1; 2', 'Content OK' );
469     }
470
471     #
472     #   Tests for optional PathPart *and* Args attributes.
473     #
474     {
475         my @expected = qw[
476           TestApp::Controller::Action::Chained->begin
477           TestApp::Controller::Action::Chained->opt_all_start
478           TestApp::Controller::Action::Chained->oa
479           TestApp::Controller::Action::Chained->end
480         ];
481
482         my $expected = join( ", ", @expected );
483
484         ok( my $response = request('http://localhost/chained/optall/1/oa/2/3'),
485             'Optional :PathName *and* :Args attributes working' );
486         is( $response->header('X-Catalyst-Executed'),
487             $expected, 'Executed actions' );
488         is( $response->content, '1; 2, 3', 'Content OK' );
489     }
490
491     #
492     #   Test if :Chained is the same as :Chained('/')
493     #
494     {
495         my @expected = qw[
496           TestApp::Controller::Action::Chained->begin
497           TestApp::Controller::Action::Chained->rootdef
498           TestApp::Controller::Action::Chained->end
499         ];
500
501         my $expected = join( ", ", @expected );
502
503         ok( my $response = request('http://localhost/chained/rootdef/23'),
504             ":Chained is the same as :Chained('/')" );
505         is( $response->header('X-Catalyst-Executed'),
506             $expected, 'Executed actions' );
507         is( $response->content, '; 23', 'Content OK' );
508     }
509
510     #
511     #   Test if :Chained('.') is working
512     #
513     {
514         my @expected = qw[
515           TestApp::Controller::Action::Chained->begin
516           TestApp::Controller::Action::Chained->parentchain
517           TestApp::Controller::Action::Chained::ParentChain->child
518           TestApp::Controller::Action::Chained->end
519         ];
520
521         my $expected = join( ", ", @expected );
522
523         ok( my $response = request('http://localhost/chained/parentchain/1/child/2'),
524             ":Chained('.') chains to parent controller action" );
525         is( $response->header('X-Catalyst-Executed'),
526             $expected, 'Executed actions' );
527         is( $response->content, '1; 2', 'Content OK' );
528     }
529
530     #
531     #   Test if :Chained('../act') is working
532     #
533     {
534         local $TODO = "To Be Coded";
535         my @expected = qw[
536           TestApp::Controller::Action::Chained->begin
537           TestApp::Controller::Action::Chained->rootdef
538           TestApp::Controller::Action::Chained::ParentChain->chained_rel
539           TestApp::Controller::Action::Chained->end
540         ];
541
542         my $expected = join( ", ", @expected );
543
544         ok( my $response = request('http://localhost/chained/rootdef/1/chained_rel/3/2'),
545             ":Chained('../action') chains to correct action" );
546         is( $response->header('X-Catalyst-Executed'),
547             $expected, 'Executed actions' );
548         is( $response->content, '1; 3, 2', 'Content OK' );
549     }
550
551     #
552     #   Test if :ChainedParent is working
553     #
554     {
555         local $TODO = "To Be Coded";
556         my @expected = qw[
557           TestApp::Controller::Action::Chained->begin
558           TestApp::Controller::Action::Chained->loose
559           TestApp::Controller::Action::Chained::ParentChain->loose
560           TestApp::Controller::Action::Chained->end
561         ];
562
563         my $expected = join( ", ", @expected );
564
565         ok( my $response = request('http://localhost/chained/loose/4/loose/a/b'),
566             ":Chained('../action') chains to correct action" );
567         is( $response->header('X-Catalyst-Executed'),
568             $expected, 'Executed actions' );
569         is( $response->content, '4; a, b', 'Content OK' );
570     }
571
572     #
573     #   Test if :Chained('../name/act') is working
574     #
575     {
576         local $TODO = "To Be Coded";
577         my @expected = qw[
578           TestApp::Controller::Action::Chained->begin
579           TestApp::Controller::Action::Chained::Bar->cross1
580           TestApp::Controller::Action::Chained::ParentChain->up_down
581           TestApp::Controller::Action::Chained->end
582         ];
583
584         my $expected = join( ", ", @expected );
585
586         ok( my $response = request('http://localhost/chained/cross/4/up_down/5'),
587             ":Chained('../action') chains to correct action" );
588         is( $response->header('X-Catalyst-Executed'),
589             $expected, 'Executed actions' );
590         is( $response->content, '4; 5', 'Content OK' );
591     }
592
593     #
594     #   Test behaviour of auto actions returning '1' for the chain.
595     #
596     {
597         my @expected = qw[
598           TestApp::Controller::Action::Chained->begin
599           TestApp::Controller::Action::Chained::Auto->auto
600           TestApp::Controller::Action::Chained::Auto::Foo->auto
601           TestApp::Controller::Action::Chained::Auto->foo
602           TestApp::Controller::Action::Chained::Auto::Foo->fooend
603           TestApp::Controller::Action::Chained->end
604         ];
605
606         my $expected = join( ", ", @expected );
607
608         ok( my $response = request('http://localhost/chained/autochain1/1/fooend/2'),
609             "Behaviour when auto returns 1 correct" );
610         is( $response->header('X-Catalyst-Executed'),
611             $expected, 'Executed actions' );
612         is( $response->content, '1; 2', 'Content OK' );
613     }
614
615     #
616     #   Test behaviour of auto actions returning '0' for the chain.
617     #
618     {
619         my @expected = qw[
620           TestApp::Controller::Action::Chained->begin
621           TestApp::Controller::Action::Chained::Auto->auto
622           TestApp::Controller::Action::Chained::Auto::Bar->auto
623           TestApp::Controller::Action::Chained->end
624         ];
625
626         my $expected = join( ", ", @expected );
627
628         ok( my $response = request('http://localhost/chained/autochain2/1/barend/2'),
629             "Behaviour when auto returns 0 correct" );
630         is( $response->header('X-Catalyst-Executed'),
631             $expected, 'Executed actions' );
632         is( $response->content, '1; 2', 'Content OK' );
633     }
634
635     #
636     #   Test what auto actions are run when namespaces are changed
637     #   horizontally.
638     #
639     {
640         my @expected = qw[
641           TestApp::Controller::Action::Chained->begin
642           TestApp::Controller::Action::Chained::Auto->auto
643           TestApp::Controller::Action::Chained::Auto::Foo->auto
644           TestApp::Controller::Action::Chained::Auto::Bar->crossloose
645           TestApp::Controller::Action::Chained::Auto::Foo->crossend
646           TestApp::Controller::Action::Chained->end
647         ];
648
649         my $expected = join( ", ", @expected );
650
651         ok( my $response = request('http://localhost/chained/auto_cross/1/crossend/2'),
652             "Correct auto actions are run on cross controller dispatch" );
653         is( $response->header('X-Catalyst-Executed'),
654             $expected, 'Executed actions' );
655         is( $response->content, '1; 2', 'Content OK' );
656     }
657
658     #
659     #   Test forwarding from auto action in chain dispatch.
660     #
661     {
662         my @expected = qw[
663           TestApp::Controller::Action::Chained->begin
664           TestApp::Controller::Action::Chained::Auto->auto
665           TestApp::Controller::Action::Chained::Auto::Forward->auto
666           TestApp::Controller::Action::Chained::Auto->fw3
667           TestApp::Controller::Action::Chained::Auto->fw1
668           TestApp::Controller::Action::Chained::Auto::Forward->forwardend
669           TestApp::Controller::Action::Chained->end
670         ];
671
672         my $expected = join( ", ", @expected );
673
674         ok( my $response = request('http://localhost/chained/auto_forward/1/forwardend/2'),
675             "Forwarding out of auto in chain" );
676         is( $response->header('X-Catalyst-Executed'),
677             $expected, 'Executed actions' );
678         is( $response->content, '1; 2', 'Content OK' );
679     }
680
681     #
682     #   Detaching out of the auto action of a chain.
683     #
684     {
685         my @expected = qw[
686           TestApp::Controller::Action::Chained->begin
687           TestApp::Controller::Action::Chained::Auto->auto
688           TestApp::Controller::Action::Chained::Auto::Detach->auto
689           TestApp::Controller::Action::Chained::Auto->fw3
690           TestApp::Controller::Action::Chained->end
691         ];
692
693         my $expected = join( ", ", @expected );
694
695         ok( my $response = request('http://localhost/chained/auto_detach/1/detachend/2'),
696             "Detaching out of auto in chain" );
697         is( $response->header('X-Catalyst-Executed'),
698             $expected, 'Executed actions' );
699         is( $response->content, '1; 2', 'Content OK' );
700     }
701
702     #
703     #   Test forwarding from auto action in chain dispatch.
704     #
705     {
706         my $expected = undef;
707
708         ok( my $response = request('http://localhost/chained/loose/23'),
709             "Loose end is not callable" );
710         is( $response->header('X-Catalyst-Executed'),
711             $expected, 'Executed actions' );
712         is( $response->code, 500, 'Status OK' );
713     }
714
715     #
716     #   Test forwarding out of a chain.
717     #
718     {
719         my @expected = qw[
720           TestApp::Controller::Action::Chained->begin
721           TestApp::Controller::Action::Chained->chain_fw_a
722           TestApp::Controller::Action::Chained->fw_dt_target
723           TestApp::Controller::Action::Chained->chain_fw_b
724           TestApp::Controller::Action::Chained->end
725         ];
726
727         my $expected = join( ", ", @expected );
728
729         ok( my $response = request('http://localhost/chained/chain_fw/1/end/2'),
730             "Forwarding out a chain" );
731         is( $response->header('X-Catalyst-Executed'),
732             $expected, 'Executed actions' );
733         is( $response->content, '1; 2', 'Content OK' );
734     }
735
736     #
737     #   Test detaching out of a chain.
738     #
739     {
740         my @expected = qw[
741           TestApp::Controller::Action::Chained->begin
742           TestApp::Controller::Action::Chained->chain_dt_a
743           TestApp::Controller::Action::Chained->fw_dt_target
744           TestApp::Controller::Action::Chained->end
745         ];
746
747         my $expected = join( ", ", @expected );
748
749         ok( my $response = request('http://localhost/chained/chain_dt/1/end/2'),
750             "Forwarding out a chain" );
751         is( $response->header('X-Catalyst-Executed'),
752             $expected, 'Executed actions' );
753         is( $response->content, '1; 2', 'Content OK' );
754     }
755
756     #
757     #   Tests that an uri_for to a chained root index action
758     #   returns the right value.
759     #
760     {
761         ok( my $response = request(
762             'http://localhost/action/chained/to_root' ),
763             'uri_for with chained root action as arg' );
764         like( $response->content,
765             qr(URI:https?://[^/]+/),
766             'Correct URI generated' );
767     }
768
769     #
770     #   Test interception of recursive chains. This test was added because at
771     #   one point during the :Chained development, Catalyst used to hang on
772     #   recursive chains.
773     #
774     {
775         eval { require 'TestAppChainedRecursive.pm' };
776         if ($run_number == 1) {
777             ok( ! $@, "Interception of recursive chains" );
778         }
779         else { pass( "Interception of recursive chains already tested" ) }
780     }
781
782     #
783     #   Test failure of absolute path part arguments.
784     #
785     {
786         eval { require 'TestAppChainedAbsolutePathPart.pm' };
787         if ($run_number == 1) {
788             like( $@, qr(foo/foo),
789                 "Usage of absolute path part argument emits error" );
790         }
791         else { pass( "Error on absolute path part arguments already tested" ) }
792     }
793
794     #
795     #   Test chained actions in the root controller
796     #
797     {
798         my @expected = qw[
799           TestApp::Controller::Action::Chained::Root->rootsub
800           TestApp::Controller::Action::Chained::Root->endpointsub
801           TestApp->end
802         ];
803
804         my $expected = join( ", ", @expected );
805
806         ok( my $response = request('http://localhost/rootsub/1/endpointsub/2'), 'chained in root namespace' );
807         is( $response->header('X-Catalyst-Executed'),
808             $expected, 'Executed actions' );
809         is( $response->content, '', 'Content OK' );
810     }
811
812     #
813     #   Complex path with multiple empty pathparts
814     #
815     {
816         my @expected = qw[
817           TestApp::Controller::Action::Chained->begin
818           TestApp::Controller::Action::Chained->mult_nopp_base
819           TestApp::Controller::Action::Chained->mult_nopp_all
820           TestApp::Controller::Action::Chained->end
821         ];
822
823         my $expected = join( ", ", @expected );
824
825         ok( my $response = request('http://localhost/chained/mult_nopp'),
826             "Complex path with multiple empty pathparts" );
827         is( $response->header('X-Catalyst-Executed'),
828             $expected, 'Executed actions' );
829         is( $response->content, '; ', 'Content OK' );
830     }
831
832     #
833     #   Higher Args() hiding more specific CaptureArgs chains sections
834     #
835     {
836         my @expected = qw[
837             TestApp::Controller::Action::Chained->begin
838             TestApp::Controller::Action::Chained->cc_base
839             TestApp::Controller::Action::Chained->cc_link
840             TestApp::Controller::Action::Chained->cc_anchor
841             TestApp::Controller::Action::Chained->end
842             ];
843
844         my $expected = join ', ', @expected;
845
846         ok( my $response = request('http://localhost/chained/choose_capture/anchor.html'),
847             'Choose between an early Args() and a later more ideal chain' );
848         is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
849         is( $response->content => '; ', 'Content OK' );
850     }
851
852     #
853     #   Less specific chain not being seen correctly due to earlier looser capture
854     #
855     {
856         my @expected = qw[
857             TestApp::Controller::Action::Chained->begin
858             TestApp::Controller::Action::Chained->cc_base
859             TestApp::Controller::Action::Chained->cc_b
860             TestApp::Controller::Action::Chained->cc_b_link
861             TestApp::Controller::Action::Chained->cc_b_anchor
862             TestApp::Controller::Action::Chained->end
863             ];
864
865         my $expected = join ', ', @expected;
866
867         ok( my $response = request('http://localhost/chained/choose_capture/b/a/anchor.html'),
868             'Choose between a more specific chain and an earlier looser one' );
869         is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
870         is( $response->content => 'a; ', 'Content OK' );
871     }
872
873     #
874     #   Check we get the looser one when it's the correct match
875     #
876     {
877         my @expected = qw[
878             TestApp::Controller::Action::Chained->begin
879             TestApp::Controller::Action::Chained->cc_base
880             TestApp::Controller::Action::Chained->cc_a
881             TestApp::Controller::Action::Chained->cc_a_link
882             TestApp::Controller::Action::Chained->cc_a_anchor
883             TestApp::Controller::Action::Chained->end
884             ];
885
886         my $expected = join ', ', @expected;
887
888         ok( my $response = request('http://localhost/chained/choose_capture/a/a/anchor.html'),
889             'Choose between a more specific chain and an earlier looser one' );
890         is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
891         is( $response->content => 'a; anchor.html', 'Content OK' );
892     }
893
894     #
895     #   Args(0) should win over Args() if we actually have no arguments.
896     {
897         my @expected = qw[
898           TestApp::Controller::Action::Chained->begin
899           TestApp::Controller::Action::Chained::ArgsOrder->base
900           TestApp::Controller::Action::Chained::ArgsOrder->index
901           TestApp::Controller::Action::Chained::ArgsOrder->end
902         ];
903
904         my $expected = join( ", ", @expected );
905
906     # With no args, we should run "index"
907         ok( my $response = request('http://localhost/argsorder/'),
908             'Correct arg order ran' );
909         is( $response->header('X-Catalyst-Executed'),
910             $expected, 'Executed actions' );
911         is( $response->content, 'base; ; index; ', 'Content OK' );
912
913     # With args given, run "all"
914         ok( $response = request('http://localhost/argsorder/X'),
915             'Correct arg order ran' );
916         is( $response->header('X-Catalyst-Executed'), 
917         join(", ", 
918          qw[
919              TestApp::Controller::Action::Chained->begin
920              TestApp::Controller::Action::Chained::ArgsOrder->base
921              TestApp::Controller::Action::Chained::ArgsOrder->all
922              TestApp::Controller::Action::Chained::ArgsOrder->end
923           ])
924       );
925         is( $response->content, 'base; ; all; X', 'Content OK' );
926     
927     }
928
929     #
930     #   PathPrefix
931     #
932     {
933         my @expected = qw[
934           TestApp::Controller::Action::Chained->begin
935           TestApp::Controller::Action::Chained::PathPrefix->instance
936           TestApp::Controller::Action::Chained->end
937         ];
938
939         my $expected = join( ", ", @expected );
940
941         ok( my $response = request('http://localhost/action/chained/pathprefix/1'),
942             "PathPrefix (as an endpoint)" );
943         is( $response->header('X-Catalyst-Executed'),
944             $expected, 'Executed actions' );
945         is( $response->content, '; 1', 'Content OK' );
946     }
947
948     #
949     #   static paths vs. captures
950     #
951     {
952         my @expected = qw[
953             TestApp::Controller::Action::Chained->begin
954             TestApp::Controller::Action::Chained->apan
955             TestApp::Controller::Action::Chained->korv
956             TestApp::Controller::Action::Chained->static_end
957             TestApp::Controller::Action::Chained->end
958         ];
959
960         my $expected = join( ", ", @expected );
961
962         ok( my $response = request('http://localhost/action/chained/static_end'),
963             "static paths are prefered over captures" );
964         is( $response->header('X-Catalyst-Executed'),
965             $expected, 'Executed actions' );
966     }
967 }