ServerUrlTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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:4974',
  67. server_url(
  68. array(
  69. 'HTTPS' => 'Off',
  70. 'SERVER_NAME' => 'host.tld',
  71. 'SERVER_PORT' => '80',
  72. 'HTTP_X_FORWARDED_PROTO' => 'https, https',
  73. 'HTTP_X_FORWARDED_PORT' => '4974, 80'
  74. )
  75. )
  76. );
  77. }
  78. /**
  79. * Detect if the server uses a specific port (!= 80)
  80. */
  81. public function testPort()
  82. {
  83. // HTTP
  84. $this->assertEquals(
  85. 'http://host.tld:8080',
  86. server_url(
  87. array(
  88. 'HTTPS' => 'OFF',
  89. 'SERVER_NAME' => 'host.tld',
  90. 'SERVER_PORT' => '8080'
  91. )
  92. )
  93. );
  94. // HTTPS
  95. $this->assertEquals(
  96. 'https://host.tld:8080',
  97. server_url(
  98. array(
  99. 'HTTPS' => 'ON',
  100. 'SERVER_NAME' => 'host.tld',
  101. 'SERVER_PORT' => '8080'
  102. )
  103. )
  104. );
  105. }
  106. /**
  107. * HTTP server on port 80
  108. */
  109. public function testStandardHttpPort()
  110. {
  111. $this->assertEquals(
  112. 'http://host.tld',
  113. server_url(
  114. array(
  115. 'HTTPS' => 'OFF',
  116. 'SERVER_NAME' => 'host.tld',
  117. 'SERVER_PORT' => '80'
  118. )
  119. )
  120. );
  121. }
  122. /**
  123. * HTTPS server on port 443
  124. */
  125. public function testStandardHttpsPort()
  126. {
  127. $this->assertEquals(
  128. 'https://host.tld',
  129. server_url(
  130. array(
  131. 'HTTPS' => 'ON',
  132. 'SERVER_NAME' => 'host.tld',
  133. 'SERVER_PORT' => '443'
  134. )
  135. )
  136. );
  137. }
  138. }