URINorm.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Tests for the URI normalization routines used by the OpenID
  4. * library.
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: See the COPYING file included in this distribution.
  9. *
  10. * @package OpenID
  11. * @author JanRain, Inc. <openid@janrain.com>
  12. * @copyright 2005-2008 Janrain, Inc.
  13. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
  14. */
  15. require_once 'Auth/OpenID/URINorm.php';
  16. require_once 'Tests/Auth/OpenID/TestUtil.php';
  17. class Tests_Auth_OpenID_URINorm_TestCase extends PHPUnit_Framework_TestCase {
  18. function Tests_Auth_OpenID_URINorm_TestCase(
  19. $name, $uri, $expected)
  20. {
  21. $this->setName($name);
  22. $this->uri = $uri;
  23. $this->expected = $expected;
  24. }
  25. function runTest()
  26. {
  27. $actual = Auth_OpenID_urinorm($this->uri);
  28. $this->assertEquals($this->expected, $actual);
  29. }
  30. }
  31. class Tests_Auth_OpenID_URINorm extends PHPUnit_Framework_TestSuite {
  32. function _readTestCases()
  33. {
  34. $lines = Tests_Auth_OpenID_readlines('urinorm.txt');
  35. $cases = array();
  36. $case = array();
  37. for ($i = 0; $i < count($lines) && ($i + 3 <= count($lines)); $i += 4) {
  38. $name = trim($lines[$i]);
  39. $uri = trim($lines[$i + 1]);
  40. $expected = trim($lines[$i + 2]);
  41. if ($expected == 'fail') {
  42. $expected = null;
  43. }
  44. $cases[] = array($name, $uri, $expected);
  45. }
  46. return $cases;
  47. }
  48. function Tests_Auth_OpenID_URINorm($name)
  49. {
  50. $this->setName($name);
  51. $cases = $this->_readTestCases();
  52. foreach ($cases as $case) {
  53. list($name, $uri, $expected) = $case;
  54. $this->addTest(new Tests_Auth_OpenID_URINorm_TestCase($name, $uri, $expected));
  55. }
  56. }
  57. }