File: live_component_controller_action_index.t

package info (click to toggle)
libcatalyst-perl 5.90132-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,016 kB
  • sloc: perl: 11,061; makefile: 7
file content (98 lines) | stat: -rw-r--r-- 3,269 bytes parent folder | download | duplicates (6)
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
use strict;
use warnings;

use FindBin;
use lib "$FindBin::Bin/../lib";

our $iters;

BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }

use Test::More tests => 20*$iters;
use Catalyst::Test 'TestApp';

if ( $ENV{CAT_BENCHMARK} ) {
    require Benchmark;
    Benchmark::timethis( $iters, \&run_tests );
}
else {
    for ( 1 .. $iters ) {
        run_tests();
    }
}

sub run_tests {
    # test root index
    {
        my @expected = qw[
          TestApp::Controller::Root->index
          TestApp::Controller::Root->end
        ];

        my $expected = join( ", ", @expected );
        ok( my $response = request('http://localhost/'), 'root index' );
        is( $response->header('X-Catalyst-Executed'),
            $expected, 'Executed actions' );
        is( $response->content, 'root index', 'root index ok' );

        ok( $response = request('http://localhost'), 'root index no slash' );
        is( $response->content, 'root index', 'root index no slash ok' );
    }

    # test first-level controller index
    {
        my @expected = qw[
          TestApp::Controller::Index->index
          TestApp::Controller::Root->end
        ];

        my $expected = join( ", ", @expected );

        ok( my $response = request('http://localhost/index/'), 'first-level controller index' );
        is( $response->header('X-Catalyst-Executed'),
            $expected, 'Executed actions' );
        is( $response->content, 'Index index', 'first-level controller index ok' );

        ok( $response = request('http://localhost/index'), 'first-level controller index no slash' );
        is( $response->header('X-Catalyst-Executed'),
            $expected, 'Executed actions' );
        is( $response->content, 'Index index', 'first-level controller index no slash ok' );
    }

    # test second-level controller index
    {
        my @expected = qw[
          TestApp::Controller::Action::Index->begin
          TestApp::Controller::Action::Index->index
          TestApp::Controller::Root->end
        ];

        my $expected = join( ", ", @expected );

        ok( my $response = request('http://localhost/action/index/'), 'second-level controller index' );
        is( $response->header('X-Catalyst-Executed'),
            $expected, 'Executed actions' );
        is( $response->content, 'Action-Index index', 'second-level controller index ok' );

        ok( $response = request('http://localhost/action/index'), 'second-level controller index no slash' );
        is( $response->header('X-Catalyst-Executed'),
            $expected, 'Executed actions' );
        is( $response->content, 'Action-Index index', 'second-level controller index no slash ok' );
    }

    # test controller default when index is present
    {
        my @expected = qw[
          TestApp::Controller::Action::Index->begin
          TestApp::Controller::Action::Index->default
          TestApp::Controller::Root->end
        ];

        my $expected = join( ", ", @expected );

        ok( my $response = request('http://localhost/action/index/foo'), 'default with index' );
        is( $response->header('X-Catalyst-Executed'),
            $expected, 'Executed actions' );
        is( $response->content, "Error - TestApp::Controller::Action\n", 'default with index ok' );
    }
}