mirror of
https://github.com/mrclay/minify.git
synced 2025-08-09 15:46:34 +02:00
port HTTPConditionalGetTest
This commit is contained in:
committed by
Steve Clay
parent
3a9687ad4e
commit
8816e270e6
@@ -3,5 +3,4 @@
|
||||
require 'test_Minify.php';
|
||||
require 'test_Minify_CSS.php';
|
||||
require 'test_Minify_Lines.php';
|
||||
require 'test_HTTP_ConditionalGet.php';
|
||||
require 'test_environment.php';
|
||||
|
@@ -1,15 +1,22 @@
|
||||
<?php
|
||||
require_once '_inc.php';
|
||||
|
||||
function test_HTTP_ConditionalGet()
|
||||
class HTTPConditionalGetTest extends TestCase
|
||||
{
|
||||
global $thisDir;
|
||||
|
||||
$lmTime = time() - 900;
|
||||
$gmtTime = gmdate('D, d M Y H:i:s \G\M\T', $lmTime);
|
||||
|
||||
public function TestData()
|
||||
{
|
||||
/*
|
||||
* NOTE: calculate $lmTime as parameter
|
||||
* because dataProviders are executed before tests run,
|
||||
* and in fact each test is new instance of the class, so can't share data
|
||||
* other than parameters.
|
||||
*/
|
||||
|
||||
$lmTime = time() - 900;
|
||||
$gmtTime = gmdate('D, d M Y H:i:s \G\M\T', $lmTime);
|
||||
|
||||
$tests = array(
|
||||
array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'client has valid If-Modified-Since'
|
||||
,'inm' => null
|
||||
,'ims' => $gmtTime
|
||||
@@ -23,6 +30,7 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
,array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'client has valid If-Modified-Since with trailing semicolon'
|
||||
,'inm' => null
|
||||
,'ims' => $gmtTime . ';'
|
||||
@@ -36,6 +44,7 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
,array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'client has valid ETag (non-encoded version)'
|
||||
,'inm' => "\"badEtagFoo\", \"pri{$lmTime}\""
|
||||
,'ims' => null
|
||||
@@ -49,6 +58,7 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
,array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'client has valid ETag (gzip version)'
|
||||
,'inm' => "\"badEtagFoo\", \"pri{$lmTime};gz\""
|
||||
,'ims' => null
|
||||
@@ -62,6 +72,7 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
,array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'no conditional get'
|
||||
,'inm' => null
|
||||
,'ims' => null
|
||||
@@ -74,6 +85,7 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
,array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'client has invalid ETag'
|
||||
,'inm' => '"pri' . ($lmTime - 300) . '"'
|
||||
,'ims' => null
|
||||
@@ -86,6 +98,7 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
,array(
|
||||
'lm' => $lmTime,
|
||||
'desc' => 'client has invalid If-Modified-Since'
|
||||
,'inm' => null
|
||||
,'ims' => gmdate('D, d M Y H:i:s \G\M\T', $lmTime - 300)
|
||||
@@ -98,38 +111,37 @@ function test_HTTP_ConditionalGet()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($tests as $test) {
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider TestData
|
||||
*/
|
||||
public function test_HTTP_ConditionalGet($lmTime, $desc, $inm, $ims, $exp)
|
||||
{
|
||||
|
||||
// setup env
|
||||
if (null === $test['inm']) {
|
||||
if (null === $inm) {
|
||||
unset($_SERVER['HTTP_IF_NONE_MATCH']);
|
||||
} else {
|
||||
$_SERVER['HTTP_IF_NONE_MATCH'] = get_magic_quotes_gpc()
|
||||
? addslashes($test['inm'])
|
||||
: $test['inm'];
|
||||
? addslashes($inm) :
|
||||
$inm;
|
||||
}
|
||||
if (null === $test['ims']) {
|
||||
|
||||
if (null === $ims) {
|
||||
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
||||
} else {
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $test['ims'];
|
||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $ims;
|
||||
}
|
||||
$exp = $test['exp'];
|
||||
|
||||
|
||||
$cg = new HTTP_ConditionalGet(array(
|
||||
'lastModifiedTime' => $lmTime
|
||||
,'encoding' => 'x-gzip'
|
||||
'lastModifiedTime' => $lmTime,
|
||||
'encoding' => 'x-gzip',
|
||||
));
|
||||
$ret = $cg->getHeaders();
|
||||
$ret['isValid'] = $cg->cacheIsValid;
|
||||
|
||||
$passed = assertTrue($exp == $ret, 'HTTP_ConditionalGet : ' . $test['desc']);
|
||||
|
||||
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
|
||||
echo "\n--- INM = {$test['inm']} / IMS = {$test['ims']}\n";
|
||||
echo "Expected = " . preg_replace('/\\s+/', ' ', var_export($exp, 1)) . "\n";
|
||||
echo "Returned = " . preg_replace('/\\s+/', ' ', var_export($ret, 1)) . "\n\n";
|
||||
}
|
||||
|
||||
$this->assertEquals($exp, $ret, $desc);
|
||||
}
|
||||
}
|
||||
|
||||
test_HTTP_ConditionalGet();
|
Reference in New Issue
Block a user