Headers.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class RequestsTest_Response_Headers extends PHPUnit_Framework_TestCase {
  3. public function testArrayAccess() {
  4. $headers = new Requests_Response_Headers();
  5. $headers['Content-Type'] = 'text/plain';
  6. $this->assertEquals('text/plain', $headers['Content-Type']);
  7. }
  8. public function testCaseInsensitiveArrayAccess() {
  9. $headers = new Requests_Response_Headers();
  10. $headers['Content-Type'] = 'text/plain';
  11. $this->assertEquals('text/plain', $headers['CONTENT-TYPE']);
  12. $this->assertEquals('text/plain', $headers['content-type']);
  13. }
  14. /**
  15. * @depends testArrayAccess
  16. */
  17. public function testIteration() {
  18. $headers = new Requests_Response_Headers();
  19. $headers['Content-Type'] = 'text/plain';
  20. $headers['Content-Length'] = 10;
  21. foreach ($headers as $name => $value) {
  22. switch (strtolower($name)) {
  23. case 'content-type':
  24. $this->assertEquals('text/plain', $value);
  25. break;
  26. case 'content-length':
  27. $this->assertEquals(10, $value);
  28. break;
  29. default:
  30. throw new Exception('Invalid name: ' . $name);
  31. }
  32. }
  33. }
  34. /**
  35. * @expectedException Requests_Exception
  36. */
  37. public function testInvalidKey() {
  38. $headers = new Requests_Response_Headers();
  39. $headers[] = 'text/plain';
  40. }
  41. public function testMultipleHeaders() {
  42. $headers = new Requests_Response_Headers();
  43. $headers['Accept'] = 'text/html;q=1.0';
  44. $headers['Accept'] = '*/*;q=0.1';
  45. $this->assertEquals('text/html;q=1.0,*/*;q=0.1', $headers['Accept']);
  46. }
  47. }