Blame view

framework/tests/control/HTTPResponseTest.php 1.44 KB
0084d336   Administrator   Importers CRUD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  <?php
  /**
   * @package framework
   * @subpackage tests
   */
  class HTTPResponseTest extends SapphireTest {
  	
  	public function testStatusDescriptionStripsNewlines() {
  		$r = new SS_HTTPResponse('my body', 200, "my description \nwith newlines \rand carriage returns");
  		$this->assertEquals(
  			"my description with newlines and carriage returns",
  			$r->getStatusDescription()
  		);
  	}
  	
  	public function testHTTPResponseException() {
  		$response = new SS_HTTPResponse("Test", 200, 'OK');
  
  		// Confirm that the exception's statusCode and statusDescription take precedence
  		try {
  			throw new SS_HTTPResponse_Exception($response, 404, 'not even found');
  
  		} catch(SS_HTTPResponse_Exception $e) {
  			$this->assertEquals(404, $e->getResponse()->getStatusCode());
  			$this->assertEquals('not even found', $e->getResponse()->getStatusDescription());
  			return;
  		}
  		// Fail if we get to here
  		$this->assertFalse(true, 'Something went wrong with our test exception');
  
  	}
  
  	public function testExceptionContentPlainByDefault() {
  
  		// Confirm that the exception's statusCode and statusDescription take precedence
  		try {
  			throw new SS_HTTPResponse_Exception("Some content that may be from a hacker", 404, 'not even found');
  
  		} catch(SS_HTTPResponse_Exception $e) {
  			$this->assertEquals("text/plain", $e->getResponse()->getHeader("Content-Type"));
  			return;
  		}
  		// Fail if we get to here
  		$this->assertFalse(true, 'Something went wrong with our test exception');
  
  	}
  }