first cut at :ChildOf
[catagits/Catalyst-Runtime.git] / t / live_priorities.t
CommitLineData
6ea96b03 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
7use lib "$FindBin::Bin/lib";
8
0bd5f8a2 9use Test::More tests => 28;
6ea96b03 10use Catalyst::Test 'TestApp';
11use Data::Dumper;
12
13local $^W = 0;
14
15my $uri_base = 'http://localhost/priorities';
16my @tests = (
17
18 # Simple
19 'Regex vs. Local', { path => '/re_vs_loc', expect => 'local' },
20 'Regex vs. LocalRegex', { path => '/re_vs_locre', expect => 'regex' },
21 'Regex vs. Path', { path => '/re_vs_path', expect => 'path' },
22 'Local vs. LocalRegex', { path => '/loc_vs_locre', expect => 'local' },
23 'Local vs. Path 1', { path => '/loc_vs_path1', expect => 'local' },
24 'Local vs. Path 2', { path => '/loc_vs_path2', expect => 'path' },
25 'Path vs. LocalRegex', { path => '/path_vs_locre', expect => 'path' },
26
27 # index
28 'index vs. Regex', { path => '/re_vs_index', expect => 'index' },
29 'index vs. Local', { path => '/loc_vs_index', expect => 'index' },
30 'index vs. LocalRegex', { path => '/locre_vs_index', expect => 'index' },
31 'index vs. Path', { path => '/path_vs_index', expect => 'index' },
0bd5f8a2 32
33 'multimethod zero', { path => '/multimethod', expect => 'zero' },
34 'multimethod one', { path => '/multimethod/1', expect => 'one 1' },
35 'multimethod two', { path => '/multimethod/1/2',
36 expect => 'two 1 2' },
6ea96b03 37);
38
39while ( @tests ) {
40
41 my $name = shift @tests;
42 my $data = shift @tests;
43
44 # Run tests for path with trailing slash and without
45 SKIP: for my $req_uri
46 (
47 join( '' => $uri_base, $data->{ path } ), # Without trailing path
48 join( '' => $uri_base, $data->{ path }, '/' ), # With trailing path
49 ) {
50 my $end_slash = ( $req_uri =~ qr(/$) ? 1 : 0 );
51
52 # use slash_expect argument if URI ends with slash
53 # and the slash_expect argument is defined
54 my $expect = $data->{ expect } || '';
55 if ( $end_slash and exists $data->{ slash_expect } ) {
56 $expect = $data->{ slash_expect };
57 }
58
59 # Call the URI on the TestApp
60 my $response = request( $req_uri );
61
62 # Leave expect out to see the result
63 unless ( $expect ) {
64 skip 'Nothing expected, winner is ' . $response->content, 1;
65 }
66
67 # Show error if response was no success
68 if ( not $response->is_success ) {
69 diag 'Error: ' . $response->headers->{ 'x-catalyst-error' };
70 }
71
72 # Test if content matches expectations.
73 # TODO This might flood the screen with the catalyst please-come-later
74 # page. So I don't know it is a good idea.
75 is( $response->content, $expect,
76 "$name: @{[ $data->{ expect } ]} wins"
77 . ( $end_slash ? ' (trailing slash)' : '' )
78 );
79 }
80}
81