Add mech testing in from the branch I previously made. 5 of the URIs which we test...
[catagits/Gitalist.git] / t / lib / TestGitalist.pm
CommitLineData
6dac2638 1package TestGitalist;
2use strict;
3use warnings;
4use Exporter qw/import/;
5use Catalyst::Test qw/Gitalist/;
6use Test::More;
7
8our @EXPORT = qw/
9 test_uri
10 curry_test_uri
11/;
12
13use constant ();
14BEGIN {
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
22sub 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
38sub 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
471;