ServerUrlTest.php 3.1 KB

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