| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/net/src/lmbHttpRequest.class.php'); 10 lmb_require('limb/net/src/lmbUri.class.php'); 11 12 class lmbHttpRequestTest extends UnitTestCase 13 { 14 function testGetUri() 15 { 16 $request = new lmbHttpRequest('http://test.com'); 17 $this->assertEqual($request->getUri(), new lmbUri('http://test.com')); 18 } 19 20 function testGetUriPath() 21 { 22 $request = new lmbHttpRequest('http://test.com/path?foo=1'); 23 $this->assertEqual($request->getUriPath(), '/path'); 24 } 25 26 function testGet() 27 { 28 $request = new lmbHttpRequest('http://test.com', array('c' => 1), array('d' => 2)); 29 $this->assertEqual($request->get('c'), 1); 30 $this->assertEqual($request->get('d'), 2); 31 $this->assertNull($request->get('foo')); 32 } 33 34 function testMergePostOverGet() 35 { 36 $request = new lmbHttpRequest('http://test.com', array('a' => 2), array('a' => 3)); 37 $this->assertEqual($request->get('a'), 3); 38 } 39 40 function testGetSafe() 41 { 42 $request = new lmbHttpRequest('http://test.com', array('c' => '<xss>')); 43 $this->assertEqual($request->getSafe('c'), htmlspecialchars('<xss>')); 44 } 45 46 function testGetRequest() 47 { 48 $request = new lmbHttpRequest('http://test.com', array('c' => 1), array('d' => 2)); 49 $this->assertEqual($request->getRequest(), array('c' => 1, 'd' => 2)); 50 $this->assertEqual($request->getRequest('c'), 1); 51 $this->assertNull($request->getRequest('b'), 1); 52 } 53 54 function testGetGet() 55 { 56 $request = new lmbHttpRequest('http://test.com', array('c' => 1)); 57 $this->assertEqual($request->getGet(), array('c' => 1)); 58 $this->assertEqual($request->getGet('c'), 1); 59 $this->assertNull($request->getGet('b'), 1); 60 } 61 62 function testGetPost() 63 { 64 $request = new lmbHttpRequest('http://test.com', array(), array('c' => 1)); 65 $this->assertEqual($request->getPost(), array('c' => 1)); 66 $this->assertEqual($request->getPost('c'), 1); 67 $this->assertNull($request->getPost('b'), 1); 68 } 69 70 function testGetCookie() 71 { 72 $request = new lmbHttpRequest('http://test.com', array(), array(), array('c' => 1)); 73 $this->assertEqual($request->getCookie(), array('c' => 1)); 74 $this->assertEqual($request->getCookie('c'), 1); 75 $this->assertNull($request->getCookie('b'), 1); 76 } 77 78 function testGetFiles() 79 { 80 $files = array( 81 'form' => array( 82 'name' => array( 83 'file1' => 'file', 84 'file2' => 'file', 85 ), 86 'type' => array( 87 'file1' => 'file_type', 88 'file2' => 'file_type', 89 ), 90 'tmp_name' => array( 91 'file1' => 'file_tmp_name', 92 'file2' => 'file_tmp_name', 93 ), 94 'size' => array( 95 'file1' => 'file_size', 96 'file2' => 'file_size', 97 ), 98 'error' => array( 99 'file1' => 'file_err_code', 100 'file2' => 'file_err_code', 101 ), 102 ), 103 ); 104 105 $expected = array( 106 'form' => array( 107 'file1' => new lmbUploadedFile(array( 108 'name' => 'file', 109 'type' => 'file_type', 110 'tmp_name' => 'file_tmp_name', 111 'size' => 'file_size', 112 'error' => 'file_err_code' 113 )), 114 'file2' => new lmbUploadedFile(array( 115 'name' => 'file', 116 'type' => 'file_type', 117 'tmp_name' => 'file_tmp_name', 118 'size' => 'file_size', 119 'error' => 'file_err_code' 120 )), 121 ), 122 ); 123 124 $request = new lmbHttpRequest('http://test.com', array(), array(), array(), $files); 125 $this->assertEqual($request->getFiles(), $expected); 126 $this->assertEqual($request->getFiles('form'), $expected['form']); 127 128 //files ARE returned with raw get 129 $this->assertEqual($request->get('form'), $expected['form']); 130 } 131 132 function testGetFilesMultipartException() 133 { 134 $old = null; 135 if(isset($_SERVER['CONTENT_TYPE'])) 136 $old = $_SERVER['CONTENT_TYPE']; 137 138 $_SERVER['CONTENT_TYPE'] = 'blah'; 139 140 $request = new lmbHttpRequest('http://test.com'); 141 $request->getFiles();//it's ok, no post request 142 143 $request->pretendPost(); 144 145 try 146 { 147 $request->getFiles(); 148 $this->assertTrue(false); 149 } 150 catch(lmbException $e){} 151 152 $_SERVER['CONTENT_TYPE'] = $old; 153 } 154 155 function testToString() 156 { 157 $files = array( 158 'file1' => array( 159 'name' => 'file', 160 'type' => 'file_type', 161 'tmp_name' => 'file_tmp_name', 162 'size' => 'file_size', 163 'error' => 'file_err_code' 164 ) 165 ); 166 167 $request = new lmbHttpRequest('http://test.com?z=1', 168 array('b' => array('c' => 1)), 169 array('d' => 2), 170 //only get & post data gets into string, cookies and files are ignored 171 array('cookie' => 2), 172 $files); 173 $this->assertEqual($request->toString(), 'http://test.com?b[c]=1&z=1&d=2'); 174 } 175 176 function testUriQueryOverridesGets() 177 { 178 $request = new lmbHttpRequest('http://test.com?a=1', array('a' => 2), array()); 179 180 $this->assertEqual($request->get('a'), 1); 181 } 182 } 183 184 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Sep 8 04:35:41 2008 | Cross-referenced by PHPXref 0.7 |