Yadis.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Tests for the core of the PHP Yadis library.
  4. */
  5. require_once 'Auth/Yadis/Yadis.php';
  6. require_once 'Tests/Auth/Yadis/TestUtil.php';
  7. class Tests_Auth_Yadis_DiscoveryTest extends PHPUnit_Framework_TestCase {
  8. function Tests_Auth_Yadis_DiscoveryTest($input_url, $redir_uri,
  9. $xrds_uri, $num)
  10. {
  11. $this->input_url = $input_url;
  12. $this->redir_uri = $redir_uri;
  13. $this->xrds_uri = $xrds_uri;
  14. $this->num = $num;
  15. }
  16. function getName()
  17. {
  18. return "Yadis discovery test ".$this->num;
  19. }
  20. function runTest()
  21. {
  22. $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
  23. $y = Auth_Yadis_Yadis::discover(
  24. $this->input_url, $fetcher);
  25. $this->assertTrue($y !== null);
  26. // Compare parts of returned Yadis object to expected URLs.
  27. $this->assertEquals($this->redir_uri, $y->normalized_uri, "tried $this->input_url");
  28. if ($this->xrds_uri) {
  29. $this->assertEquals($this->xrds_uri, $y->xrds_uri);
  30. // Compare contents of actual HTTP GET with that of Yadis
  31. // response.
  32. $f = Auth_Yadis_Yadis::getHTTPFetcher();
  33. $http_response = $f->get($this->xrds_uri);
  34. $this->assertEquals($http_response->body, $y->response_text);
  35. } else {
  36. $this->assertTrue($y->xrds_uri === null);
  37. }
  38. }
  39. }
  40. class Tests_Auth_Yadis_Yadis extends PHPUnit_Framework_TestSuite {
  41. function getName()
  42. {
  43. return "Tests_Auth_Yadis_Yadis";
  44. }
  45. function parseTests($data)
  46. {
  47. $cases = explode("\n", $data);
  48. $tests = array();
  49. foreach ($cases as $line) {
  50. if ($line && ($line[0] != "#")) {
  51. $tests[] = explode("\t", $line, 3);
  52. }
  53. }
  54. return $tests;
  55. }
  56. function Tests_Auth_Yadis_Yadis()
  57. {
  58. $test_data = file_get_contents('http://www.openidenabled.com/resources/yadis-test/discover/manifest.txt');
  59. $test_cases = $this->parseTests($test_data);
  60. $i = 0;
  61. foreach ($test_cases as $case) {
  62. $i++;
  63. list($input, $redir, $xrds) = $case;
  64. $this->addTest(new Tests_Auth_Yadis_DiscoveryTest($input,
  65. $redir,
  66. $xrds, $i));
  67. }
  68. }
  69. }