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.

parsehtml.test.php 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?PHP if (!defined('INCLUDE')) { ?><html>
  2. <head>
  3. <title>Poidsy unit test - HTML parser</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. var { font-size: small; color: purple; font-style: normal; padding: 0 2px; }
  10. </style>
  11. </head>
  12. <body>
  13. <table>
  14. <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
  15. <?PHP
  16. }
  17. require_once('../discoverer.inc.php');
  18. define('BASE_URI', 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/');
  19. function doHtmlTest($output, $input) {
  20. $disc = new Discoverer(BASE_URI . $input);
  21. $aoutput = $disc->getVersion() . "\n" . $disc->getEndpointUrl() . "\n" . $disc->getUserSuppliedId() . "\n" . $disc->getClaimedId() . "\n" . $disc->getOpLocalId();
  22. $aoutput = str_replace(BASE_URI, '%URL%', $aoutput);
  23. $result = $aoutput == $output;
  24. echo '<tr><td><a href="', htmlentities($input), '">', htmlentities($input), '</a></td>';
  25. echo '<td>', str_replace('%URL%', '<var>%URL%</var>', nl2br(htmlentities($output))), '</td>';
  26. echo '<td>', str_replace('%URL%', '<var>%URL%</var>', nl2br(htmlentities($aoutput))), '</td>';
  27. echo '<td class="', $result ? 'succ' : 'error', '">';
  28. echo $result ? 'Passed' : 'Failed';
  29. echo '</td>';
  30. echo '</tr>';
  31. }
  32. $tests = array(
  33. 'samplehtml/test1.html' => "1\nhttp://server.com/path\n%URL%samplehtml/test1.html\n%URL%samplehtml/test1.html\nhttp://delegate.com/",
  34. 'samplehtml/test2.html' => "1\nhttp://server.com/path\n%URL%samplehtml/test2.html\n%URL%samplehtml/test2.html\nhttp://delegate.com/",
  35. 'samplehtml/test3.html' => "1\nhttp://server/path?foo&bar\n%URL%samplehtml/test3.html\n%URL%samplehtml/test3.html\n",
  36. 'samplehtml/v2-test1.html' => "2\nhttp://server.com/path\n%URL%samplehtml/v2-test1.html\n%URL%samplehtml/v2-test1.html\nhttp://delegate.com/",
  37. 'samplehtml/v2-test2.html' => "2\nhttp://server.com/path\n%URL%samplehtml/v2-test2.html\n%URL%samplehtml/v2-test2.html\n%URL%samplehtml/v2-test2.html",
  38. 'samplehtml/v2-test3.html' => "2\nhttp://server.com/path\n%URL%samplehtml/v2-test3.html\n%URL%samplehtml/v2-test3.html\n%URL%samplehtml/v2-test3.html",
  39. 'samplehtml/v2-test4.html' => "1\nhttp://server.com/path\n%URL%samplehtml/v2-test4.html\n%URL%samplehtml/v2-test4.html\nhttp://delegate.com/",
  40. 'samplehtml/v2-test5.html' => "1\nhttp://server.com/path\n%URL%samplehtml/v2-test5.html\n%URL%samplehtml/v2-test5.html\nhttp://delegate.com/",
  41. );
  42. array_walk($tests, 'doHtmlTest');
  43. ?>