| [ 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/lmbHttpRedirectStrategy.class.php'); 10 11 Mock :: generatePartial( 12 'lmbHttpResponse', 13 'SpecialMockResponse', 14 array('_sendHeader', 15 '_sendCookie', 16 '_sendString', 17 '_sendFile') 18 ); 19 20 Mock::generate('lmbHttpRedirectStrategy', 'MockHttpRedirectStrategy'); 21 22 class lmbHttpResponseTest extends UnitTestCase 23 { 24 var $response; 25 26 function setUp() 27 { 28 $this->response = new SpecialMockResponse(); 29 } 30 31 function testIsEmpty() 32 { 33 $this->assertTrue($this->response->isEmpty()); 34 } 35 36 function testIsEmptyHeadersSent() 37 { 38 $this->response->header('test'); 39 $this->assertTrue($this->response->isEmpty()); 40 } 41 42 function testNotEmptyRedirect() 43 { 44 $this->response->redirect("/to/some/place?t=1&t=2"); 45 $this->assertFalse($this->response->isEmpty()); 46 } 47 48 function testNotEmptyResponseString() 49 { 50 $this->response->write("<b>wow</b>"); 51 $this->assertFalse($this->response->isEmpty()); 52 } 53 54 function testNotEmptyReadfile() 55 { 56 $this->response->readfile("/path/to/file"); 57 $this->assertFalse($this->response->isEmpty()); 58 } 59 60 function testNotEmpty304Status() 61 { 62 $this->response->header('HTTP/1.0 304 Not Modified'); 63 $this->assertFalse($this->response->isEmpty()); 64 } 65 66 function testNotEmpty412Status() 67 { 68 $this->response->header('HTTP/1.1 412 Precondition Failed'); 69 $this->assertFalse($this->response->isEmpty()); 70 } 71 72 function testHeadersNotSent() 73 { 74 $this->assertFalse($this->response->headersSent()); 75 } 76 77 function testFileNotSent() 78 { 79 $this->assertFalse($this->response->fileSent()); 80 } 81 82 function testFileSent() 83 { 84 $this->response->readfile('somefile'); 85 $this->assertTrue($this->response->fileSent()); 86 } 87 88 function testHeadersSent() 89 { 90 $this->response->header("Location:to-some-place"); 91 $this->assertTrue($this->response->headersSent()); 92 } 93 94 function testRedirect() 95 { 96 $this->assertFalse($this->response->isRedirected()); 97 98 $this->response->redirect($path = 'some path'); 99 100 $this->assertTrue($this->response->isRedirected()); 101 $this->assertEqual($this->response->getRedirectedPath(), $path); 102 } 103 104 function testRedirectOnlyOnce() 105 { 106 $strategy = new MockHttpRedirectStrategy(); 107 108 $this->response->setRedirectStrategy($strategy); 109 110 $this->assertFalse($this->response->isRedirected()); 111 112 $strategy->expectOnce('redirect'); 113 $this->response->redirect($path = 'some path'); 114 $this->response->redirect('some other path'); 115 116 $this->assertTrue($this->response->isRedirected()); 117 $this->assertEqual($this->response->getRedirectedPath(), $path); 118 } 119 120 function testSendHeadersOnCommit() 121 { 122 $this->response->header("Location:to-some-place"); 123 $this->response->header("Location:to-some-place2"); 124 125 $this->response->expectCallCount('_sendHeader', 2); 126 $this->response->expectArgumentsAt(0, '_sendHeader', array("Location:to-some-place")); 127 $this->response->expectArgumentsAt(1, '_sendHeader', array("Location:to-some-place2")); 128 129 $this->response->commit(); 130 } 131 132 function testWriteOnCommit() 133 { 134 $this->response->write("<b>wow</b>"); 135 $this->response->expectOnce('_sendString', array("<b>wow</b>")); 136 $this->response->commit(); 137 } 138 139 function testReadfileOnCommit() 140 { 141 $this->response->readfile("/path/to/file"); 142 $this->response->expectOnce('_sendFile', array("/path/to/file")); 143 $this->response->commit(); 144 } 145 146 function testSendCookiesOnCommit() 147 { 148 $this->response->setCookie($name1 = 'foo', $value1 = '1', $expire1 = 10, $path1 = '/', $domain1 = '.org', $secure1 = true); 149 $this->response->setCookie($name2 = 'bar', $value2 = '2', $expire2 = 20, $path2 = '/path', $domain2 = 'net.org', $secure2 = false); 150 151 $this->response->expectCallCount('_sendCookie', 2); 152 $this->response->expectArgumentsAt(0, '_sendCookie', array(array('name' => $name1, 153 'value' => $value1, 154 'expire' => $expire1, 155 'path' => $path1, 156 'domain' => $domain1, 157 'secure' => $secure1 158 ))); 159 $this->response->expectArgumentsAt(1, '_sendCookie', array(array('name' => $name2, 160 'value' => $value2, 161 'expire' => $expire2, 162 'path' => $path2, 163 'domain' => $domain2, 164 'secure' => $secure2 165 ))); 166 $this->response->commit(); 167 } 168 169 function testGetResponseDefaultStatus() 170 { 171 $this->assertEqual($this->response->getStatus(), 200); 172 } 173 174 function testGetResponseStatusHttp() 175 { 176 $this->response->header('HTTP/1.0 304 '); 177 $this->assertEqual($this->response->getStatus(), 304); 178 179 $this->response->header('HTTP/1.1 412'); 180 $this->assertEqual($this->response->getStatus(), 412); 181 } 182 183 function testGetUnknownDirective() 184 { 185 $this->assertFalse($this->response->getDirective('cache-control')); 186 } 187 188 function testGetDirective() 189 { 190 $this->response->header('Cache-Control: protected, max-age=0, must-revalidate'); 191 $this->assertEqual($this->response->getDirective('cache-control'), 'protected, max-age=0, must-revalidate'); 192 193 $this->response->header('Cache-Control : protected, max-age=10 '); 194 $this->assertEqual($this->response->getDirective('cache-control'), 'protected, max-age=10'); 195 } 196 197 function testGetContentDefaultType() 198 { 199 $this->assertEqual($this->response->getContentType(), 'text/html'); 200 } 201 202 function testGetContentType() 203 { 204 $this->response->header('Content-Type: image/png'); 205 $this->assertEqual($this->response->getContentType(), 'image/png'); 206 207 $this->response->header('Content-Type: application/rss+xml'); 208 $this->assertEqual($this->response->getContentType(), 'application/rss+xml'); 209 } 210 211 function testGetContentTypeWithDelimiter() 212 { 213 $this->response->header('Content-Type: text/html; charset=UTF-8'); 214 $this->assertEqual($this->response->getContentType(), 'text/html'); 215 } 216 } 217 218 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |