From: David Dorward Date: Thu, 17 Sep 2009 19:38:09 +0000 (+0100) Subject: Add test for Vary header X-Git-Tag: 1.102~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c386dbe407678c058330b0ec4d4db1ae035bbf1b;hp=d763a58ddf4bc459216bf08131b3ac48c8475726;p=catagits%2FCatalyst-View-ContentNegotiation-XHTML.git Add test for Vary header As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44, HTTP headers for resources that vary based on request headers should specify this fact in a Vary header. --- diff --git a/t/live-test.t b/t/live-test.t index aba365a..afed51b 100644 --- a/t/live-test.t +++ b/t/live-test.t @@ -2,7 +2,7 @@ use strict; use warnings; -use Test::More tests => 28; +use Test::More tests => 29; # setup library path use FindBin qw($Bin); @@ -15,15 +15,18 @@ use_ok 'TestApp'; use Test::WWW::Mechanize::Catalyst 'TestApp'; my $mech = Test::WWW::Mechanize::Catalyst->new; -# 2-4 +# 2-5 $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8', 'No Accept header = text/html'; +my @vary_headers = $mech->response->headers->{'vary'}; +is ((grep { 'accept' eq lc $_} @vary_headers), 1, + "Does not Vary on Accept headers (or sets Accept multiple times)"); $mech->add_header( Accept => 'text/html' ); -# 5-7 +# 6-8 $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8', @@ -31,19 +34,19 @@ is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8', $mech->add_header( Accept => 'application/xhtml+xml' ); -# 8-10 +# 9-11 $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8', 'Accept xhtml gives content type application/xhtml+xml'; -# 11-13 +# 12-14 $mech->get_ok('http://localhost/nothtml', 'get nothtml page'); $mech->content_like(qr/not html/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'application/json', 'application/json is unmolested'; -# 14-16 +# 15-17 $mech->add_header( Accept => 'text/html, application/xhtml+xml'); $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); @@ -51,28 +54,28 @@ is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=u 'Accept xhtml AND html gives content type application/xhtml+xml'; -# 17-19 +# 18-20 $mech->add_header( Accept => 'text/html, application/xhtml+xml;q=0'); $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8', 'Accept header of application/xhtml+xml with q value of 0 and text/html = text/html'; -# 20-22 +# 21-23 $mech->add_header( Accept => 'text/html;q=0, application/xhtml+xml'); $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'application/xhtml+xml; charset=utf-8', 'Accept html with a q value of 0 gives content type application/xhtml+xml'; -# 23-25 +# 24-26 $mech->add_header( Accept => '*/*'); $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text'); is $mech->response->headers->{'content-type'}, 'text/html; charset=utf-8', 'Accept */* content type text/html'; -# 26-28 +# 27-29 $mech->add_header( Accept => '*/*, application/xhtml+xml'); $mech->get_ok('http://localhost/', 'get main page'); $mech->content_like(qr/it works/i, 'see if it has our text');