TestUtil.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Utilites for test functions
  4. */
  5. function Tests_Auth_OpenID_datafile($name, $reader)
  6. {
  7. $path = dirname(realpath(__FILE__));
  8. $sep = DIRECTORY_SEPARATOR;
  9. $filename = $path . $sep . 'data' . $sep . $name;
  10. $data = $reader($filename);
  11. if ($data === false) {
  12. $msg = "Failed to open data file: $name";
  13. trigger_error($msg, E_USER_ERROR);
  14. }
  15. return $data;
  16. }
  17. function Tests_Auth_OpenID_readdata($name)
  18. {
  19. return Tests_Auth_OpenID_datafile($name, 'file_get_contents');
  20. }
  21. function Tests_Auth_OpenID_readlines($name)
  22. {
  23. return Tests_Auth_OpenID_datafile($name, 'file');
  24. }
  25. class OpenIDTestMixin extends PHPUnit_Framework_TestCase {
  26. function failUnlessOpenIDValueEquals($msg, $key, $expected, $ns=null)
  27. {
  28. if ($ns === null) {
  29. $ns = Auth_OpenID_OPENID_NS;
  30. }
  31. $actual = $msg->getArg($ns, $key);
  32. $error_format = 'Wrong value for openid.%s: expected=%s, actual=%s';
  33. $error_message = sprintf($error_format,
  34. $key, $expected, $actual);
  35. $this->assertEquals($expected, $actual, $error_message);
  36. }
  37. function failIfOpenIDKeyExists($msg, $key, $ns=null)
  38. {
  39. if ($ns === null) {
  40. $ns = Auth_OpenID_OPENID_NS;
  41. }
  42. $actual = $msg->getArg($ns, $key);
  43. $error_message = sprintf('openid.%s unexpectedly present: %s',
  44. $key, $actual);
  45. $this->assertFalse($msg->hasKey($ns, $key),
  46. $error_message);
  47. }
  48. }