diff options
author | Cash Costello <cash.costello@gmail.com> | 2011-12-11 06:38:23 -0500 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2011-12-11 06:38:23 -0500 |
commit | d9bf22a0e29c2a70049443a0ae8521a2c0492c8b (patch) | |
tree | c7599a9169d5def7df56c480ad6d67f312443d6f /models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php | |
download | elgg-d9bf22a0e29c2a70049443a0ae8521a2c0492c8b.tar.gz elgg-d9bf22a0e29c2a70049443a0ae8521a2c0492c8b.tar.bz2 |
initial commit for git repository
Diffstat (limited to 'models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php')
-rw-r--r-- | models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php b/models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php new file mode 100644 index 000000000..28e3ca9af --- /dev/null +++ b/models/openid-php-openid-782224d/Tests/Auth/OpenID/TestUtil.php @@ -0,0 +1,60 @@ +<?php + +/** + * Utilites for test functions + */ + + +function Tests_Auth_OpenID_datafile($name, $reader) +{ + $path = dirname(realpath(__FILE__)); + $sep = DIRECTORY_SEPARATOR; + $filename = $path . $sep . 'data' . $sep . $name; + $data = $reader($filename); + if ($data === false) { + $msg = "Failed to open data file: $name"; + trigger_error($msg, E_USER_ERROR); + } + return $data; +} + +function Tests_Auth_OpenID_readdata($name) +{ + return Tests_Auth_OpenID_datafile($name, 'file_get_contents'); +} + +function Tests_Auth_OpenID_readlines($name) +{ + return Tests_Auth_OpenID_datafile($name, 'file'); +} + +class OpenIDTestMixin extends PHPUnit_Framework_TestCase { + function failUnlessOpenIDValueEquals($msg, $key, $expected, $ns=null) + { + if ($ns === null) { + $ns = Auth_OpenID_OPENID_NS; + } + + $actual = $msg->getArg($ns, $key); + $error_format = 'Wrong value for openid.%s: expected=%s, actual=%s'; + $error_message = sprintf($error_format, + $key, $expected, $actual); + + $this->assertEquals($expected, $actual, $error_message); + } + + function failIfOpenIDKeyExists($msg, $key, $ns=null) + { + if ($ns === null) { + $ns = Auth_OpenID_OPENID_NS; + } + + $actual = $msg->getArg($ns, $key); + $error_message = sprintf('openid.%s unexpectedly present: %s', + $key, $actual); + + $this->assertFalse($msg->hasKey($ns, $key), + $error_message); + } +} + |