Commit | Line | Data |
e2e866b4 |
1 | #!/usr/bin/env perl |
2 | |
3 | use strict; |
4 | use warnings; |
c386dbe4 |
5 | use Test::More tests => 29; |
e2e866b4 |
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 | |
c386dbe4 |
18 | # 2-5 |
e2e866b4 |
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'; |
c386dbe4 |
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)"); |
e2e866b4 |
26 | |
27 | $mech->add_header( Accept => 'text/html' ); |
28 | |
c386dbe4 |
29 | # 6-8 |
e2e866b4 |
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 | |
c386dbe4 |
37 | # 9-11 |
e2e866b4 |
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 | |
c386dbe4 |
43 | # 12-14 |
e2e866b4 |
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 | |
c386dbe4 |
49 | # 15-17 |
e2e866b4 |
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 | |
c386dbe4 |
57 | # 18-20 |
e2e866b4 |
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 | |
c386dbe4 |
64 | # 21-23 |
e2e866b4 |
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 | |
c386dbe4 |
71 | # 24-26 |
e2e866b4 |
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 | |
c386dbe4 |
78 | # 27-29 |
e2e866b4 |
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 | |