File: 003_dispatch.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 (83 lines) | stat: -rw-r--r-- 2,227 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl

use strict;
use warnings;

use lib 't/lib/';

use Test::More;

use Test::Exception;
use Test::HTTP::Server::Simple;
use Test::WWW::Mechanize;

unless (eval "require CGI::Application::Dispatch; 1") {
  plan skip_all => "CGI::Application::Dispatch required for these tests";
} else {
  plan tests => 19;
}

use_ok('CGI::Application::Server');
use_ok('MyCGIApp');
use_ok('MyCGIApp::Dispatch');

{
    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);
isa_ok($server, 'CGI::Application::Server');
isa_ok($server, 'HTTP::Server::Simple');

is_deeply($server->entry_points, {}, '... no entry-point yet');
$server->entry_points({
    '/index.cgi' => 'MyCGIApp',
    '/bar'       => 'MyCGIApp::Dispatch',
});

is_deeply(
  $server->entry_points,
  {
    '/index.cgi' => 'MyCGIApp',
    '/bar'       => 'MyCGIApp::Dispatch',
  },
  '... we have an entry point now',
);

$server->document_root('./t/htdocs');
is($server->document_root, './t/htdocs', '... got the new server root');

# ignore the warnings for now, 
# they are too hard to test really
local $SIG{__WARN__} = sub { 1 };

my $url_root = $server->started_ok("start up my web server");

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

# test our static index page

$mech->get_ok($url_root.'/index.html', '... got the index.html page okay');
$mech->title_is('Test Static Index Page', '... got the right page title for index.html');

# test out entry point page

$mech->get_ok($url_root.'/index.cgi', '... got the index.cgi page start-point okay');
$mech->title_is('Hello', '... got the right page title for index.cgi');

# test with query params

$mech->get_ok($url_root.'/bar/foo/mode1', '... got mode1 via dispatch');
$mech->title_is('Hello', '... got the right page title for mode1 (hello)');

$mech->get_ok($url_root.'/bar/foo/mode2', '... got mode2 via dispatch');
$mech->title_is('Goodbye', '... got the right page title for mode2 (bye)');

$mech->get_ok($url_root.'/bar/foo/mode3', '... got mode3, get redir');
$mech->title_is('Redirect End', '... got the right page title for mode4');