ParseHTML.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Tests for the Yadis HTML parsing functionality.
  4. *
  5. * PHP versions 4 and 5
  6. *
  7. * LICENSE: See the COPYING file included in this distribution.
  8. *
  9. * @package OpenID
  10. * @author JanRain, Inc. <openid@janrain.com>
  11. * @copyright 2005-2008 Janrain, Inc.
  12. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
  13. */
  14. require_once 'Tests/Auth/Yadis/TestUtil.php';
  15. require_once 'Auth/Yadis/ParseHTML.php';
  16. require_once 'PHPUnit.php';
  17. class Tests_Auth_Yadis_ParseTest extends PHPUnit_TestCase {
  18. function Tests_Auth_Yadis_ParseTest($case)
  19. {
  20. list($result, $comment, $html) = $case;
  21. $this->result = $result;
  22. $this->comment = $comment;
  23. $this->html_string = $html;
  24. $this->parser = new Auth_Yadis_ParseHTML();
  25. }
  26. function getName()
  27. {
  28. return $this->comment;
  29. }
  30. function runTest()
  31. {
  32. $value = $this->parser->getHTTPEquiv($this->html_string);
  33. if ($this->result == "EOF") {
  34. $this->assertTrue($value === null);
  35. } else if ($this->result == "None") {
  36. $this->assertTrue($value === null);
  37. } else {
  38. $this->assertEquals($this->result, $value);
  39. }
  40. }
  41. }
  42. class Tests_Auth_Yadis_ParseHTML extends PHPUnit_TestSuite {
  43. function getName()
  44. {
  45. return "Tests_Auth_Yadis_Parse";
  46. }
  47. function parseTests($s)
  48. {
  49. $tests = array();
  50. $cases = preg_split("/\f\n/", $s);
  51. foreach ($cases as $case) {
  52. // Split the case text on newline, and keep the first two
  53. // lines and re-join the rest (those are the HTML).
  54. $parts = explode("\n", $case);
  55. $result = $parts[0];
  56. $html_comment = $parts[1];
  57. $html_string = implode("\n", array_slice($parts, 2));
  58. $tests[] = array($result, $html_comment, $html_string);
  59. }
  60. return $tests;
  61. }
  62. function Tests_Auth_Yadis_ParseHTML()
  63. {
  64. $test_data = Tests_Auth_Yadis_readdata('test1-parsehtml.txt');
  65. $test_cases = $this->parseTests($test_data);
  66. foreach ($test_cases as $case) {
  67. $this->addTest(new Tests_Auth_Yadis_ParseTest($case));
  68. }
  69. }
  70. }
  71. ?>