GetAllHeadersTest.php 3.5 KB

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