Catalyst-Runtime

 view release on metacpan or  search on metacpan

t/aggregate/live_component_controller_action_chained.t  view on Meta::CPAN

          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;



( run in 0.487 second using v1.01-cache-2.11-cpan-e1769b4cff6 )