GetAllHeadersTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. class GetAllHeadersTest extends \PHPUnit_Framework_TestCase
  3. {
  4. /**
  5. * @dataProvider testWorksData
  6. */
  7. public function testWorks($test_type, $expected, $server)
  8. {
  9. foreach ($server as $key => $val) {
  10. $_SERVER[$key] = $val;
  11. }
  12. $result = getallheaders();
  13. $this->assertEquals($expected, $result, "Error testing $test_type works.");
  14. }
  15. public function testWorksData()
  16. {
  17. return array(
  18. array(
  19. 'normal case',
  20. array(
  21. 'Key-One' => 'foo',
  22. 'Key-Two' => 'bar',
  23. 'Another-Key-For-Testing' => 'baz'
  24. ),
  25. array(
  26. 'HTTP_KEY_ONE' => 'foo',
  27. 'HTTP_KEY_TWO' => 'bar',
  28. 'HTTP_ANOTHER_KEY_FOR_TESTING' => 'baz'
  29. )
  30. ),
  31. array(
  32. 'Content-Type',
  33. array(
  34. 'Content-Type' => 'two'
  35. ),
  36. array(
  37. 'HTTP_CONTENT_TYPE' => 'one',
  38. 'CONTENT_TYPE' => 'two'
  39. )
  40. ),
  41. array(
  42. 'Content-Length',
  43. array(
  44. 'Content-Length' => '222'
  45. ),
  46. array(
  47. 'CONTENT_LENGTH' => '222',
  48. 'HTTP_CONTENT_LENGTH' => '111'
  49. )
  50. ),
  51. array(
  52. 'Content-Length (HTTP_CONTENT_LENGTH only)',
  53. array(
  54. 'Content-Length' => '111'
  55. ),
  56. array(
  57. 'HTTP_CONTENT_LENGTH' => '111'
  58. )
  59. ),
  60. array(
  61. 'Content-MD5',
  62. array(
  63. 'Content-Md5' => 'aef123'
  64. ),
  65. array(
  66. 'CONTENT_MD5' => 'aef123',
  67. 'HTTP_CONTENT_MD5' => 'fea321'
  68. )
  69. ),
  70. array(
  71. 'Content-MD5 (HTTP_CONTENT_MD5 only)',
  72. array(
  73. 'Content-Md5' => 'f123'
  74. ),
  75. array(
  76. 'HTTP_CONTENT_MD5' => 'f123'
  77. )
  78. ),
  79. array(
  80. 'Authorization (normal)',
  81. array(
  82. 'Authorization' => 'testing'
  83. ),
  84. array(
  85. 'HTTP_AUTHORIZATION' => 'testing',
  86. )
  87. ),
  88. array(
  89. 'Authorization (redirect)',
  90. array(
  91. 'Authorization' => 'testing redirect'
  92. ),
  93. array(
  94. 'REDIRECT_HTTP_AUTHORIZATION' => 'testing redirect',
  95. )
  96. ),
  97. array(
  98. 'Authorization (PHP_AUTH_USER + PHP_AUTH_PW)',
  99. array(
  100. 'Authorization' => 'Basic ' . base64_encode('foo:bar')
  101. ),
  102. array(
  103. 'PHP_AUTH_USER' => 'foo',
  104. 'PHP_AUTH_PW' => 'bar'
  105. )
  106. ),
  107. array(
  108. 'Authorization (PHP_AUTH_DIGEST)',
  109. array(
  110. 'Authorization' => 'example-digest'
  111. ),
  112. array(
  113. 'PHP_AUTH_DIGEST' => 'example-digest'
  114. )
  115. )
  116. );
  117. }
  118. }