File: catalyst-action-rest-action-dispatch-for-browsers.t

package info (click to toggle)
libcatalyst-action-rest-perl 1.21-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 476 kB
  • sloc: perl: 1,750; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,140 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;
use Test::More;
use FindBin;

use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
use Test::Rest;

my $t = Test::Rest->new( 'content_type' => 'text/plain' );

use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';

my $url = '/actionsforbrowsers/for_browsers';

foreach my $method (qw(GET POST)) {
    my $run_method = lc($method);
    my $result     = "something $method";
    my $res;
    if ( $method eq 'GET' ) {
        $res = request( $t->$run_method( url => $url ) );
    } else {
        $res = request(
            $t->$run_method(
                url  => $url,
                data => '',
            )
        );
    }
    ok( $res->is_success, "$method request succeeded" );
    is(
        $res->content,
        "$method",
        "$method request had proper response"
    );
}

my $res = request(
    $t->get(
        url     => $url,
        headers => { Accept => 'text/html' },
    )
);

ok( $res->is_success, "GET request succeeded (client looks like browser)" );
is(
    $res->content,
    "GET_html",
    "GET request had proper response (client looks like browser)"
);

done_testing;