Test :Chained('../../action').
[catagits/Catalyst-Runtime.git] / t / live_component_controller_action_chained.t
CommitLineData
141459fa 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
9our $iters;
10
6b25e555 11BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
141459fa 12
2989c763 13use Test::More tests => 141*$iters;
141459fa 14use Catalyst::Test 'TestApp';
15
16if ( $ENV{CAT_BENCHMARK} ) {
17 require Benchmark;
18 Benchmark::timethis( $iters, \&run_tests );
19}
20else {
21 for ( 1 .. $iters ) {
8a6a6581 22 run_tests($_);
141459fa 23 }
24}
922c58d6 25
141459fa 26sub run_tests {
8a6a6581 27 my ($run_number) = @_;
d416846e 28
29 #
30 # This is a simple test where the parent and child actions are
31 # within the same controller.
32 #
141459fa 33 {
34 my @expected = qw[
5882c86e 35 TestApp::Controller::Action::Chained->begin
36 TestApp::Controller::Action::Chained->foo
37 TestApp::Controller::Action::Chained->endpoint
38 TestApp::Controller::Action::Chained->end
141459fa 39 ];
922c58d6 40
141459fa 41 my $expected = join( ", ", @expected );
922c58d6 42
5882c86e 43 ok( my $response = request('http://localhost/chained/foo/1/end/2'), 'chained + local endpoint' );
141459fa 44 is( $response->header('X-Catalyst-Executed'),
45 $expected, 'Executed actions' );
46 is( $response->content, '1; 2', 'Content OK' );
47 }
d416846e 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
5882c86e 56 ok( my $response = request('http://localhost/chained/foo/1/end'),
57 'chained + local endpoint; missing last argument' );
d416846e 58 is( $response->header('X-Catalyst-Executed'),
59 $expected, 'Executed actions' );
10ae2631 60 is( $response->code, 500, 'Status OK' );
d416846e 61 }
62
63 #
64 # Tests the case when the child action is placed in a subcontroller.
65 #
141459fa 66 {
67 my @expected = qw[
5882c86e 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
141459fa 72 ];
922c58d6 73
141459fa 74 my $expected = join( ", ", @expected );
922c58d6 75
5882c86e 76 ok( my $response = request('http://localhost/chained/foo/1/spoon'), 'chained + subcontroller endpoint' );
141459fa 77 is( $response->header('X-Catalyst-Executed'),
78 $expected, 'Executed actions' );
79 is( $response->content, '1; ', 'Content OK' );
80 }
d416846e 81
82 #
5882c86e 83 # Tests if the relative specification (e.g.: Chained('bar') ) works
d416846e 84 # as expected.
85 #
141459fa 86 {
87 my @expected = qw[
5882c86e 88 TestApp::Controller::Action::Chained->begin
89 TestApp::Controller::Action::Chained->bar
90 TestApp::Controller::Action::Chained->finale
91 TestApp::Controller::Action::Chained->end
141459fa 92 ];
922c58d6 93
141459fa 94 my $expected = join( ", ", @expected );
922c58d6 95
5882c86e 96 ok( my $response = request('http://localhost/chained/bar/1/spoon'), 'chained + relative endpoint' );
141459fa 97 is( $response->header('X-Catalyst-Executed'),
98 $expected, 'Executed actions' );
99 is( $response->content, '; 1, spoon', 'Content OK' );
100 }
d416846e 101
102 #
103 # Just a test for multiple arguments.
104 #
922c58d6 105 {
106 my @expected = qw[
5882c86e 107 TestApp::Controller::Action::Chained->begin
108 TestApp::Controller::Action::Chained->foo2
109 TestApp::Controller::Action::Chained->endpoint2
110 TestApp::Controller::Action::Chained->end
922c58d6 111 ];
112
113 my $expected = join( ", ", @expected );
114
5882c86e 115 ok( my $response = request('http://localhost/chained/foo2/10/20/end2/15/25'),
116 'chained + local (2 args each)' );
922c58d6 117 is( $response->header('X-Catalyst-Executed'),
118 $expected, 'Executed actions' );
119 is( $response->content, '10, 20; 15, 25', 'Content OK' );
120 }
d416846e 121
122 #
123 # The first three-chain test tries to call the action with :Args(1)
1c34f703 124 # specification. There's also a one action with a :CaptureArgs(1)
d416846e 125 # attribute, that should not be dispatched to.
126 #
922c58d6 127 {
128 my @expected = qw[
5882c86e 129 TestApp::Controller::Action::Chained->begin
130 TestApp::Controller::Action::Chained->one_end
131 TestApp::Controller::Action::Chained->end
922c58d6 132 ];
133
134 my $expected = join( ", ", @expected );
135
5882c86e 136 ok( my $response = request('http://localhost/chained/one/23'),
922c58d6 137 'three-chain (only first)' );
138 is( $response->header('X-Catalyst-Executed'),
139 $expected, 'Executed actions' );
140 is( $response->content, '; 23', 'Content OK' );
141 }
d416846e 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
1c34f703 146 # having :Args(2), not the one having :CaptureArgs(2).
d416846e 147 #
922c58d6 148 {
149 my @expected = qw[
5882c86e 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
922c58d6 154 ];
155
156 my $expected = join( ", ", @expected );
157
5882c86e 158 ok( my $response = request('http://localhost/chained/one/23/two/23/46'),
922c58d6 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 }
d416846e 164
165 #
1c34f703 166 # Last of the three-chain tests. Has no concurrent action with :CaptureArgs
d416846e 167 # and is more thought to simply test the chain as a whole and the 'two'
1c34f703 168 # action specifying :CaptureArgs.
d416846e 169 #
922c58d6 170 {
171 my @expected = qw[
5882c86e 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
922c58d6 177 ];
178
179 my $expected = join( ", ", @expected );
180
5882c86e 181 ok( my $response = request('http://localhost/chained/one/23/two/23/46/three/1/2/3'),
922c58d6 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 }
d416846e 187
188 #
189 # Tests dispatching on number of arguments for :Args. This should be
190 # dispatched to the action expecting one argument.
191 #
922c58d6 192 {
193 my @expected = qw[
5882c86e 194 TestApp::Controller::Action::Chained->begin
195 TestApp::Controller::Action::Chained->multi1
196 TestApp::Controller::Action::Chained->end
922c58d6 197 ];
198
199 my $expected = join( ", ", @expected );
200
5882c86e 201 ok( my $response = request('http://localhost/chained/multi/23'),
922c58d6 202 'multi-action (one arg)' );
203 is( $response->header('X-Catalyst-Executed'),
204 $expected, 'Executed actions' );
205 is( $response->content, '; 23', 'Content OK' );
206 }
d416846e 207
208 #
209 # Belongs to the former test and goes for the action expecting two arguments.
210 #
922c58d6 211 {
212 my @expected = qw[
5882c86e 213 TestApp::Controller::Action::Chained->begin
214 TestApp::Controller::Action::Chained->multi2
215 TestApp::Controller::Action::Chained->end
922c58d6 216 ];
217
218 my $expected = join( ", ", @expected );
219
5882c86e 220 ok( my $response = request('http://localhost/chained/multi/23/46'),
922c58d6 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 }
d416846e 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
5882c86e 234 ok( my $response = request('http://localhost/chained/multi/23/46/67'),
d416846e 235 'multi-action (three args, should lead to error)' );
236 is( $response->header('X-Catalyst-Executed'),
237 $expected, 'Executed actions' );
10ae2631 238 is( $response->code, 500, 'Status OK' );
d416846e 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[
5882c86e 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
d416846e 251 ];
252
253 my $expected = join( ", ", @expected );
254
5882c86e 255 ok( my $response = request('http://localhost/chained/higher_root/23/bar/11'),
d416846e 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[
5882c86e 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
d416846e 273 ];
274
275 my $expected = join( ", ", @expected );
276
5882c86e 277 ok( my $response = request('http://localhost/chained/pcp1/1/pcp2/2/pcp3/3'),
d416846e 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[
5882c86e 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
d416846e 293 ];
294
295 my $expected = join( ", ", @expected );
296
5882c86e 297 ok( my $response = request('http://localhost/chained/multi_cap/1/baz'),
d416846e 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[
5882c86e 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
d416846e 314 ];
315
316 my $expected = join( ", ", @expected );
317
5882c86e 318 ok( my $response = request('http://localhost/chained/multi_cap/1/2/baz'),
d416846e 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[
5882c86e 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
d416846e 335 ];
336
337 my $expected = join( ", ", @expected );
338
5882c86e 339 ok( my $response = request('http://localhost/chained/priority_a/1/end/2'),
d416846e 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[
5882c86e 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
d416846e 356 ];
357
358 my $expected = join( ", ", @expected );
359
5882c86e 360 ok( my $response = request('http://localhost/chained/priority_b/1/end/2'),
d416846e 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 #
b7ce908f 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 #
d416846e 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[
5882c86e 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
d416846e 398 ];
399
400 my $expected = join( ", ", @expected );
401
5882c86e 402 ok( my $response = request('http://localhost/chained/cross/1/end/2'),
d416846e 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 }
b25353e5 408
409 #
410 # This is for testing if the arguments got passed to the actions
411 # correctly.
412 #
413 {
414 my @expected = qw[
5882c86e 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
b25353e5 420 ];
421
422 my $expected = join( ", ", @expected );
423
5882c86e 424 ok( my $response = request('http://localhost/chained/passedargs/a/1/b/2/c/3'),
b25353e5 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 }
47f9968d 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[
5882c86e 437 TestApp::Controller::Action::Chained->begin
438 TestApp::Controller::Action::Chained->opt_args
439 TestApp::Controller::Action::Chained->end
47f9968d 440 ];
441
442 my $expected = join( ", ", @expected );
443
5882c86e 444 ok( my $response = request('http://localhost/chained/opt_args/1/2/3'),
47f9968d 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 }
9cc84996 450
451 #
452 # Tests for optional PathPart attribute.
453 #
454 {
455 my @expected = qw[
5882c86e 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
9cc84996 460 ];
461
462 my $expected = join( ", ", @expected );
463
5882c86e 464 ok( my $response = request('http://localhost/chained/optpp/1/opt_pathpart/2'),
9cc84996 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[
5882c86e 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
9cc84996 480 ];
481
482 my $expected = join( ", ", @expected );
483
5882c86e 484 ok( my $response = request('http://localhost/chained/optall/1/oa/2/3'),
9cc84996 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 }
0e853a7f 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 #
f88e7f69 511 # Test if :Chained('.') is working
0e853a7f 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 }
2349aeea 529
530 #
d64fb878 531 # Test if :Chained('../act') is working
532 #
533 {
d64fb878 534 my @expected = qw[
535 TestApp::Controller::Action::Chained->begin
93ba5ed5 536 TestApp::Controller::Action::Chained->one
d64fb878 537 TestApp::Controller::Action::Chained::ParentChain->chained_rel
538 TestApp::Controller::Action::Chained->end
539 ];
540
541 my $expected = join( ", ", @expected );
542
93ba5ed5 543 ok( my $response = request('http://localhost/chained/one/1/chained_rel/3/2'),
d64fb878 544 ":Chained('../action') chains to correct action" );
545 is( $response->header('X-Catalyst-Executed'),
546 $expected, 'Executed actions' );
547 is( $response->content, '1; 3, 2', 'Content OK' );
548 }
549
550 #
2989c763 551 # Test if ../ works to go up more than one level
552 #
553 {
554 local $TODO = 'to be coded';
555 my @expected = qw[
556 TestApp::Controller::Action::Chained->begin
557 TestApp::Controller::Action::Chained->one
558 TestApp::Controller::Action::Chained::ParentChain::Relative->chained_rel_two
559 TestApp::Controller::Action::Chained->end
560 ];
561
562 my $expected = join( ", ", @expected );
563
564 ok( my $response = request('http://localhost/chained/one/1/chained_rel_two/42/23'),
565 "../ works to go up more than one level" );
566 is( $response->header('X-Catalyst-Executed'),
567 $expected, 'Executed actions' );
568 is( $response->content, '1; 42, 23', 'Content OK' );
569 }
570
571 #
d64fb878 572 # Test if :ChainedParent is working
573 #
574 {
d64fb878 575 my @expected = qw[
576 TestApp::Controller::Action::Chained->begin
577 TestApp::Controller::Action::Chained->loose
578 TestApp::Controller::Action::Chained::ParentChain->loose
579 TestApp::Controller::Action::Chained->end
580 ];
581
582 my $expected = join( ", ", @expected );
583
584 ok( my $response = request('http://localhost/chained/loose/4/loose/a/b'),
585 ":Chained('../action') chains to correct action" );
586 is( $response->header('X-Catalyst-Executed'),
587 $expected, 'Executed actions' );
588 is( $response->content, '4; a, b', 'Content OK' );
589 }
590
591 #
592 # Test if :Chained('../name/act') is working
593 #
594 {
d64fb878 595 my @expected = qw[
596 TestApp::Controller::Action::Chained->begin
597 TestApp::Controller::Action::Chained::Bar->cross1
598 TestApp::Controller::Action::Chained::ParentChain->up_down
599 TestApp::Controller::Action::Chained->end
600 ];
601
602 my $expected = join( ", ", @expected );
603
604 ok( my $response = request('http://localhost/chained/cross/4/up_down/5'),
605 ":Chained('../action') chains to correct action" );
606 is( $response->header('X-Catalyst-Executed'),
607 $expected, 'Executed actions' );
608 is( $response->content, '4; 5', 'Content OK' );
609 }
610
611 #
2349aeea 612 # Test behaviour of auto actions returning '1' for the chain.
613 #
614 {
615 my @expected = qw[
616 TestApp::Controller::Action::Chained->begin
617 TestApp::Controller::Action::Chained::Auto->auto
618 TestApp::Controller::Action::Chained::Auto::Foo->auto
619 TestApp::Controller::Action::Chained::Auto->foo
620 TestApp::Controller::Action::Chained::Auto::Foo->fooend
621 TestApp::Controller::Action::Chained->end
622 ];
623
624 my $expected = join( ", ", @expected );
625
626 ok( my $response = request('http://localhost/chained/autochain1/1/fooend/2'),
627 "Behaviour when auto returns 1 correct" );
628 is( $response->header('X-Catalyst-Executed'),
629 $expected, 'Executed actions' );
630 is( $response->content, '1; 2', 'Content OK' );
631 }
632
633 #
634 # Test behaviour of auto actions returning '0' for the chain.
635 #
636 {
637 my @expected = qw[
638 TestApp::Controller::Action::Chained->begin
639 TestApp::Controller::Action::Chained::Auto->auto
640 TestApp::Controller::Action::Chained::Auto::Bar->auto
641 TestApp::Controller::Action::Chained->end
642 ];
643
644 my $expected = join( ", ", @expected );
645
646 ok( my $response = request('http://localhost/chained/autochain2/1/barend/2'),
647 "Behaviour when auto returns 0 correct" );
648 is( $response->header('X-Catalyst-Executed'),
649 $expected, 'Executed actions' );
650 is( $response->content, '1; 2', 'Content OK' );
651 }
652
653 #
654 # Test what auto actions are run when namespaces are changed
655 # horizontally.
656 #
657 {
658 my @expected = qw[
659 TestApp::Controller::Action::Chained->begin
660 TestApp::Controller::Action::Chained::Auto->auto
661 TestApp::Controller::Action::Chained::Auto::Foo->auto
662 TestApp::Controller::Action::Chained::Auto::Bar->crossloose
663 TestApp::Controller::Action::Chained::Auto::Foo->crossend
664 TestApp::Controller::Action::Chained->end
665 ];
666
667 my $expected = join( ", ", @expected );
668
669 ok( my $response = request('http://localhost/chained/auto_cross/1/crossend/2'),
670 "Correct auto actions are run on cross controller dispatch" );
671 is( $response->header('X-Catalyst-Executed'),
672 $expected, 'Executed actions' );
673 is( $response->content, '1; 2', 'Content OK' );
674 }
675
676 #
677 # Test forwarding from auto action in chain dispatch.
678 #
679 {
680 my @expected = qw[
681 TestApp::Controller::Action::Chained->begin
682 TestApp::Controller::Action::Chained::Auto->auto
683 TestApp::Controller::Action::Chained::Auto::Forward->auto
684 TestApp::Controller::Action::Chained::Auto->fw3
685 TestApp::Controller::Action::Chained::Auto->fw1
686 TestApp::Controller::Action::Chained::Auto::Forward->forwardend
687 TestApp::Controller::Action::Chained->end
688 ];
689
690 my $expected = join( ", ", @expected );
691
692 ok( my $response = request('http://localhost/chained/auto_forward/1/forwardend/2'),
693 "Forwarding out of auto in chain" );
694 is( $response->header('X-Catalyst-Executed'),
695 $expected, 'Executed actions' );
696 is( $response->content, '1; 2', 'Content OK' );
697 }
698
699 #
700 # Detaching out of the auto action of a chain.
701 #
702 {
703 my @expected = qw[
704 TestApp::Controller::Action::Chained->begin
705 TestApp::Controller::Action::Chained::Auto->auto
706 TestApp::Controller::Action::Chained::Auto::Detach->auto
707 TestApp::Controller::Action::Chained::Auto->fw3
708 TestApp::Controller::Action::Chained->end
709 ];
710
711 my $expected = join( ", ", @expected );
712
713 ok( my $response = request('http://localhost/chained/auto_detach/1/detachend/2'),
714 "Detaching out of auto in chain" );
715 is( $response->header('X-Catalyst-Executed'),
716 $expected, 'Executed actions' );
717 is( $response->content, '1; 2', 'Content OK' );
718 }
719
720 #
721 # Test forwarding from auto action in chain dispatch.
722 #
723 {
724 my $expected = undef;
725
726 ok( my $response = request('http://localhost/chained/loose/23'),
727 "Loose end is not callable" );
728 is( $response->header('X-Catalyst-Executed'),
729 $expected, 'Executed actions' );
10ae2631 730 is( $response->code, 500, 'Status OK' );
2349aeea 731 }
732
733 #
734 # Test forwarding out of a chain.
735 #
736 {
737 my @expected = qw[
738 TestApp::Controller::Action::Chained->begin
739 TestApp::Controller::Action::Chained->chain_fw_a
740 TestApp::Controller::Action::Chained->fw_dt_target
741 TestApp::Controller::Action::Chained->chain_fw_b
742 TestApp::Controller::Action::Chained->end
743 ];
744
745 my $expected = join( ", ", @expected );
746
747 ok( my $response = request('http://localhost/chained/chain_fw/1/end/2'),
748 "Forwarding out a chain" );
749 is( $response->header('X-Catalyst-Executed'),
750 $expected, 'Executed actions' );
751 is( $response->content, '1; 2', 'Content OK' );
752 }
753
754 #
755 # Test detaching out of a chain.
756 #
757 {
758 my @expected = qw[
759 TestApp::Controller::Action::Chained->begin
760 TestApp::Controller::Action::Chained->chain_dt_a
761 TestApp::Controller::Action::Chained->fw_dt_target
762 TestApp::Controller::Action::Chained->end
763 ];
764
765 my $expected = join( ", ", @expected );
766
767 ok( my $response = request('http://localhost/chained/chain_dt/1/end/2'),
768 "Forwarding out a chain" );
769 is( $response->header('X-Catalyst-Executed'),
770 $expected, 'Executed actions' );
771 is( $response->content, '1; 2', 'Content OK' );
772 }
8a6a6581 773
774 #
81e75875 775 # Tests that an uri_for to a chained root index action
776 # returns the right value.
777 #
778 {
779 ok( my $response = request(
780 'http://localhost/action/chained/to_root' ),
781 'uri_for with chained root action as arg' );
10ae2631 782 like( $response->content,
de19de2e 783 qr(URI:https?://[^/]+/),
81e75875 784 'Correct URI generated' );
785 }
786
787 #
8a6a6581 788 # Test interception of recursive chains. This test was added because at
789 # one point during the :Chained development, Catalyst used to hang on
790 # recursive chains.
791 #
792 {
793 eval { require 'TestAppChainedRecursive.pm' };
05a90578 794 if ($run_number == 1) {
795 ok( ! $@, "Interception of recursive chains" );
796 }
797 else { pass( "Interception of recursive chains already tested" ) }
8a6a6581 798 }
799
800 #
801 # Test failure of absolute path part arguments.
802 #
803 {
804 eval { require 'TestAppChainedAbsolutePathPart.pm' };
805 if ($run_number == 1) {
806 like( $@, qr(foo/foo),
807 "Usage of absolute path part argument emits error" );
808 }
809 else { pass( "Error on absolute path part arguments already tested" ) }
810 }
f505df49 811
812 #
caaf37ad 813 # Test chained actions in the root controller
814 #
815 {
816 my @expected = qw[
caaf37ad 817 TestApp::Controller::Action::Chained::Root->rootsub
818 TestApp::Controller::Action::Chained::Root->endpointsub
f720422c 819 TestApp->end
caaf37ad 820 ];
821
822 my $expected = join( ", ", @expected );
823
824 ok( my $response = request('http://localhost/rootsub/1/endpointsub/2'), 'chained in root namespace' );
825 is( $response->header('X-Catalyst-Executed'),
826 $expected, 'Executed actions' );
f720422c 827 is( $response->content, '', 'Content OK' );
caaf37ad 828 }
829
830 #
f505df49 831 # Complex path with multiple empty pathparts
832 #
833 {
834 my @expected = qw[
835 TestApp::Controller::Action::Chained->begin
836 TestApp::Controller::Action::Chained->mult_nopp_base
837 TestApp::Controller::Action::Chained->mult_nopp_all
838 TestApp::Controller::Action::Chained->end
839 ];
840
841 my $expected = join( ", ", @expected );
842
843 ok( my $response = request('http://localhost/chained/mult_nopp'),
844 "Complex path with multiple empty pathparts" );
845 is( $response->header('X-Catalyst-Executed'),
846 $expected, 'Executed actions' );
847 is( $response->content, '; ', 'Content OK' );
848 }
849
953c176d 850 #
851 # Higher Args() hiding more specific CaptureArgs chains sections
852 #
853 {
854 my @expected = qw[
855 TestApp::Controller::Action::Chained->begin
856 TestApp::Controller::Action::Chained->cc_base
857 TestApp::Controller::Action::Chained->cc_link
858 TestApp::Controller::Action::Chained->cc_anchor
859 TestApp::Controller::Action::Chained->end
860 ];
861
862 my $expected = join ', ', @expected;
863
864 ok( my $response = request('http://localhost/chained/choose_capture/anchor.html'),
865 'Choose between an early Args() and a later more ideal chain' );
866 is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
867 is( $response->content => '; ', 'Content OK' );
868 }
869
870 #
871 # Less specific chain not being seen correctly due to earlier looser capture
872 #
873 {
874 my @expected = qw[
875 TestApp::Controller::Action::Chained->begin
876 TestApp::Controller::Action::Chained->cc_base
877 TestApp::Controller::Action::Chained->cc_b
878 TestApp::Controller::Action::Chained->cc_b_link
879 TestApp::Controller::Action::Chained->cc_b_anchor
880 TestApp::Controller::Action::Chained->end
881 ];
882
883 my $expected = join ', ', @expected;
884
885 ok( my $response = request('http://localhost/chained/choose_capture/b/a/anchor.html'),
886 'Choose between a more specific chain and an earlier looser one' );
887 is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
888 is( $response->content => 'a; ', 'Content OK' );
889 }
890
891 #
892 # Check we get the looser one when it's the correct match
893 #
894 {
895 my @expected = qw[
896 TestApp::Controller::Action::Chained->begin
897 TestApp::Controller::Action::Chained->cc_base
898 TestApp::Controller::Action::Chained->cc_a
899 TestApp::Controller::Action::Chained->cc_a_link
900 TestApp::Controller::Action::Chained->cc_a_anchor
901 TestApp::Controller::Action::Chained->end
902 ];
903
904 my $expected = join ', ', @expected;
905
906 ok( my $response = request('http://localhost/chained/choose_capture/a/a/anchor.html'),
907 'Choose between a more specific chain and an earlier looser one' );
908 is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
909 is( $response->content => 'a; anchor.html', 'Content OK' );
910 }
911
912 #
913 # Args(0) should win over Args() if we actually have no arguments.
914 {
915 my @expected = qw[
916 TestApp::Controller::Action::Chained->begin
917 TestApp::Controller::Action::Chained::ArgsOrder->base
918 TestApp::Controller::Action::Chained::ArgsOrder->index
919 TestApp::Controller::Action::Chained::ArgsOrder->end
920 ];
921
922 my $expected = join( ", ", @expected );
923
924 # With no args, we should run "index"
925 ok( my $response = request('http://localhost/argsorder/'),
926 'Correct arg order ran' );
927 is( $response->header('X-Catalyst-Executed'),
928 $expected, 'Executed actions' );
929 is( $response->content, 'base; ; index; ', 'Content OK' );
930
931 # With args given, run "all"
932 ok( $response = request('http://localhost/argsorder/X'),
933 'Correct arg order ran' );
934 is( $response->header('X-Catalyst-Executed'),
935 join(", ",
936 qw[
937 TestApp::Controller::Action::Chained->begin
938 TestApp::Controller::Action::Chained::ArgsOrder->base
939 TestApp::Controller::Action::Chained::ArgsOrder->all
940 TestApp::Controller::Action::Chained::ArgsOrder->end
941 ])
942 );
943 is( $response->content, 'base; ; all; X', 'Content OK' );
944
945 }
6365b527 946
e5d2cfdb 947 #
948 # PathPrefix
949 #
950 {
951 my @expected = qw[
952 TestApp::Controller::Action::Chained->begin
953 TestApp::Controller::Action::Chained::PathPrefix->instance
954 TestApp::Controller::Action::Chained->end
955 ];
956
957 my $expected = join( ", ", @expected );
958
959 ok( my $response = request('http://localhost/action/chained/pathprefix/1'),
960 "PathPrefix (as an endpoint)" );
961 is( $response->header('X-Catalyst-Executed'),
962 $expected, 'Executed actions' );
963 is( $response->content, '; 1', 'Content OK' );
964 }
965
69e7f147 966 #
967 # static paths vs. captures
968 #
969 {
970 my @expected = qw[
971 TestApp::Controller::Action::Chained->begin
972 TestApp::Controller::Action::Chained->apan
973 TestApp::Controller::Action::Chained->korv
974 TestApp::Controller::Action::Chained->static_end
975 TestApp::Controller::Action::Chained->end
976 ];
977
978 my $expected = join( ", ", @expected );
979
980 ok( my $response = request('http://localhost/action/chained/static_end'),
981 "static paths are prefered over captures" );
982 is( $response->header('X-Catalyst-Executed'),
983 $expected, 'Executed actions' );
984 }
141459fa 985}