Changeset 405
- Timestamp:
- 10/15/07 13:58:38 (1 year ago)
- Files:
-
- trunk/lib/AkRequest.php (modified) (2 diffs)
- trunk/test/unit/lib/AkRequest.php (modified) (8 diffs)
- trunk/test/unit/lib/utils/_Ak_object_inspection.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AkRequest.php
r384 r405 600 600 601 601 if(is_array($details) && !empty($details['name']) && !empty($details['tmp_name']) && !empty($details['size'])){ 602 603 if( is_array($details['tmp_name']) && 604 ( 605 count($details['tmp_name']) == 1 && 606 !is_array(array_shift(array_values($details['tmp_name'])))) 607 ){ 608 609 foreach (array_keys($details['tmp_name']) as $k){ 610 if(UPLOAD_ERR_NO_FILE != $details['error'][$k]){ 611 $result[$name][$k] = array( 612 'name'=>$details['name'][$k], 613 'tmp_name'=>$details['tmp_name'][$k], 614 'size'=>$details['size'][$k], 615 'type'=>$details['type'][$k], 616 'error'=>$details['error'][$k], 617 ); 618 } 619 } 620 }elseif(is_array($details['tmp_name'])){ 602 if(is_array($details['tmp_name'])){ 621 603 foreach ($details['tmp_name'] as $item=>$item_details){ 622 foreach (array_keys($item_details) as $k){ 623 if(UPLOAD_ERR_NO_FILE != $details['error'][$item][$k]){ 624 $result[$name][$item][$k] = array( 625 'name'=>$details['name'][$item][$k], 626 'tmp_name'=>$details['tmp_name'][$item][$k], 627 'size'=>$details['size'][$item][$k], 628 'type'=>$details['type'][$item][$k], 629 'error'=>$details['error'][$item][$k], 604 if(is_array($item_details)){ 605 foreach (array_keys($item_details) as $k){ 606 if(UPLOAD_ERR_NO_FILE != $details['error'][$item][$k]){ 607 $result[$name][$item][$k] = array( 608 'name'=>$details['name'][$item][$k], 609 'tmp_name'=>$details['tmp_name'][$item][$k], 610 'size'=>$details['size'][$item][$k], 611 'type'=>$details['type'][$item][$k], 612 'error'=>$details['error'][$item][$k], 613 ); 614 } 615 } 616 }else{ 617 if(UPLOAD_ERR_NO_FILE != $details['error'][$item]){ 618 $result[$name][$item] = array( 619 'name'=>$details['name'][$item], 620 'tmp_name'=>$details['tmp_name'][$item], 621 'size'=>$details['size'][$item], 622 'type'=>$details['type'][$item], 623 'error'=>$details['error'][$item], 630 624 ); 631 625 } … … 649 643 return $result; 650 644 } 651 652 645 653 646 // {{{ _addParams() 654 647 trunk/test/unit/lib/AkRequest.php
r217 r405 7 7 class Test_of_AkRequest_Class extends UnitTestCase 8 8 { 9 10 9 var $test_request; 11 10 var $test_request2; … … 59 58 'general_param'=>'cmd' 60 59 ); 61 62 63 60 61 62 64 63 $this->_testRequestInstance =& new AkRequest(); 65 64 $this->_testRequestInstance->init(); 66 65 67 66 } 68 67 … … 70 69 { 71 70 unset($this->_testRequestInstance); 72 71 73 72 //We reset the original values 74 73 $_SESSION['request'] = $this->_original_values[0]; … … 83 82 { 84 83 $gpc_param = get_magic_quotes_gpc() ? "Isn't it ironic" : 'Isn\\\'t it ironic'; 85 84 86 85 $expected = array( 87 86 'cmd_param'=>'cmd', … … 94 93 'gpc_param'=>$gpc_param, 95 94 ); 96 95 97 96 $this->_testRequestInstance->_mergeRequest(); 98 97 99 98 $this->assertEqual($this->_testRequestInstance->_request,$expected,'Comparing request precedence'); 100 99 } … … 104 103 { 105 104 $expected_values = array('user','list','100'); 106 105 107 106 $this->assertEqual($this->_testRequestInstance->_parseAkRequestString('/user/list/100'), $expected_values); 108 107 $this->assertEqual($this->_testRequestInstance->_parseAkRequestString('/user/list/100/'), $expected_values); 109 108 $this->assertEqual($this->_testRequestInstance->_parseAkRequestString('user/list/100/'), $expected_values); 110 109 $this->assertEqual($this->_testRequestInstance->_parseAkRequestString('user/list/100'), $expected_values); 111 110 112 111 $expected_keys = array('controller','action','id'); 113 112 $this->assertEqual($this->_testRequestInstance->_parseAkRequestString('/:controller/:action/:id','/:'), $expected_keys); … … 116 115 $this->assertEqual($this->_testRequestInstance->_parseAkRequestString('controller/:action/:id','/:'), $expected_keys); 117 116 } 118 119 120 117 118 119 121 120 function test_for_getRemoteIp() 122 121 { 123 122 $Request = new AkRequest(); 124 123 125 124 $Request->env = array('HTTP_CLIENT_IP'=>'64.68.15.10'); 126 125 $this->assertEqual($Request->getRemoteIp(),'64.68.15.10'); 127 126 128 127 $Request->env = array('HTTP_X_FORWARDED_FOR'=>'64.68.15.11'); 129 128 $this->assertEqual($Request->getRemoteIp(),'64.68.15.11'); 130 129 131 130 $Request->env = array('HTTP_X_FORWARDED_FOR'=>'364.68.15.11'); 132 131 $this->assertEqual($Request->getRemoteIp(),''); 133 132 134 133 $Request->env = array('HTTP_X_FORWARDED_FOR'=>'3e4f:123f:c12a:5566:888e:9975:aaff:2344'); 135 134 $this->assertEqual($Request->getRemoteIp(),'3e4f:123f:c12a:5566:888e:9975:aaff:2344'); 136 135 137 136 $Request->env = array('HTTP_X_FORWARDED_FOR'=>'3e4f:123f:c12a:5566:888e:9975:aafg:2344'); 138 137 $this->assertEqual($Request->getRemoteIp(),''); … … 140 139 $Request->env = array('HTTP_X_FORWARDED_FOR'=>'364.68.15.11,64.68.15.11'); 141 140 $this->assertEqual($Request->getRemoteIp(),'64.68.15.11'); 142 141 143 142 $Request->env = array('REMOTE_ADDR'=>'64.68.15.11'); 144 143 $this->assertEqual($Request->getRemoteIp(),'64.68.15.11'); 145 144 } 146 145 147 146 function test_for_getDomain() 148 147 { 149 148 $Request = new AkRequest(); 150 149 151 150 $env_backup = $Request->env; 152 151 153 152 $Request->env['SERVER_NAME'] = 'localhost'; 154 153 $Request->env['SERVER_ADDR'] = '127.0.0.1'; 155 154 156 155 $this->assertEqual($Request->getDomain(), 'localhost'); 157 156 158 157 $Request->_host = 'www.dev.akelos.com'; 159 158 160 159 $this->assertEqual($Request->getDomain(),'akelos.com'); 161 160 $this->assertEqual($Request->getDomain(2),'dev.akelos.com'); 162 161 163 162 $Request->env = $env_backup; 164 163 } 165 164 166 165 function test_for_getSubDomains() 167 166 { 168 167 $Request = new AkRequest(); 169 168 170 169 $env_backup = $Request->env; 171 170 172 171 $Request->_host = 'www.dev.akelos.com'; 173 172 174 173 $this->assertEqual($Request->getSubdomains(), array('www','dev')); 175 174 $this->assertEqual($Request->getSubdomains(2),array('www')); 175 176 $Request->env = $env_backup; 177 } 178 179 180 function test_should_normalize_single_level_file_uploads() 181 { 182 $Request = new AkRequest(); 183 $_FILES = array ( 184 'image0' => array ( 'name' => 'mod_rewrite_cheat_sheet.pdf', 'type' => 'application/pdf', 'tmp_name' => '/tmp/php0JvZ0p', 'error' => 0, 'size' => 332133 ), 185 'image1' => array ( 'name' => 'microformats_cheat_sheet.pdf', 'type' => 'application/pdf', 'tmp_name' => '/tmp/phpKry1xs', 'error' => 0, 'size' => 427735 ), 186 'image2' => array ( 'name' => '', 'type' => '', 'tmp_name' => '', 'error' => 4, 'size' => 0 ) ); 187 $normalized = array ( 188 'image0' => array ( 'name' => 'mod_rewrite_cheat_sheet.pdf', 'type' => 'application/pdf', 'tmp_name' => '/tmp/php0JvZ0p', 'error' => 0, 'size' => 332133 ), 189 'image1' => array ( 'name' => 'microformats_cheat_sheet.pdf', 'type' => 'application/pdf', 'tmp_name' => '/tmp/phpKry1xs', 'error' => 0, 'size' => 427735 )); 176 190 177 $Request->env = $env_backup; 191 $this->assertEqual($Request->_getNormalizedFilesArray(), $normalized); 192 } 193 194 function test_should_normalize_multi_level_but_flat_file_uploads() 195 { 196 $Request = new AkRequest(); 197 $_FILES = array ( 'image' => array ( 'name' => array ( 'file' => array ( 'a' => 'mod_rewrite_cheat_sheet.pdf', 'b' => 'microformats_cheat_sheet.pdf', 'c' => '', ), ), 'type' => array ( 'file' => array ( 'a' => 'application/pdf', 'b' => 'application/pdf', 'c' => '', ), ), 'tmp_name' => array ( 'file' => array ( 'a' => '/tmp/phporGMwx', 'b' => '/tmp/phpGycyd6', 'c' => '', ), ), 'error' => array ( 'file' => array ( 'a' => 0, 'b' => 0, 'c' => 4, ), ), 'size' => array ( 'file' => array ( 'a' => 332133, 'b' => 427735, 'c' => 0, ), ), ), ); 198 $normalized = array ( 'image' => array ( 'file' => array ( 'a' => array ( 'name' => 'mod_rewrite_cheat_sheet.pdf', 'tmp_name' => '/tmp/phporGMwx', 'size' => 332133, 'type' => 'application/pdf', 'error' => 0, ), 'b' => array ( 'name' => 'microformats_cheat_sheet.pdf', 'tmp_name' => '/tmp/phpGycyd6', 'size' => 427735, 'type' => 'application/pdf', 'error' => 0, ), ), ), ); 199 200 $this->assertEqual($Request->_getNormalizedFilesArray(), $normalized); 201 } 202 203 function test_should_normalize_multi_level_as_array_file_uploads() 204 { 205 $Request = new AkRequest(); 206 $_FILES = array ( 'image' => array ( 'name' => array ( 'file' => array ( 0 => 'mod_rewrite_cheat_sheet.pdf', 1 => 'microformats_cheat_sheet.pdf', 2 => '', ), ), 'type' => array ( 'file' => array ( 0 => 'application/pdf', 1 => 'application/pdf', 2 => '', ), ), 'tmp_name' => array ( 'file' => array ( 0 => '/tmp/phpoOcNXs', 1 => '/tmp/php4xVEbv', 2 => '', ), ), 'error' => array ( 'file' => array ( 0 => 0, 1 => 0, 2 => 4, ), ), 'size' => array ( 'file' => array ( 0 => 332133, 1 => 427735, 2 => 0, ), ), ), ); 207 $normalized = array ( 'image' => array ( 'file' => array ( 0 => array ( 'name' => 'mod_rewrite_cheat_sheet.pdf', 'tmp_name' => '/tmp/phpoOcNXs', 'size' => 332133, 'type' => 'application/pdf', 'error' => 0, ), 1 => array ( 'name' => 'microformats_cheat_sheet.pdf', 'tmp_name' => '/tmp/php4xVEbv', 'size' => 427735, 'type' => 'application/pdf', 'error' => 0, ), ), ), ); 208 209 $this->assertEqual($Request->_getNormalizedFilesArray(), $normalized); 210 } 211 212 function test_should_normalize_simple_level_as_array_file_uploads() 213 { 214 $Request = new AkRequest(); 215 $_FILES = array ( 'image' => array ( 'name' => array ( 0 => 'mod_rewrite_cheat_sheet.pdf', 1 => 'microformats_cheat_sheet.pdf', 2 => '', ), 'type' => array ( 0 => 'application/pdf', 1 => 'application/pdf', 2 => '', ), 'tmp_name' => array ( 0 => '/tmp/phpXpfUKA', 1 => '/tmp/phpkB6MnX', 2 => '', ), 'error' => array ( 0 => 0, 1 => 0, 2 => 4, ), 'size' => array ( 0 => 332133, 1 => 427735, 2 => 0, ), ), ); 216 $normalized = array ('image' => array (0 => array ('name' => 'mod_rewrite_cheat_sheet.pdf','tmp_name' => '/tmp/phpXpfUKA','size' => 332133,'type' => 'application/pdf','error' => 0),1 => array ('name' => 'microformats_cheat_sheet.pdf','tmp_name' => '/tmp/phpkB6MnX','size' => 427735,'type' => 'application/pdf','error' => 0))); 217 $this->assertEqual($Request->_getNormalizedFilesArray(), $normalized); 178 218 } 179 219 trunk/test/unit/lib/utils/_Ak_object_inspection.php
r217 r405 124 124 $this->assertEqual('1592-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('1592-10-09'))); 125 125 $this->assertEqual('2192-10-09 00:00:00', Ak::getDate(Ak::getTimestamp('2192-10-09'))); 126 $this->assertEqual('2192-10-09 01:02:03', Ak::getDate(Ak::getTimestamp('2192-10-9 1:2:3')));126 $this->assertEqual('2192-10-09 01:02:03', Ak::getDate(Ak::getTimestamp('2192-10-9 01:02:03'))); 127 127 } 128 128
