4 # trs: I'd write a quick t/web/caching-headers.t file which loops the available
5 # endpoints checking for the right headers.
10 # Ensure that the test and server processes use the same fixed time.
11 use constant TIME => 1365175699;
12 use Test::MockTime 'set_fixed_time';
17 config => "use Test::MockTime 'set_fixed_time'; set_fixed_time(".TIME.");";
20 my ($base, $m) = RT::Test->started_ok;
21 ok $m->login, 'logged in';
23 my $docroot = join '/', qw(share html);
25 # find endpoints to loop over
27 "/NoAuth/css/aileron/squished-".("0"x32).".css",
28 '/static/images/bpslogo.png',
32 if ( -f $_ && $_ !~ m|autohandler$| ) {
33 return if m{/\.[^/]+\.sw[op]$}; # vim swap files
34 ( my $endpoint = $_ ) =~ s|^$docroot||;
35 push @endpoints, $endpoint;
39 } => join '/', $docroot => 'Helpers');
42 diag "create a ticket via the API";
44 my $ticket = RT::Ticket->new( RT->SystemUser );
45 my ($id, $txn, $msg) = $ticket->Create(
47 Subject => 'test ticket',
49 ok $id, 'created a ticket #'. $id or diag "error: $msg";
50 is $ticket->Subject, 'test ticket', 'correct subject';
56 diag "set up expected date headers";
62 'Cache-Control' => 'max-age=120, private',
63 'Expires' => 'Fri, 5 Apr 2013 15:30:19 GMT',
66 'Cache-Control' => 'max-age=2592000, public',
67 'Expires' => 'Sun, 5 May 2013 15:28:19 GMT',
70 'Cache-Control' => 'no-cache',
71 'Expires' => 'Fri, 5 Apr 2013 15:28:19 GMT',
77 foreach my $endpoint ( @endpoints ) {
78 $m->get_ok( $endpoint . "?id=${ticket_id}&Status=open&Requestor=root" );
80 my $header_key = 'default';
81 if ( $endpoint =~ m|Autocomplete| ) {
82 $header_key = 'Autocomplete';
83 } elsif ( $endpoint =~ m/NoAuth|static/ ) {
84 $header_key = 'NoAuth';
86 my $headers = $expected->{$header_key};
89 $m->res->header('Cache-Control') => $headers->{'Cache-Control'},
90 'got expected Cache-Control header'
94 $m->res->header('Expires') => $headers->{'Expires'},
95 'got expected Expires header'