Unfuck merge, I should stick with adding docs when I'm shattered
[catagits/Catalyst-View-ContentNegotiation-XHTML.git] / t / live-test.t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 28;
6
7 # setup library path
8 use FindBin qw($Bin);
9 use lib "$Bin/lib";
10
11 # 1 make sure testapp works
12 use_ok 'TestApp';
13
14 # a live test against TestApp, the test application
15 use Test::WWW::Mechanize::Catalyst 'TestApp';
16 my $mech = Test::WWW::Mechanize::Catalyst->new;
17
18 # 2-4
19 $mech->get_ok('http://localhost/', 'get main page');
20 $mech->content_like(qr/it works/i, 'see if it has our text');
21 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
22   'No Accept header = text/html';
23
24 $mech->add_header( Accept => 'text/html' );
25
26 # 5-7
27 $mech->get_ok('http://localhost/', 'get main page');
28 $mech->content_like(qr/it works/i, 'see if it has our text');
29 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
30   'Accept header of text/html = text/html';
31
32 $mech->add_header( Accept => 'application/xhtml+xml' );
33
34 # 8-10
35 $mech->get_ok('http://localhost/', 'get main page');
36 $mech->content_like(qr/it works/i, 'see if it has our text');
37 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
38   'Accept xhtml gives content type application/xhtml+xml';
39
40 # 11-13
41 $mech->get_ok('http://localhost/nothtml', 'get nothtml page');
42 $mech->content_like(qr/not html/i, 'see if it has our text');
43 is $mech->response->headers->{'content-type'}, 'application/json',
44   'application/json is unmolested';
45
46 # 14-16
47 $mech->add_header( Accept => 'text/html, application/xhtml+xml');
48 $mech->get_ok('http://localhost/', 'get main page');
49 $mech->content_like(qr/it works/i, 'see if it has our text');
50 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
51   'Accept xhtml AND html gives content type application/xhtml+xml';
52
53
54 # 17-19
55 $mech->add_header( Accept => 'text/html, application/xhtml+xml;q=0');
56 $mech->get_ok('http://localhost/', 'get main page');
57 $mech->content_like(qr/it works/i, 'see if it has our text');
58 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
59   'Accept header of application/xhtml+xml with q value of 0 and text/html = text/html';
60
61 # 20-22
62 $mech->add_header( Accept => 'text/html;q=0, application/xhtml+xml');
63 $mech->get_ok('http://localhost/', 'get main page');
64 $mech->content_like(qr/it works/i, 'see if it has our text');
65 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
66   'Accept html with a q value of 0 gives content type application/xhtml+xml';
67
68 # 23-25
69 $mech->add_header( Accept => '*/*');
70 $mech->get_ok('http://localhost/', 'get main page');
71 $mech->content_like(qr/it works/i, 'see if it has our text');
72 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
73   'Accept */* content type text/html';
74
75 # 26-28
76 $mech->add_header( Accept => '*/*, application/xhtml+xml');
77 $mech->get_ok('http://localhost/', 'get main page');
78 $mech->content_like(qr/it works/i, 'see if it has our text');
79 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
80   'Accept */* and application/xhtml+xml gives content type application/xhtml+xml';
81