5 use Test::More tests => 29;
11 # 1 make sure testapp works
14 # a live test against TestApp, the test application
15 use Test::WWW::Mechanize::Catalyst 'TestApp';
16 my $mech = Test::WWW::Mechanize::Catalyst->new;
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)");
27 $mech->add_header( Accept => 'text/html' );
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';
35 $mech->add_header( Accept => 'application/xhtml+xml' );
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';
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';
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';
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';
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';
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';
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';