fix ticketing system error on bootstrap of new install
[freeside.git] / rt / t / web / helpers-http-cache-headers.t
1 use strict;
2 use warnings;
3
4 # trs: I'd write a quick t/web/caching-headers.t file which loops the available
5 #      endpoints checking for the right headers.
6
7 use File::Find;
8
9 BEGIN {
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';
13     set_fixed_time(TIME);
14
15     use RT::Test
16         tests   => undef,
17         config  => "use Test::MockTime 'set_fixed_time'; set_fixed_time(".TIME.");";
18 }
19
20 my ($base, $m) = RT::Test->started_ok;
21 ok $m->login, 'logged in';
22
23 my $docroot = join '/', qw(share html);
24
25 # find endpoints to loop over
26 my @endpoints = (
27     "/NoAuth/css/aileron/squished-".("0"x32).".css",
28     '/static/images/bpslogo.png',
29 );
30 find({
31   wanted => sub {
32     if ( -f $_ && $_ !~ m|autohandler$| ) {
33       return if m{/\.[^/]+\.sw[op]$}; # vim swap files
34       ( my $endpoint = $_ ) =~ s|^$docroot||;
35       push @endpoints, $endpoint;
36     }
37   },
38   no_chdir => 1,
39 } => join '/', $docroot => 'Helpers');
40
41 my $ticket_id;
42 diag "create a ticket via the API";
43 {
44     my $ticket = RT::Ticket->new( RT->SystemUser );
45     my ($id, $txn, $msg) = $ticket->Create(
46         Queue => 'General',
47         Subject => 'test ticket',
48     );
49     ok $id, 'created a ticket #'. $id or diag "error: $msg";
50     is $ticket->Subject, 'test ticket', 'correct subject';
51     $ticket_id = $id;
52 }
53
54
55 my $expected;
56 diag "set up expected date headers";
57 {
58
59   # expected headers
60   $expected = {
61     Autocomplete => {
62       'Cache-Control' => 'max-age=120, private',
63       'Expires'       => 'Fri, 5 Apr 2013 15:30:19 GMT',
64     },
65     NoAuth      => {
66       'Cache-Control' => 'max-age=2592000, public',
67       'Expires'       => 'Sun, 5 May 2013 15:28:19 GMT',
68     },
69     default      => {
70       'Cache-Control' => 'no-cache',
71       'Expires'       => 'Fri, 5 Apr 2013 15:28:19 GMT',
72     },
73   };
74
75 }
76
77 foreach my $endpoint ( @endpoints ) {
78   $m->get_ok( $endpoint . "?id=${ticket_id}&Status=open&Requestor=root" );
79
80   my $header_key = 'default';
81   if ( $endpoint =~ m|Autocomplete| ) {
82     $header_key =  'Autocomplete';
83   } elsif ( $endpoint =~ m/NoAuth|static/ ) {
84     $header_key =  'NoAuth';
85   }
86   my $headers = $expected->{$header_key};
87
88   is(
89       $m->res->header('Cache-Control') => $headers->{'Cache-Control'},
90       'got expected Cache-Control header'
91   );
92
93   is(
94     $m->res->header('Expires') => $headers->{'Expires'},
95     'got expected Expires header'
96   );
97 }
98
99 undef $m;
100 done_testing;