summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-01-27 01:32:26 +0000
committerJosh Hoyt <josh@janrain.com>2006-01-27 01:32:26 +0000
commit2e59e5b31e37d6f68eb3ab096ae068db1ea88e24 (patch)
tree6d90a9a92995fda99ebc7190d0f6f15bd0c2a284
parent54ea6d44f73059f335424bed2386d3a54b6d5f1a (diff)
downloadphp-openid-2e59e5b31e37d6f68eb3ab096ae068db1ea88e24.zip
php-openid-2e59e5b31e37d6f68eb3ab096ae068db1ea88e24.tar.gz
php-openid-2e59e5b31e37d6f68eb3ab096ae068db1ea88e24.tar.bz2
[project @ Use util data reading functions for Parse test]
-rw-r--r--Tests/Auth/OpenID/Parse.php18
-rw-r--r--Tests/Auth/OpenID/Util.php24
2 files changed, 29 insertions, 13 deletions
diff --git a/Tests/Auth/OpenID/Parse.php b/Tests/Auth/OpenID/Parse.php
index d511290..65e9424 100644
--- a/Tests/Auth/OpenID/Parse.php
+++ b/Tests/Auth/OpenID/Parse.php
@@ -13,6 +13,7 @@
* @license http://www.gnu.org/copyleft/lesser.html LGPL
*/
+require_once 'Tests/Auth/OpenID/Util.php';
require_once 'Auth/OpenID/Consumer/Parse.php';
class Tests_Auth_OpenID_Link extends PHPUnit_TestCase {
@@ -98,11 +99,18 @@ class Tests_Auth_OpenID_Parse extends PHPUnit_TestSuite {
return "Tests_Auth_OpenID_Parse";
}
+ function _parseCheck($cond, $where)
+ {
+ if (!$cond) {
+ trigger_error('Parse error in ' . $where, E_USER_ERROR);
+ }
+ }
+
function parseLink($line)
{
$parts = explode(" ", $line);
$optional = intval($parts[0] == 'Link*:');
- assert($optional || ($parts[0] == 'Link:'));
+ $this->_parseCheck($optional || ($parts[0] == 'Link:'), __FUNCTION__);
$attrs = array();
foreach (array_slice($parts, 1) as $attr) {
@@ -125,7 +133,7 @@ class Tests_Auth_OpenID_Parse extends PHPUnit_TestSuite {
list($header, $markup) = explode("\n\n", $s, 2);
$lines = explode("\n", $header);
$name = array_shift($lines);
- assert(strpos($name, 'Name: ') == 0);
+ $this->_parseCheck(strpos($name, 'Name: ') == 0, __FUNCTION__);
$desc = substr($name, 6);
$parsed = array();
foreach ($lines as $line) {
@@ -143,7 +151,7 @@ class Tests_Auth_OpenID_Parse extends PHPUnit_TestSuite {
$header = array_shift($cases);
list($tests_line, $unused) = explode("\n", $header, 2);
list($k, $v) = explode(": ", $tests_line);
- assert($k == 'Num Tests');
+ $this->_parseCheck(('Num Tests' == $k), __FUNCTION__);
$num_tests = intval($v);
foreach (array_slice($cases, 0, count($cases) - 1) as $case) {
@@ -156,9 +164,7 @@ class Tests_Auth_OpenID_Parse extends PHPUnit_TestSuite {
function Tests_Auth_OpenID_Parse()
{
- $here = realpath(dirname(__FILE__));
- $test_data_file_name = $here . DIRECTORY_SEPARATOR . 'linkparse.txt';
- $test_data = file_get_contents($test_data_file_name);
+ $test_data = Tests_Auth_OpenID_readdata('linkparse.txt');
list($num_tests, $test_cases) = $this->parseTests($test_data);
diff --git a/Tests/Auth/OpenID/Util.php b/Tests/Auth/OpenID/Util.php
index c6bf64d..8358160 100644
--- a/Tests/Auth/OpenID/Util.php
+++ b/Tests/Auth/OpenID/Util.php
@@ -4,15 +4,25 @@
* Utilites for test functions
*/
-function Tests_Auth_OpenID_readlines($name)
+function Tests_Auth_OpenID_datafile($name, $reader)
{
$path = dirname(realpath(__FILE__));
$sep = DIRECTORY_SEPARATOR;
- $data_file_name = $path . $sep . 'data' . $sep . $name;
- $lines = file($data_file_name);
- if ($lines === false) {
- trigger_error("Failed to open data file: $dh_test_data_file",
- E_USER_ERROR);
+ $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 $lines;
+ 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');
}