GetHttpUrlTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * HttpUtils' tests
  4. */
  5. require_once 'application/HttpUtils.php';
  6. /**
  7. * Unitary tests for get_http_response()
  8. */
  9. class GetHttpUrlTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * Get an invalid local URL
  13. */
  14. public function testGetInvalidLocalUrl()
  15. {
  16. // Local
  17. list($headers, $content) = get_http_response('/non/existent', 1);
  18. $this->assertEquals('Invalid HTTP Url', $headers[0]);
  19. $this->assertFalse($content);
  20. // Non HTTP
  21. list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1);
  22. $this->assertEquals('Invalid HTTP Url', $headers[0]);
  23. $this->assertFalse($content);
  24. }
  25. /**
  26. * Get an invalid remote URL
  27. */
  28. public function testGetInvalidRemoteUrl()
  29. {
  30. list($headers, $content) = @get_http_response('http://non.existent', 1);
  31. $this->assertFalse($headers);
  32. $this->assertFalse($content);
  33. }
  34. /**
  35. * Test getAbsoluteUrl with relative target URL.
  36. */
  37. public function testGetAbsoluteUrlWithRelative()
  38. {
  39. $origin = 'http://non.existent/blabla/?test';
  40. $target = '/stuff.php';
  41. $expected = 'http://non.existent/stuff.php';
  42. $this->assertEquals($expected, getAbsoluteUrl($origin, $target));
  43. $target = 'stuff.php';
  44. $expected = 'http://non.existent/blabla/stuff.php';
  45. $this->assertEquals($expected, getAbsoluteUrl($origin, $target));
  46. }
  47. /**
  48. * Test getAbsoluteUrl with absolute target URL.
  49. */
  50. public function testGetAbsoluteUrlWithAbsolute()
  51. {
  52. $origin = 'http://non.existent/blabla/?test';
  53. $target = 'http://other.url/stuff.php';
  54. $this->assertEquals($target, getAbsoluteUrl($origin, $target));
  55. }
  56. }