PHP OpenID consumer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

urlnormaliser.test.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?PHP if (!defined('INCLUDE')) { ?><html>
  2. <head>
  3. <title>Poidsy unit test - URL normaliser</title>
  4. <style type="text/css">
  5. table { border-collapse: collapse; width: 100%; }
  6. td, th { border: 1px solid #000; padding: 10px; }
  7. td.error { text-align: center; color: #fff; background-color: #c00; }
  8. td.succ { text-align: center; color: #fff; background-color: #0c0; }
  9. </style>
  10. </head>
  11. <body>
  12. <table>
  13. <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
  14. <?PHP
  15. }
  16. require_once('../discoverer.inc.php');
  17. function doNormTest($output, $input) {
  18. $aoutput = Discoverer::normalise($input);
  19. $result = $aoutput == $output;
  20. echo '<tr><td>', htmlentities($input), '</td>';
  21. echo '<td>', htmlentities($output), '</td>';
  22. echo '<td>', htmlentities($aoutput), '</td>';
  23. echo '<td class="', $result ? 'succ' : 'error', '">';
  24. echo $result ? 'Passed' : 'Failed';
  25. echo '</td>';
  26. echo '</tr>';
  27. }
  28. $tests = array(
  29. 'test.foo' => 'http://test.foo/',
  30. 'test.foo.' => 'http://test.foo/',
  31. 'http://test.foo:80/' => 'http://test.foo/',
  32. 'user@test.foo' => 'http://test.foo/',
  33. 'test.foo/path#frag' => 'http://test.foo/path',
  34. 'test.foo:81' => 'http://test.foo:81/',
  35. 'user:pass@test.foo.:80/?foo#bar' => 'http://test.foo/',
  36. 'protocol://foo/' => 'protocol://foo/',
  37. 'protocol://foo.:80/' => 'protocol://foo:80/',
  38. 'https://test.foo/' => 'https://test.foo/',
  39. 'https://:@test.foo.:443?#' => 'https://test.foo/',
  40. 'https://test.foo:80' => 'https://test.foo:80/',
  41. 'http://host/path/to/file' => 'http://host/path/to/file',
  42. 'foo/././bar' => 'http://foo/bar',
  43. 'foo/bar/../baz' => 'http://foo/baz',
  44. 'foo/bar/./../baz' => 'http://foo/baz',
  45. 'http://test.foo/abc/../def/.././' => 'http://test.foo/',
  46. );
  47. array_walk($tests, 'doNormTest');
  48. ?>