mirror of
https://github.com/mrclay/minify.git
synced 2025-08-09 23:56:43 +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.php';
|
||||||
require 'test_Minify_CSS.php';
|
require 'test_Minify_CSS.php';
|
||||||
require 'test_Minify_Lines.php';
|
require 'test_Minify_Lines.php';
|
||||||
require 'test_HTTP_ConditionalGet.php';
|
|
||||||
require 'test_environment.php';
|
require 'test_environment.php';
|
||||||
|
@@ -1,15 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once '_inc.php';
|
|
||||||
|
|
||||||
function test_HTTP_ConditionalGet()
|
class HTTPConditionalGetTest extends TestCase
|
||||||
{
|
{
|
||||||
global $thisDir;
|
public function TestData()
|
||||||
|
{
|
||||||
$lmTime = time() - 900;
|
/*
|
||||||
$gmtTime = gmdate('D, d M Y H:i:s \G\M\T', $lmTime);
|
* 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(
|
$tests = array(
|
||||||
array(
|
array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'client has valid If-Modified-Since'
|
'desc' => 'client has valid If-Modified-Since'
|
||||||
,'inm' => null
|
,'inm' => null
|
||||||
,'ims' => $gmtTime
|
,'ims' => $gmtTime
|
||||||
@@ -23,6 +30,7 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
,array(
|
,array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'client has valid If-Modified-Since with trailing semicolon'
|
'desc' => 'client has valid If-Modified-Since with trailing semicolon'
|
||||||
,'inm' => null
|
,'inm' => null
|
||||||
,'ims' => $gmtTime . ';'
|
,'ims' => $gmtTime . ';'
|
||||||
@@ -36,6 +44,7 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
,array(
|
,array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'client has valid ETag (non-encoded version)'
|
'desc' => 'client has valid ETag (non-encoded version)'
|
||||||
,'inm' => "\"badEtagFoo\", \"pri{$lmTime}\""
|
,'inm' => "\"badEtagFoo\", \"pri{$lmTime}\""
|
||||||
,'ims' => null
|
,'ims' => null
|
||||||
@@ -49,6 +58,7 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
,array(
|
,array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'client has valid ETag (gzip version)'
|
'desc' => 'client has valid ETag (gzip version)'
|
||||||
,'inm' => "\"badEtagFoo\", \"pri{$lmTime};gz\""
|
,'inm' => "\"badEtagFoo\", \"pri{$lmTime};gz\""
|
||||||
,'ims' => null
|
,'ims' => null
|
||||||
@@ -62,6 +72,7 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
,array(
|
,array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'no conditional get'
|
'desc' => 'no conditional get'
|
||||||
,'inm' => null
|
,'inm' => null
|
||||||
,'ims' => null
|
,'ims' => null
|
||||||
@@ -74,6 +85,7 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
,array(
|
,array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'client has invalid ETag'
|
'desc' => 'client has invalid ETag'
|
||||||
,'inm' => '"pri' . ($lmTime - 300) . '"'
|
,'inm' => '"pri' . ($lmTime - 300) . '"'
|
||||||
,'ims' => null
|
,'ims' => null
|
||||||
@@ -86,6 +98,7 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
,array(
|
,array(
|
||||||
|
'lm' => $lmTime,
|
||||||
'desc' => 'client has invalid If-Modified-Since'
|
'desc' => 'client has invalid If-Modified-Since'
|
||||||
,'inm' => null
|
,'inm' => null
|
||||||
,'ims' => gmdate('D, d M Y H:i:s \G\M\T', $lmTime - 300)
|
,'ims' => gmdate('D, d M Y H:i:s \G\M\T', $lmTime - 300)
|
||||||
@@ -98,38 +111,37 @@ function test_HTTP_ConditionalGet()
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
return $tests;
|
||||||
foreach ($tests as $test) {
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider TestData
|
||||||
|
*/
|
||||||
|
public function test_HTTP_ConditionalGet($lmTime, $desc, $inm, $ims, $exp)
|
||||||
|
{
|
||||||
|
|
||||||
// setup env
|
// setup env
|
||||||
if (null === $test['inm']) {
|
if (null === $inm) {
|
||||||
unset($_SERVER['HTTP_IF_NONE_MATCH']);
|
unset($_SERVER['HTTP_IF_NONE_MATCH']);
|
||||||
} else {
|
} else {
|
||||||
$_SERVER['HTTP_IF_NONE_MATCH'] = get_magic_quotes_gpc()
|
$_SERVER['HTTP_IF_NONE_MATCH'] = get_magic_quotes_gpc()
|
||||||
? addslashes($test['inm'])
|
? addslashes($inm) :
|
||||||
: $test['inm'];
|
$inm;
|
||||||
}
|
}
|
||||||
if (null === $test['ims']) {
|
|
||||||
|
if (null === $ims) {
|
||||||
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
|
||||||
} else {
|
} else {
|
||||||
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $test['ims'];
|
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $ims;
|
||||||
}
|
}
|
||||||
$exp = $test['exp'];
|
|
||||||
|
|
||||||
$cg = new HTTP_ConditionalGet(array(
|
$cg = new HTTP_ConditionalGet(array(
|
||||||
'lastModifiedTime' => $lmTime
|
'lastModifiedTime' => $lmTime,
|
||||||
,'encoding' => 'x-gzip'
|
'encoding' => 'x-gzip',
|
||||||
));
|
));
|
||||||
$ret = $cg->getHeaders();
|
$ret = $cg->getHeaders();
|
||||||
$ret['isValid'] = $cg->cacheIsValid;
|
$ret['isValid'] = $cg->cacheIsValid;
|
||||||
|
|
||||||
$passed = assertTrue($exp == $ret, 'HTTP_ConditionalGet : ' . $test['desc']);
|
$this->assertEquals($exp, $ret, $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";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
test_HTTP_ConditionalGet();
|
|
Reference in New Issue
Block a user