From 8816e270e693f1fabb2ba47b87f3575c8f9ad13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 19 Nov 2015 19:53:19 +0200 Subject: [PATCH] port HTTPConditionalGetTest --- min_unit_tests/test_all.php | 1 - .../HTTPConditionalGetTest.php | 68 +++++++++++-------- 2 files changed, 40 insertions(+), 29 deletions(-) rename min_unit_tests/test_HTTP_ConditionalGet.php => tests/HTTPConditionalGetTest.php (77%) diff --git a/min_unit_tests/test_all.php b/min_unit_tests/test_all.php index d316ceb..db9abed 100644 --- a/min_unit_tests/test_all.php +++ b/min_unit_tests/test_all.php @@ -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'; diff --git a/min_unit_tests/test_HTTP_ConditionalGet.php b/tests/HTTPConditionalGetTest.php similarity index 77% rename from min_unit_tests/test_HTTP_ConditionalGet.php rename to tests/HTTPConditionalGetTest.php index 47114ba..c1f15df 100644 --- a/min_unit_tests/test_HTTP_ConditionalGet.php +++ b/tests/HTTPConditionalGetTest.php @@ -1,15 +1,22 @@ $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(); \ No newline at end of file