File: 005_mode_param_from_path_info.t

package info (click to toggle)
libcgi-application-server-perl 0.062-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 164 kB
  • ctags: 23
  • sloc: perl: 548; makefile: 4
file content (59 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

use strict;
use warnings;
use Test::More tests => 5;
use Test::WWW::Mechanize;
use CGI::Application::Server;

{
    package TestApp;
    use base 'CGI::Application';
    
    sub setup {
        my ($self) = @_;
        
        $self->mode_param(path_info => 1);
        $self->run_modes([qw/ foo bar /]);        
    }

    sub foo {
        my ($self) = @_;
        
        return '<HTML><HEAD><TITLE>Hello world!</TITLE></HEAD>'
            . '<BODY><H1>Hello world!</H1><HR></BODY></HTML>';
    }
                                                        
    sub bar {
        my ($self) = @_;
        
        return '<HTML><HEAD><TITLE>Goodbye world!</TITLE></HEAD>'
            . '<BODY><H1>Goodbye world!</H1><HR></BODY></HTML>';
    }
                                                        
}    
    
{
    package TestServer;
    use base qw/
        Test::HTTP::Server::Simple
        CGI::Application::Server
    /;
}

my $port = $ENV{CGI_APP_SERVER_TEST_PORT} || 40000 + int(rand(10000));

my $server = TestServer->new($port);
$server->entry_points({
    '/index.cgi'         => 'TestApp',
});
my $url_root = $server->started_ok("start up my web server");

my $mech = Test::WWW::Mechanize->new();

$mech->get_ok($url_root . '/index.cgi/foo', '...got run mode foo');
$mech->title_is('Hello world!', '... got the right page title for foo');

$mech->get_ok($url_root . '/index.cgi/bar', '...got run mode bar');
$mech->title_is('Goodbye world!', '... got the right page title for bar');