ServerUrlTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * HttpUtils' tests
  4. */
  5. require_once 'application/HttpUtils.php';
  6. /**
  7. * Unitary tests for server_url()
  8. */
  9. class ServerUrlTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * Detect if the server uses SSL
  13. */
  14. public function testHttpsScheme()
  15. {
  16. $this->assertEquals(
  17. 'https://host.tld',
  18. server_url(
  19. array(
  20. 'HTTPS' => 'ON',
  21. 'SERVER_NAME' => 'host.tld',
  22. 'SERVER_PORT' => '443'
  23. )
  24. )
  25. );
  26. $this->assertEquals(
  27. 'https://host.tld:8080',
  28. server_url(
  29. array(
  30. 'HTTPS' => 'ON',
  31. 'SERVER_NAME' => 'host.tld',
  32. 'SERVER_PORT' => '8080'
  33. )
  34. )
  35. );
  36. }
  37. /**
  38. * Detect a Proxy with SSL enabled
  39. */
  40. public function testHttpsProxyForward()
  41. {
  42. $this->assertEquals(
  43. 'https://host.tld:8080',
  44. server_url(
  45. array(
  46. 'HTTPS' => 'Off',
  47. 'SERVER_NAME' => 'host.tld',
  48. 'SERVER_PORT' => '80',
  49. 'HTTP_X_FORWARDED_PROTO' => 'https',
  50. 'HTTP_X_FORWARDED_PORT' => '8080'
  51. )
  52. )
  53. );
  54. $this->assertEquals(
  55. 'https://host.tld',
  56. server_url(
  57. array(
  58. 'HTTPS' => 'Off',
  59. 'SERVER_NAME' => 'host.tld',
  60. 'SERVER_PORT' => '80',
  61. 'HTTP_X_FORWARDED_PROTO' => 'https'
  62. )
  63. )
  64. );
  65. $this->assertEquals(
  66. 'https://host.tld',
  67. server_url(
  68. array(
  69. 'HTTPS' => 'Off',
  70. 'SERVER_NAME' => 'host.tld',
  71. 'SERVER_PORT' => '80',
  72. 'HTTP_X_FORWARDED_PROTO' => 'https',
  73. 'HTTP_X_FORWARDED_PORT' => '443'
  74. )
  75. )
  76. );
  77. $this->assertEquals(
  78. 'https://host.tld:4974',
  79. server_url(
  80. array(
  81. 'HTTPS' => 'Off',
  82. 'SERVER_NAME' => 'host.tld',
  83. 'SERVER_PORT' => '80',
  84. 'HTTP_X_FORWARDED_PROTO' => 'https, https',
  85. 'HTTP_X_FORWARDED_PORT' => '4974, 80'
  86. )
  87. )
  88. );
  89. }
  90. /**
  91. * Detect if the server uses a specific port (!= 80)
  92. */
  93. public function testPort()
  94. {
  95. // HTTP
  96. $this->assertEquals(
  97. 'http://host.tld:8080',
  98. server_url(
  99. array(
  100. 'HTTPS' => 'OFF',
  101. 'SERVER_NAME' => 'host.tld',
  102. 'SERVER_PORT' => '8080'
  103. )
  104. )
  105. );
  106. // HTTPS
  107. $this->assertEquals(
  108. 'https://host.tld:8080',
  109. server_url(
  110. array(
  111. 'HTTPS' => 'ON',
  112. 'SERVER_NAME' => 'host.tld',
  113. 'SERVER_PORT' => '8080'
  114. )
  115. )
  116. );
  117. }
  118. /**
  119. * HTTP server on port 80
  120. */
  121. public function testStandardHttpPort()
  122. {
  123. $this->assertEquals(
  124. 'http://host.tld',
  125. server_url(
  126. array(
  127. 'HTTPS' => 'OFF',
  128. 'SERVER_NAME' => 'host.tld',
  129. 'SERVER_PORT' => '80'
  130. )
  131. )
  132. );
  133. }
  134. /**
  135. * HTTPS server on port 443
  136. */
  137. public function testStandardHttpsPort()
  138. {
  139. $this->assertEquals(
  140. 'https://host.tld',
  141. server_url(
  142. array(
  143. 'HTTPS' => 'ON',
  144. 'SERVER_NAME' => 'host.tld',
  145. 'SERVER_PORT' => '443'
  146. )
  147. )
  148. );
  149. }
  150. }