ParseHTML.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. class Tests_Auth_Yadis_ParseTest extends PHPUnit_Framework_TestCase {
  17. function Tests_Auth_Yadis_ParseTest($case)
  18. {
  19. list($result, $comment, $html) = $case;
  20. $this->result = $result;
  21. $this->comment = $comment;
  22. $this->html_string = $html;
  23. $this->parser = new Auth_Yadis_ParseHTML();
  24. }
  25. function getName()
  26. {
  27. return $this->comment;
  28. }
  29. function runTest()
  30. {
  31. $value = $this->parser->getHTTPEquiv($this->html_string);
  32. if ($this->result == "EOF") {
  33. $this->assertTrue($value === null);
  34. } else if ($this->result == "None") {
  35. $this->assertTrue($value === null);
  36. } else {
  37. $this->assertEquals($this->result, $value);
  38. }
  39. }
  40. }
  41. class Tests_Auth_Yadis_ParseHTML extends PHPUnit_Framework_TestSuite {
  42. function getName()
  43. {
  44. return "Tests_Auth_Yadis_Parse";
  45. }
  46. function parseTests($s)
  47. {
  48. $tests = array();
  49. $cases = preg_split("/\f\n/", $s);
  50. foreach ($cases as $case) {
  51. // Split the case text on newline, and keep the first two
  52. // lines and re-join the rest (those are the HTML).
  53. $parts = explode("\n", $case);
  54. $result = $parts[0];
  55. $html_comment = $parts[1];
  56. $html_string = implode("\n", array_slice($parts, 2));
  57. $tests[] = array($result, $html_comment, $html_string);
  58. }
  59. return $tests;
  60. }
  61. function Tests_Auth_Yadis_ParseHTML()
  62. {
  63. $test_data = Tests_Auth_Yadis_readdata('test1-parsehtml.txt');
  64. $test_cases = $this->parseTests($test_data);
  65. foreach ($test_cases as $case) {
  66. $this->addTest(new Tests_Auth_Yadis_ParseTest($case));
  67. }
  68. }
  69. }