Commit | Line | Data |
6dac2638 |
1 | package TestGitalist; |
2 | use strict; |
3 | use warnings; |
4 | use Exporter qw/import/; |
5 | use Catalyst::Test qw/Gitalist/; |
6 | use Test::More; |
7 | |
8 | our @EXPORT = qw/ |
9 | test_uri |
10 | curry_test_uri |
11 | /; |
12 | |
13 | use constant (); |
14 | BEGIN { |
15 | my $mech = eval { |
16 | require Test::WWW::Mechanize::Catalyst; |
17 | Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'Gitalist') |
18 | }; |
19 | constant->import('MECH', $mech ); |
20 | } |
21 | |
22 | sub test_uri { |
23 | my ($uri, $qs) = @_; |
24 | $qs ||= ''; |
25 | my $request = "/$uri"; |
26 | $request .= "?$qs" if defined $qs; |
27 | my $response = request($request); |
28 | ok($response->is_success, "ok $uri - $qs"); |
29 | if (MECH) { |
30 | my $res = MECH()->get($request); |
31 | ok $res->is_success, "ok mech $uri - $qs (" . $res->code . ')'; |
32 | MECH()->page_links_ok() |
33 | if $res->content_type =~ m|text/html|; |
34 | } |
35 | return $response; |
36 | } |
37 | |
38 | sub curry_test_uri { |
39 | my $prefix = shift; |
40 | my $to_curry = shift || \&test_uri; |
41 | sub { |
42 | my $uri = shift; |
43 | $to_curry->("$prefix/$uri", @_); |
44 | }; |
45 | } |
46 | |
47 | 1; |