1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
|
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
our $iters;
BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
use Test::More;
use URI;
use URI::QueryParam;
use Catalyst::Test 'TestApp';
if ( $ENV{CAT_BENCHMARK} ) {
require Benchmark;
Benchmark::timethis( $iters, \&run_tests );
}
else {
for ( 1 .. $iters ) {
run_tests($_);
}
}
sub run_tests {
my ($run_number) = @_;
#
# This is a simple test where the parent and child actions are
# within the same controller.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->foo
TestApp::Controller::Action::Chained->endpoint
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/foo/1/end/2'), 'chained + local endpoint' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# This makes sure the above isn't found if the argument for the
# end action isn't supplied.
#
{
my $expected = undef;
ok( my $response = request('http://localhost/chained/foo/1/end'),
'chained + local endpoint; missing last argument' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->code, 500, 'Status OK' );
}
#
# Tests the case when the child action is placed in a subcontroller.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->foo
TestApp::Controller::Action::Chained::Foo->spoon
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/foo/1/spoon'), 'chained + subcontroller endpoint' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; ', 'Content OK' );
}
#
# Tests if the relative specification (e.g.: Chained('bar') ) works
# as expected.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->bar
TestApp::Controller::Action::Chained->finale
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/bar/1/spoon'), 'chained + relative endpoint' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 1, spoon', 'Content OK' );
}
#
# Just a test for multiple arguments.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->foo2
TestApp::Controller::Action::Chained->endpoint2
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/foo2/10/20/end2/15/25'),
'chained + local (2 args each)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '10, 20; 15, 25', 'Content OK' );
}
#
# The first three-chain test tries to call the action with :Args(1)
# specification. There's also a one action with a :CaptureArgs(1)
# attribute, that should not be dispatched to.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->one_end
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/one/23'),
'three-chain (only first)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 23', 'Content OK' );
}
#
# This is the second three-chain test, it goes for the action that
# handles "/one/$cap/two/$arg1/$arg2" paths. Should be the two action
# having :Args(2), not the one having :CaptureArgs(2).
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->one
TestApp::Controller::Action::Chained->two_end
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/one/23/two/23/46'),
'three-chain (up to second)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '23; 23, 46', 'Content OK' );
}
#
# Last of the three-chain tests. Has no concurrent action with :CaptureArgs
# and is more thought to simply test the chain as a whole and the 'two'
# action specifying :CaptureArgs.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->one
TestApp::Controller::Action::Chained->two
TestApp::Controller::Action::Chained->three_end
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/one/23/two/23/46/three/1/2/3'),
'three-chain (all three)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '23, 23, 46; 1, 2, 3', 'Content OK' );
}
#
# Tests dispatching on number of arguments for :Args. This should be
# dispatched to the action expecting one argument.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->multi1
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/multi/23'),
'multi-action (one arg)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 23', 'Content OK' );
}
#
# Belongs to the former test and goes for the action expecting two arguments.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->multi2
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/multi/23/46'),
'multi-action (two args)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 23, 46', 'Content OK' );
}
#
# Dispatching on argument count again, this time we provide too many
# arguments, so dispatching should fail.
#
{
my $expected = undef;
ok( my $response = request('http://localhost/chained/multi/23/46/67'),
'multi-action (three args, should lead to error)' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->code, 500, 'Status OK' );
}
#
# This tests the case when an action says it's the child of an action in
# a subcontroller.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Foo->higher_root
TestApp::Controller::Action::Chained->higher_root
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/higher_root/23/bar/11'),
'root higher than child' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '23; 11', 'Content OK' );
}
#
# Just a more complex version of the former test. It tests if a controller ->
# subcontroller -> controller dispatch works.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->pcp1
TestApp::Controller::Action::Chained::Foo->pcp2
TestApp::Controller::Action::Chained->pcp3
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/pcp1/1/pcp2/2/pcp3/3'),
'parent -> child -> parent' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1, 2; 3', 'Content OK' );
}
#
# Tests dispatch on capture number. This test is for a one capture action.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->multi_cap1
TestApp::Controller::Action::Chained->multi_cap_end1
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/multi_cap/1/baz'),
'dispatch on capture num 1' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; ', 'Content OK' );
}
#
# Belongs to the former test. This one goes for the action expecting two
# captures.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->multi_cap2
TestApp::Controller::Action::Chained->multi_cap_end2
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/multi_cap/1/2/baz'),
'dispatch on capture num 2' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1, 2; ', 'Content OK' );
}
#
# Tests the priority of a slurpy arguments action (with :Args) against
# two actions chained together. The two actions should win.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->priority_a2
TestApp::Controller::Action::Chained->priority_a2_end
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/priority_a/1/end/2'),
'priority - slurpy args vs. parent/child' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# This belongs to the former test but tests if two chained actions have
# priority over an action with the exact arguments.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->priority_b2
TestApp::Controller::Action::Chained->priority_b2_end
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/priority_b/1/end/2'),
'priority - fixed args vs. parent/child' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# This belongs to the former test but tests if two chained actions have
# priority over an action with one child action not having the Args() attr set.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->priority_c1
TestApp::Controller::Action::Chained->priority_c2_xyz
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/priority_c/1/xyz/'),
'priority - no Args() order mismatch' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; ', 'Content OK' );
}
#
# Test dispatching between two controllers that are on the same level and
# therefor have no parent/child relationship.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Bar->cross1
TestApp::Controller::Action::Chained::Foo->cross2
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/cross/1/end/2'),
'cross controller w/o par/child relation' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# This is for testing if the arguments got passed to the actions
# correctly.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::PassedArgs->first
TestApp::Controller::Action::Chained::PassedArgs->second
TestApp::Controller::Action::Chained::PassedArgs->third
TestApp::Controller::Action::Chained::PassedArgs->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/passedargs/a/1/b/2/c/3'),
'Correct arguments passed to actions' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2; 3', 'Content OK' );
}
#
# The :Args attribute is optional, we check the action not specifying
# it with these tests.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->opt_args
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/opt_args/1/2/3'),
'Optional :Args attribute working' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 1, 2, 3', 'Content OK' );
}
#
# Tests for optional PathPart attribute.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->opt_pp_start
TestApp::Controller::Action::Chained->opt_pathpart
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/optpp/1/opt_pathpart/2'),
'Optional :PathName attribute working' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Tests for optional PathPart *and* Args attributes.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->opt_all_start
TestApp::Controller::Action::Chained->oa
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/optall/1/oa/2/3'),
'Optional :PathName *and* :Args attributes working' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2, 3', 'Content OK' );
}
#
# Test if :Chained is the same as :Chained('/')
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->rootdef
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/rootdef/23'),
":Chained is the same as :Chained('/')" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 23', 'Content OK' );
}
#
# Test if :Chained('.') is working
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->parentchain
TestApp::Controller::Action::Chained::ParentChain->child
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/parentchain/1/child/2'),
":Chained('.') chains to parent controller action" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test if :Chained('../act') is working
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->one
TestApp::Controller::Action::Chained::ParentChain->chained_rel
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/one/1/chained_rel/3/2'),
":Chained('../action') chains to correct action" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 3, 2', 'Content OK' );
}
#
# Test if ../ works to go up more than one level
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->one
TestApp::Controller::Action::Chained::ParentChain::Relative->chained_rel_two
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/one/1/chained_rel_two/42/23'),
"../ works to go up more than one level" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 42, 23', 'Content OK' );
}
#
# Test if :ChainedParent is working
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->loose
TestApp::Controller::Action::Chained::ParentChain->loose
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/loose/4/loose/a/b'),
":Chained('../action') chains to correct action" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '4; a, b', 'Content OK' );
}
#
# Test if :Chained('../name/act') is working
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Bar->cross1
TestApp::Controller::Action::Chained::ParentChain->up_down
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/cross/4/up_down/5'),
":Chained('../action') chains to correct action" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '4; 5', 'Content OK' );
}
#
# Test behaviour of auto actions returning '1' for the chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Auto->auto
TestApp::Controller::Action::Chained::Auto::Foo->auto
TestApp::Controller::Action::Chained::Auto->foo
TestApp::Controller::Action::Chained::Auto::Foo->fooend
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/autochain1/1/fooend/2'),
"Behaviour when auto returns 1 correct" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test behaviour of auto actions returning '0' for the chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Auto->auto
TestApp::Controller::Action::Chained::Auto::Bar->auto
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/autochain2/1/barend/2'),
"Behaviour when auto returns 0 correct" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test what auto actions are run when namespaces are changed
# horizontally.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Auto->auto
TestApp::Controller::Action::Chained::Auto::Foo->auto
TestApp::Controller::Action::Chained::Auto::Bar->crossloose
TestApp::Controller::Action::Chained::Auto::Foo->crossend
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/auto_cross/1/crossend/2'),
"Correct auto actions are run on cross controller dispatch" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test forwarding from auto action in chain dispatch.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Auto->auto
TestApp::Controller::Action::Chained::Auto::Forward->auto
TestApp::Controller::Action::Chained::Auto->fw3
TestApp::Controller::Action::Chained::Auto->fw1
TestApp::Controller::Action::Chained::Auto::Forward->forwardend
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/auto_forward/1/forwardend/2'),
"Forwarding out of auto in chain" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Detaching out of the auto action of a chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::Auto->auto
TestApp::Controller::Action::Chained::Auto::Detach->auto
TestApp::Controller::Action::Chained::Auto->fw3
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/auto_detach/1/detachend/2'),
"Detaching out of auto in chain" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test forwarding from auto action in chain dispatch.
#
{
my $expected = undef;
ok( my $response = request('http://localhost/chained/loose/23'),
"Loose end is not callable" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->code, 500, 'Status OK' );
}
#
# Test forwarding out of a chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->chain_fw_a
TestApp::Controller::Action::Chained->fw_dt_target
TestApp::Controller::Action::Chained->chain_fw_b
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/chain_fw/1/end/2'),
"Forwarding out a chain" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test detaching out of a chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->chain_dt_a
TestApp::Controller::Action::Chained->fw_dt_target
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/chain_dt/1/end/2'),
"Forwarding out a chain" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '1; 2', 'Content OK' );
}
#
# Test throwing an error in the middle of a chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->chain_error_a
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/chain_error/1/end/2'),
"Break a chain in the middle" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, 'FATAL ERROR: break in the middle of a chain', 'Content OK' );
}
#
# Test dieing in the middle of a chain.
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->chain_die_a
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/chain_die/1/end/2'),
"Break a chain in the middle" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, 'FATAL ERROR: Caught exception in TestApp::Controller::Action::Chained->chain_die_a "die in the middle of a chain"', 'Content OK' );
}
#
# Tests that an uri_for to a chained root index action
# returns the right value.
#
{
ok( my $response = request(
'http://localhost/action/chained/to_root' ),
'uri_for with chained root action as arg' );
like( $response->content,
qr(URI:https?://[^/]+/),
'Correct URI generated' );
}
#
# Test interception of recursive chains. This test was added because at
# one point during the :Chained development, Catalyst used to hang on
# recursive chains.
#
{
eval { require 'TestAppChainedRecursive.pm' };
if ($run_number == 1) {
ok( ! $@, "Interception of recursive chains" );
}
else { pass( "Interception of recursive chains already tested" ) }
}
#
# Test failure of absolute path part arguments.
#
{
eval { require 'TestAppChainedAbsolutePathPart.pm' };
if ($run_number == 1) {
like( $@, qr(foo/foo),
"Usage of absolute path part argument emits error" );
}
else { pass( "Error on absolute path part arguments already tested" ) }
}
#
# Test chained actions in the root controller
#
{
my @expected = qw[
TestApp::Controller::Action::Chained::Root->rootsub
TestApp::Controller::Action::Chained::Root->endpointsub
TestApp::Controller::Root->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/rootsub/1/endpointsub/2'), 'chained in root namespace' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '', 'Content OK' );
}
#
# Complex path with multiple empty pathparts
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->mult_nopp_base
TestApp::Controller::Action::Chained->mult_nopp_all
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/mult_nopp'),
"Complex path with multiple empty pathparts" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; ', 'Content OK' );
}
#
# Complex path with multiple non-capturing pathparts
# PathPart('') CaptureArgs(0), PathPart('foo') CaptureArgs(0), PathPart('') Args(0)
# should win over PathPart('') CaptureArgs(1), PathPart('') Args(0)
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->mult_nopp2_base
TestApp::Controller::Action::Chained->mult_nopp2_nocap
TestApp::Controller::Action::Chained->mult_nopp2_action
TestApp::Controller::Action::Chained->mult_nopp2_action_default
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/mult_nopp2/action'),
"Complex path with multiple non-capturing pathparts" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; ', 'Content OK' );
}
#
# Higher Args() hiding more specific CaptureArgs chains sections
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->cc_base
TestApp::Controller::Action::Chained->cc_link
TestApp::Controller::Action::Chained->cc_anchor
TestApp::Controller::Action::Chained->end
];
my $expected = join ', ', @expected;
ok( my $response = request('http://localhost/chained/choose_capture/anchor.html'),
'Choose between an early Args() and a later more ideal chain' );
is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
is( $response->content => '; ', 'Content OK' );
}
#
# Less specific chain not being seen correctly due to earlier looser capture
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->cc_base
TestApp::Controller::Action::Chained->cc_b
TestApp::Controller::Action::Chained->cc_b_link
TestApp::Controller::Action::Chained->cc_b_anchor
TestApp::Controller::Action::Chained->end
];
my $expected = join ', ', @expected;
ok( my $response = request('http://localhost/chained/choose_capture/b/a/anchor.html'),
'Choose between a more specific chain and an earlier looser one' );
is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
is( $response->content => 'a; ', 'Content OK' );
}
#
# Check we get the looser one when it's the correct match
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->cc_base
TestApp::Controller::Action::Chained->cc_a
TestApp::Controller::Action::Chained->cc_a_link
TestApp::Controller::Action::Chained->cc_a_anchor
TestApp::Controller::Action::Chained->end
];
my $expected = join ', ', @expected;
ok( my $response = request('http://localhost/chained/choose_capture/a/a/anchor.html'),
'Choose between a more specific chain and an earlier looser one' );
is( $response->header('X-Catalyst-Executed') => $expected, 'Executed actions');
is( $response->content => 'a; anchor.html', 'Content OK' );
}
# CaptureArgs(1) PathPart('...') should win over CaptureArgs(2) PathPart('')
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::CaptureArgs->base
TestApp::Controller::Action::Chained::CaptureArgs->one_arg
TestApp::Controller::Action::Chained::CaptureArgs->edit_one_arg
TestApp::Controller::Action::Chained::CaptureArgs->end
];
my $expected = join( ", ", @expected );
# should dispatch to /base/one_args/edit_one_arg
ok( my $response = request('http://localhost/captureargs/one/edit'),
'Correct arg order ran' );
TODO: {
local $TODO = 'Known bug';
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, 'base; one_arg; edit_one_arg', 'Content OK' );
}
}
# PathPart('...') Args(1) should win over CaptureArgs(2) PathPart('')
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::CaptureArgs->base
TestApp::Controller::Action::Chained::CaptureArgs->test_one_arg
TestApp::Controller::Action::Chained::CaptureArgs->end
];
my $expected = join( ", ", @expected );
# should dispatch to /base/test_one_arg
ok( my $response = request('http://localhost/captureargs/test/one'),
'Correct pathpart/arg ran' );
TODO: {
local $TODO = 'Known bug';
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, 'base; test_plus_arg; one;', 'Content OK' );
}
}
#
# Args(0) should win over Args() if we actually have no arguments.
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::ArgsOrder->base
TestApp::Controller::Action::Chained::ArgsOrder->index
TestApp::Controller::Action::Chained::ArgsOrder->end
];
my $expected = join( ", ", @expected );
# With no args, we should run "index"
ok( my $response = request('http://localhost/argsorder/'),
'Correct arg order ran' );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, 'base; ; index; ', 'Content OK' );
# With args given, run "all"
ok( $response = request('http://localhost/argsorder/X'),
'Correct arg order ran' );
is( $response->header('X-Catalyst-Executed'),
join(", ",
qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::ArgsOrder->base
TestApp::Controller::Action::Chained::ArgsOrder->all
TestApp::Controller::Action::Chained::ArgsOrder->end
])
);
is( $response->content, 'base; ; all; X', 'Content OK' );
}
#
# PathPrefix
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained::PathPrefix->instance
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/action/chained/pathprefix/1'),
"PathPrefix (as an endpoint)" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
is( $response->content, '; 1', 'Content OK' );
}
#
# static paths vs. captures
#
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->apan
TestApp::Controller::Action::Chained->korv
TestApp::Controller::Action::Chained->static_end
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/action/chained/static_end'),
"static paths are prefered over captures" );
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
}
#
# */search
# doc/*
#
# request for doc/search should end up in doc/*
{
my @expected = qw[
TestApp::Controller::Action::Chained->begin
TestApp::Controller::Action::Chained->doc_star
TestApp::Controller::Action::Chained->end
];
my $expected = join( ", ", @expected );
ok( my $response = request('http://localhost/chained/doc/search'),
"we prefer static path parts earlier in the chain" );
TODO: {
local $TODO = 'gbjk never got off his ass and fixed this';
is( $response->header('X-Catalyst-Executed'),
$expected, 'Executed actions' );
}
}
{
ok( my $content =
get('http://localhost/chained/capture%2Farg%3B/return_arg/foo%2Fbar%3B'),
'request with URI-encoded arg' );
like( $content, qr{foo/bar;\z}, 'args decoded' );
like( $content, qr{capture/arg;}, 'captureargs decoded' );
}
{
ok( my $content =
get('http://localhost/chained/return_arg_decoded/foo%2Fbar%3B'),
'request with URI-encoded arg' );
like( $content, qr{foo/bar;\z}, 'args decoded' );
}
# Test round tripping, specifically the / character %2F in uri_for:
# not being able to feed it back action + captureargs and args into uri for
# and result in the original request uri is a major piece of suck ;)
foreach my $thing (
['foo', 'bar'],
['foo%2Fbar', 'baz'],
['foo', 'bar%2Fbaz'],
['foo%2Fbar', 'baz%2Fquux'],
['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz' => 'quux%2Ffrood'}],
['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz%2Ffnoo' => 'quux%2Ffrood'}],
['h%C3%BCtte', 'h%C3%BCtte', { test => 'h%C3%BCtte' } ],
) {
my $path = '/chained/roundtrip_urifor/' .
$thing->[0] . '/' . $thing->[1];
$path .= '?' . join('&',
map { $_ .'='. $thing->[2]->{$_}}
sort keys %{$thing->[2]}) if $thing->[2];
ok( my $content =
get('http://localhost/' . $path),
'request ' . $path . ' ok');
my $exp = URI->new('http://localhost:3000' . $path);
my ($want) = $content =~ m{/chained/(.*)};
my $got = URI->new('http://localhost:3000/chained/' . $want);
# Just check that the path matches, as who the hell knows or cares
# where the app is based (live tests etc)
is $got->path, $exp->path, "uri $path can round trip through uri_for (path)"
or diag("Expected $path, got $content");
is_deeply $got->query_form_hash, $exp->query_form_hash, "uri $path can round trip through uri_for (query)"
or diag("Expected $path, got $content");
}
#
# match_captures
#
{
ok( my $response = request('http://localhost/chained/match_captures/foo/bar'), 'match_captures: falling through' );
is($response->header('X-TestAppActionTestMatchCaptures'), 'fallthrough', 'match_captures: fell through');
ok($response = request('http://localhost/chained/match_captures/force/bar'), 'match_captures: *not* falling through' );
is($response->header('X-TestAppActionTestMatchCaptures'), 'forcing', 'match_captures: forced');
is($response->header('X-TestAppActionTestMatchCapturesHasRan'), 'yes', 'match_captures: actually ran');
}
}
done_testing;
|