diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-09-15 20:44:48 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-09-15 20:44:48 -0700 |
commit | ed1f84b4e8f626245995ecda5afcf83092c153b2 (patch) | |
tree | 3f58bbef5fbf2502e65d29b37b5dbe537519e89d /rt/t/web/helpers-http-cache-headers.t | |
parent | fe9ea9183e8a16616d6d04a7b5c7498d28e78248 (diff) |
RT 4.0.22
Diffstat (limited to 'rt/t/web/helpers-http-cache-headers.t')
-rw-r--r-- | rt/t/web/helpers-http-cache-headers.t | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/rt/t/web/helpers-http-cache-headers.t b/rt/t/web/helpers-http-cache-headers.t new file mode 100644 index 000000000..1731e9d17 --- /dev/null +++ b/rt/t/web/helpers-http-cache-headers.t @@ -0,0 +1,96 @@ +use strict; +use warnings; + +# trs: I'd write a quick t/web/caching-headers.t file which loops the available +# endpoints checking for the right headers. + +use File::Find; + +BEGIN { + # Ensure that the test and server processes use the same fixed time. + use constant TIME => 1365175699; + use Test::MockTime 'set_fixed_time'; + set_fixed_time(TIME); + + use RT::Test + tests => undef, + config => "use Test::MockTime 'set_fixed_time'; set_fixed_time(".TIME.");"; +} + +my ($base, $m) = RT::Test->started_ok; +ok $m->login, 'logged in'; + +my $docroot = join '/', qw(share html); + +# find endpoints to loop over +my @endpoints = ('/NoAuth/css/print.css'); +find({ + wanted => sub { + if ( -f $_ && $_ !~ m|autohandler$| ) { + ( my $endpoint = $_ ) =~ s|^$docroot||; + push @endpoints, $endpoint; + } + }, + no_chdir => 1, +} => join '/', $docroot => 'Helpers'); + +my $ticket_id; +diag "create a ticket via the API"; +{ + my $ticket = RT::Ticket->new( RT->SystemUser ); + my ($id, $txn, $msg) = $ticket->Create( + Queue => 'General', + Subject => 'test ticket', + ); + ok $id, 'created a ticket #'. $id or diag "error: $msg"; + is $ticket->Subject, 'test ticket', 'correct subject'; + $ticket_id = $id; +} + + +my $expected; +diag "set up expected date headers"; +{ + + # expected headers + $expected = { + Autocomplete => { + 'Cache-Control' => 'max-age=120, private', + 'Expires' => 'Fri, 5 Apr 2013 15:30:19 GMT', + }, + NoAuth => { + 'Cache-Control' => 'max-age=2592000, public', + 'Expires' => 'Sun, 5 May 2013 15:28:19 GMT', + }, + default => { + 'Cache-Control' => 'no-cache', + 'Expires' => 'Fri, 5 Apr 2013 15:28:19 GMT', + }, + }; + +} + +foreach my $endpoint ( @endpoints ) { + $m->get_ok( $endpoint . "?id=${ticket_id}&Status=open&Requestor=root" ); + + my $header_key = 'default'; + if ( $endpoint =~ m|Autocomplete| ) { + $header_key = 'Autocomplete'; + } elsif ( $endpoint =~ m|NoAuth| ) { + $header_key = 'NoAuth'; + } + my $headers = $expected->{$header_key}; + + is( + $m->res->header('Cache-Control') => $headers->{'Cache-Control'}, + 'got expected Cache-Control header' + ); + + is( + $m->res->header('Expires') => $headers->{'Expires'}, + 'got expected Expires header' + ); +} + +undef $m; +done_testing; |