From: Chad Horohoe Date: Fri, 29 Jan 2010 23:52:06 +0000 (+0000) Subject: Followup r61655, add sys_get_temp_dir() support to wfTempDir(), use this in HttpTest... X-Git-Tag: 1.31.0-rc.0~38041 X-Git-Url: http://git.cyclocoop.org//%27%40script%40/%27?a=commitdiff_plain;h=4f772a5b33015379c6e308b2b1bb69d0252d3da4;p=lhc%2Fweb%2Fwiklou.git Followup r61655, add sys_get_temp_dir() support to wfTempDir(), use this in HttpTest rather than duplicating code --- diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 5fa6abff1b..5ff9629aa3 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2135,9 +2135,10 @@ function &wfGetMimeMagic() { } /** - * Tries to get the system directory for temporary files. - * The TMPDIR, TMP, and TEMP environment variables are checked in sequence, - * and if none are set /tmp is returned as the generic Unix default. + * Tries to get the system directory for temporary files. For PHP >= 5.2.1, + * we'll use sys_get_temp_dir(). The TMPDIR, TMP, and TEMP environment + * variables are then checked in sequence, and if none are set /tmp is + * returned as the generic Unix default. * * NOTE: When possible, use the tempfile() function to create temporary * files to avoid race conditions on file creation, etc. @@ -2145,6 +2146,9 @@ function &wfGetMimeMagic() { * @return String */ function wfTempDir() { + if( function_exists( 'sys_get_temp_dir' ) ) { + return sys_get_temp_dir(); + } foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) { $tmp = getenv( $var ); if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) { diff --git a/tests/HttpTest.php b/tests/HttpTest.php index 2a1037f4be..e81c71d0ea 100644 --- a/tests/HttpTest.php +++ b/tests/HttpTest.php @@ -32,8 +32,8 @@ class HttpTest extends PhpUnit_Framework_TestCase { $this->markTestIncomplete("This test requires the curl binary at /usr/bin/curl. If you have curl, please file a bug on this test, or, better yet, provide a patch."); } - $content = tempnam( sys_get_temp_dir(), "" ); - $headers = tempnam( sys_get_temp_dir(), "" ); + $content = tempnam( wfTempDir(), "" ); + $headers = tempnam( wfTempDir(), "" ); if ( !$content && !$headers ) { die( "Couldn't create temp file!" ); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3f0e6bed92..0eec5b2fe5 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -21,18 +21,4 @@ require_once "$IP/includes/ProfilerStub.php"; require_once "$IP/includes/GlobalFunctions.php"; require_once "$IP/includes/Hooks.php"; -// for php versions before 5.2.1 -if ( !function_exists('sys_get_temp_dir')) { - function sys_get_temp_dir() { - if( $temp=getenv('TMP') ) return $temp; - if( $temp=getenv('TEMP') ) return $temp; - if( $temp=getenv('TMPDIR') ) return $temp; - $temp=tempnam(__FILE__,''); - if (file_exists($temp)) { - unlink($temp); - return dirname($temp); - } - return null; - } - }