Add test for Vary header
[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 => 29;
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-5
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 my @vary_headers = $mech->response->headers->{'vary'};
24 is ((grep { 'accept' eq lc $_} @vary_headers), 1,
25     "Does not Vary on Accept headers (or sets Accept multiple times)");
26
27 $mech->add_header( Accept => 'text/html' );
28
29 # 6-8
30 $mech->get_ok('http://localhost/', 'get main page');
31 $mech->content_like(qr/it works/i, 'see if it has our text');
32 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
33   'Accept header of text/html = text/html';
34
35 $mech->add_header( Accept => 'application/xhtml+xml' );
36
37 # 9-11
38 $mech->get_ok('http://localhost/', 'get main page');
39 $mech->content_like(qr/it works/i, 'see if it has our text');
40 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
41   'Accept xhtml gives content type application/xhtml+xml';
42
43 # 12-14
44 $mech->get_ok('http://localhost/nothtml', 'get nothtml page');
45 $mech->content_like(qr/not html/i, 'see if it has our text');
46 is $mech->response->headers->{'content-type'}, 'application/json',
47   'application/json is unmolested';
48
49 # 15-17
50 $mech->add_header( Accept => 'text/html, application/xhtml+xml');
51 $mech->get_ok('http://localhost/', 'get main page');
52 $mech->content_like(qr/it works/i, 'see if it has our text');
53 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
54   'Accept xhtml AND html gives content type application/xhtml+xml';
55
56
57 # 18-20
58 $mech->add_header( Accept => 'text/html, application/xhtml+xml;q=0');
59 $mech->get_ok('http://localhost/', 'get main page');
60 $mech->content_like(qr/it works/i, 'see if it has our text');
61 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
62   'Accept header of application/xhtml+xml with q value of 0 and text/html = text/html';
63
64 # 21-23
65 $mech->add_header( Accept => 'text/html;q=0, application/xhtml+xml');
66 $mech->get_ok('http://localhost/', 'get main page');
67 $mech->content_like(qr/it works/i, 'see if it has our text');
68 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
69   'Accept html with a q value of 0 gives content type application/xhtml+xml';
70
71 # 24-26
72 $mech->add_header( Accept => '*/*');
73 $mech->get_ok('http://localhost/', 'get main page');
74 $mech->content_like(qr/it works/i, 'see if it has our text');
75 is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8',
76   'Accept */* content type text/html';
77
78 # 27-29
79 $mech->add_header( Accept => '*/*, application/xhtml+xml');
80 $mech->get_ok('http://localhost/', 'get main page');
81 $mech->content_like(qr/it works/i, 'see if it has our text');
82 is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8',
83   'Accept */* and application/xhtml+xml gives content type application/xhtml+xml';
84