1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
<?php
/**
* Smarty PHPunit tests for cache resource file
*
* @author Uwe Tews
*/
/**
* class for cache resource file tests
*
*
*
*
*/
class HttpModifiedSinceTest extends PHPUnit_Smarty
{
public function setUp(): void
{
$this->setUpSmarty(__DIR__);
}
/**
*
*/
public function testDisabled()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(false);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$this->smarty->display('helloworld.tpl');
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$this->assertEquals('', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
/**
*
*/
public function testEnabledUncached()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = false;
$this->smarty->cache_lifetime = 20;
ob_start();
$this->smarty->display('helloworld.tpl');
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$this->assertEquals('', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
/**
*
*/
public function testEnabledCached()
{
$_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS'] = true;
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l1 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l2 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$t1 = time();
$t2 = strtotime(substr( $_SERVER['SMARTY_PHPUNIT_HEADERS'][0],15));
$this->assertTrue(($t2-$t1) <= 1);
}
/**
*
*/
public function testEnabledCached2()
{
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() - 3600) . ' GMT';
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l3 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l4 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('hello world', $output);
$t1 = time();
$t2 = strtotime(substr( $_SERVER['SMARTY_PHPUNIT_HEADERS'][0],15));
$this->assertTrue(($t2-$t1) <= 1);
}
/**
*
*/
public function testEnabledCached3()
{
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
$_SERVER['SMARTY_PHPUNIT_HEADERS'] = array();
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = gmdate('D, d M Y H:i:s', time() + 10) . ' GMT';
$this->smarty->setCacheModifiedCheck(true);
$this->smarty->caching = true;
$this->smarty->cache_lifetime = 20;
ob_start();
$l5 = ob_get_level();
$this->smarty->display('helloworld.tpl');
$l6 = ob_get_level();
$output = ob_get_contents();
ob_end_clean();
$this->assertEquals('', $output);
$this->assertEquals('304 Not Modified', join("\r\n", $_SERVER['SMARTY_PHPUNIT_HEADERS']));
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
unset($_SERVER['SMARTY_PHPUNIT_HEADERS']);
unset($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']);
}
}
|