cvs: pear-core / package-PEAR.xml package2.xml /PEAR RunTest.php /tests/PEAR_RunTest test_bug10092upload.phpt

From: Date: Sat, 17 Feb 2007 17:54:28 +0000
Subject: cvs: pear-core / package-PEAR.xml package2.xml /PEAR RunTest.php /tests/PEAR_RunTest test_bug10092upload.phpt
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-core+get-5437@lists.php.net to get a copy of this message
cellog Sat Feb 17 17:54:28 2007 UTC Added files: /pear-core/tests/PEAR_RunTest test_bug10092upload.phpt Modified files: /pear-core package-PEAR.xml package2.xml /pear-core/PEAR RunTest.php Log: complete missing run-tests section support. Now file uploads are supported http://cvs.php.net/viewvc.cgi/pear-core/package-PEAR.xml?r1=1.434&r2=1.435&diff_format=u Index: pear-core/package-PEAR.xml diff -u pear-core/package-PEAR.xml:1.434 pear-core/package-PEAR.xml:1.435 --- pear-core/package-PEAR.xml:1.434 Sat Feb 17 00:19:10 2007 +++ pear-core/package-PEAR.xml Sat Feb 17 17:54:28 2007 @@ -90,7 +90,8 @@ * fix Bug #9971: Improve run-tests diffs of EXPECTF sections * fix Bug #10012: pear package: tokenizer should be enabled * fix Bug #10081: installer dies on uninstall (recursion too deep) - * fix Bug #10092: run-tests does not support --INI-- or --POST-- + * fix Bug #10092: run-tests does not support --INI--. --POST--, --GET--, + --STDIN--, --UPLOAD-- * fix Bug #10108: update-error with backups from test-Folder * fix Bug #10109: on failed upgrade, .bak files everywhere * fix Bug #10113 proc_get_status() is php5 http://cvs.php.net/viewvc.cgi/pear-core/package2.xml?r1=1.328&r2=1.329&diff_format=u Index: pear-core/package2.xml diff -u pear-core/package2.xml:1.328 pear-core/package2.xml:1.329 --- pear-core/package2.xml:1.328 Sat Feb 17 00:19:10 2007 +++ pear-core/package2.xml Sat Feb 17 17:54:28 2007 @@ -99,7 +99,8 @@ * fix Bug #9971: Improve run-tests diffs of EXPECTF sections * fix Bug #10012: pear package: tokenizer should be enabled * fix Bug #10081: installer dies on uninstall (recursion too deep) - * fix Bug #10092: run-tests does not support --INI-- or --POST-- + * fix Bug #10092: run-tests does not support --INI--. --POST--, --GET--, + --STDIN--, --UPLOAD-- * fix Bug #10108: update-error with backups from test-Folder * fix Bug #10109: on failed upgrade, .bak files everywhere * fix Bug #10113 proc_get_status() is php5 http://cvs.php.net/viewvc.cgi/pear-core/PEAR/RunTest.php?r1=1.31&r2=1.32&diff_format=u Index: pear-core/PEAR/RunTest.php diff -u pear-core/PEAR/RunTest.php:1.31 pear-core/PEAR/RunTest.php:1.32 --- pear-core/PEAR/RunTest.php:1.31 Sat Feb 17 05:41:32 2007 +++ pear-core/PEAR/RunTest.php Sat Feb 17 17:54:28 2007 @@ -16,7 +16,7 @@ * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: RunTest.php,v 1.31 2007/02/17 05:41:32 cellog Exp $ + * @version CVS: $Id: RunTest.php,v 1.32 2007/02/17 17:54:28 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.3.3 */ @@ -216,7 +216,6 @@ 'SKIPIF' => '', 'GET' => '', 'COOKIE' => '', - 'POST_RAW' => '', 'POST' => '', 'ARGS' => '', 'INI' => '', @@ -247,6 +246,9 @@ } fclose($fp); + if (isset($section_text['POST_RAW']) && isset($section_text['UPLOAD'])) { + return PEAR::raiseError("Cannot contain both POST_RAW and UPLOAD in test file: $file"); + } $ini_settings = array(); $ini_settings = $this->settings2array($this->ini_overwrites, $ini_settings); if ($section_text['INI']) { @@ -264,7 +266,8 @@ $tested = trim($section_text['TEST']) . ' '; } if (!empty($section_text['GET']) || !empty($section_text['POST']) || - !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE'])) { + !empty($section_text['POST_RAW']) || !empty($section_text['COOKIE']) || + !empty($section_text['UPLOAD'])) { if (empty($this->_options['cgi'])) { if (!isset($this->_options['quiet'])) { $this->_logger->log(0, "SKIP $tested (reason: --cgi option needed for this test, type 'pear help run-tests')"); @@ -384,6 +387,50 @@ $env['QUERY_STRING'] = $query_string; $env['PATH_TRANSLATED'] = $test_file; $env['SCRIPT_FILENAME'] = $test_file; + if (array_key_exists('UPLOAD', $section_text) && !empty($section_text['UPLOAD'])) { + $upload_files = trim($section_text['UPLOAD']); + $upload_files = explode("\n", $upload_files); + + $request = "Content-Type: multipart/form-data; boundary=---------------------------20896060251896012921717172737\n" . + "-----------------------------20896060251896012921717172737\n"; + foreach ($upload_files as $fileinfo) { + $fileinfo = explode('=', $fileinfo); + if (count($fileinfo) != 2) { + return PEAR::raiseError("Invalid UPLOAD section in test file: $file"); + } + if (!realpath(dirname($file) . '/' . $fileinfo[1])) { + return PEAR::raiseError("File for upload does not exist: $fileinfo[1] " . + "in test file: $file"); + } + $file_contents = file_get_contents(dirname($file) . '/' . $fileinfo[1]); + $fileinfo[1] = basename($fileinfo[1]); + $request .= "Content-Disposition: form-data; name=\"$fileinfo[0]\"; filename=\"$fileinfo[1]\"\n"; + $request .= "Content-Type: text/plain\n\n"; + $request .= $file_contents . "\n" . + "-----------------------------20896060251896012921717172737\n"; + } + if (array_key_exists('POST', $section_text) && !empty($section_text['POST'])) { + // encode POST raw + $post = trim($section_text['POST']); + $post = explode('&', $post); + foreach ($post as $i => $post_info) { + $post_info = explode('=', $post_info); + if (count($post_info) != 2) { + return PEAR::raiseError("Invalid POST data in test file: $file"); + } + $post_info[0] = rawurldecode($post_info[0]); + $post_info[1] = rawurldecode($post_info[1]); + $post[$i] = $post_info; + } + foreach ($post as $post_info) { + $request .= "Content-Disposition: form-data; name=\"$post_info[0]\"\n\n"; + $request .= $post_info[1] . "\n" . + "-----------------------------20896060251896012921717172737\n"; + } + unset($section_text['POST']); + } + $section_text['POST_RAW'] = $request; + } if (array_key_exists('POST_RAW', $section_text) && !empty($section_text['POST_RAW'])) { $post = trim($section_text['POST_RAW']); $raw_lines = explode("\n", $post); http://cvs.php.net/viewvc.cgi/pear-core/tests/PEAR_RunTest/test_bug10092upload.phpt?view=markup&rev=1.1 Index: pear-core/tests/PEAR_RunTest/test_bug10092upload.phpt +++ pear-core/tests/PEAR_RunTest/test_bug10092upload.phpt --TEST-- PEAR_RunTest --UPLOAD-- --SKIPIF-- <?php if (!getenv('PHP_PEAR_RUNTESTS')) { echo 'skip'; } ?> --POST-- hi=there&fool=you --UPLOAD-- file1.txt=setup.php.inc myfile2.txt=test_bug9971.phpt --FILE-- <?php var_dump($_FILES); var_dump($_POST); $fp = fopen('php://input', 'r'); $a = fread($fp, 8192); fclose($fp); var_dump($a); ?> --EXPECTF-- array(2) { ["file1_txt"]=> array(5) { ["name"]=> string(13) "setup.php.inc" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "%s" ["error"]=> int(0) ["size"]=> int(403) } ["myfile2_txt"]=> array(5) { ["name"]=> string(17) "test_bug9971.phpt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "%s" ["error"]=> int(0) ["size"]=> int(299) } } array(2) { ["hi"]=> string(5) "there" ["fool"]=> string(3) "you" } string(0) ""

« previous php.pear.core (#5437) next »