ClientIpIdTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * HttpUtils' tests
  4. */
  5. require_once 'application/HttpUtils.php';
  6. /**
  7. * Unitary tests for client_ip_id()
  8. */
  9. class ClientIpIdTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * Get a remote client ID based on its IP
  13. */
  14. public function testClientIpIdRemote()
  15. {
  16. $this->assertEquals(
  17. '10.1.167.42',
  18. client_ip_id(['REMOTE_ADDR' => '10.1.167.42'])
  19. );
  20. }
  21. /**
  22. * Get a remote client ID based on its IP and proxy information (1)
  23. */
  24. public function testClientIpIdRemoteForwarded()
  25. {
  26. $this->assertEquals(
  27. '10.1.167.42_127.0.1.47',
  28. client_ip_id([
  29. 'REMOTE_ADDR' => '10.1.167.42',
  30. 'HTTP_X_FORWARDED_FOR' => '127.0.1.47'
  31. ])
  32. );
  33. }
  34. /**
  35. * Get a remote client ID based on its IP and proxy information (2)
  36. */
  37. public function testClientIpIdRemoteForwardedClient()
  38. {
  39. $this->assertEquals(
  40. '10.1.167.42_10.1.167.56_127.0.1.47',
  41. client_ip_id([
  42. 'REMOTE_ADDR' => '10.1.167.42',
  43. 'HTTP_X_FORWARDED_FOR' => '10.1.167.56',
  44. 'HTTP_CLIENT_IP' => '127.0.1.47'
  45. ])
  46. );
  47. }
  48. }