diff options
author | tailor <cygnus@janrain.com> | 2006-01-16 23:36:45 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2006-01-16 23:36:45 +0000 |
commit | 1af777dfcba59bd1d768432655d6d8d210e899da (patch) | |
tree | 2daa5390620bc9ede3e22e81ed7f123660c3df45 /Tests/Net/OpenID/Parse.php | |
parent | 8ee5a5830f2cd3d9f9a15df133d8aebbbc74a562 (diff) | |
download | php-openid-1af777dfcba59bd1d768432655d6d8d210e899da.zip php-openid-1af777dfcba59bd1d768432655d6d8d210e899da.tar.gz php-openid-1af777dfcba59bd1d768432655d6d8d210e899da.tar.bz2 |
[project @ Moved modules from Net::OpenID namespace to Auth::OpenID for better PEAR categorization]
Diffstat (limited to 'Tests/Net/OpenID/Parse.php')
-rw-r--r-- | Tests/Net/OpenID/Parse.php | 173 |
1 files changed, 0 insertions, 173 deletions
diff --git a/Tests/Net/OpenID/Parse.php b/Tests/Net/OpenID/Parse.php deleted file mode 100644 index 52d2180..0000000 --- a/Tests/Net/OpenID/Parse.php +++ /dev/null @@ -1,173 +0,0 @@ -<?php - -/** - * Tests for the Consumer parsing functions. - * - * PHP versions 4 and 5 - * - * LICENSE: See the COPYING file included in this distribution. - * - * @package OpenID - * @author JanRain, Inc. <openid@janrain.com> - * @copyright 2005 Janrain, Inc. - * @license http://www.gnu.org/copyleft/lesser.html LGPL - */ - -require_once('Net/OpenID/Consumer/Parse.php'); - -class Tests_Net_OpenID_Link extends PHPUnit_TestCase { - function Tests_Net_OpenID_Link($case) - { - list($desc, $markup, $links, $case_text) = $case; - $this->desc = $desc; - $this->markup = $markup; - $this->expected_links = $links; - $this->case_text = $case_text; - } - - function getName() - { - return $this->desc; - } - - function runTest() - { - $parsed = Net_OpenID_parseLinkAttrs($this->markup); - $i = 0; - - foreach ($this->expected_links as $expected) { - list($is_optional_link, $expected_link) = $expected; - if ($is_optional_link && - ($i >= count($parsed))) { - continue; - } - - $act_link = $parsed[$i]; - - $increment = true; - foreach ($expected_link as $attr => $data) { - list($is_optional_attr, $value) = $data; - - if ($is_optional_attr) { - $actual_value = null; - if (array_key_exists($attr, $act_link)) { - $actual_value = $act_link[$attr]; - } else { - continue; - } - } else { - $actual_value = $act_link[$attr]; - } - - if ($is_optional_link && - ($value != $actual_value)) { - $increment = false; - break; - } - - $this->assertEquals($value, $actual_value); - } - - if ($increment) { - $i++; - } - } - - $this->assertEquals($i, count($parsed)); - } -} - -class NumTestCases extends PHPUnit_TestCase { - function NumTestCases($test_cases, $num_tests) - { - $this->test_cases = $test_cases; - $this->num_tests = $num_tests; - } - - function runTest() - { - $this->assertEquals(count($this->test_cases), - $this->num_tests); - } -} - -class Tests_Net_OpenID_Parse extends PHPUnit_TestSuite { - - function getName() - { - return "Tests_Net_OpenID_Parse"; - } - - function parseLink($line) - { - $parts = explode(" ", $line); - $optional = intval($parts[0] == 'Link*:'); - assert($optional || ($parts[0] == 'Link:')); - - $attrs = array(); - foreach (array_slice($parts, 1) as $attr) { - list($k, $v) = explode("=", $attr, 2); - if ($k[strlen($k) - 1] == '*') { - $attr_optional = 1; - $k = substr($k, 0, strlen($k) - 1); - } else { - $attr_optional = 0; - } - - $attrs[$k] = array($attr_optional, $v); - } - - return array($optional, $attrs); - } - - function parseCase($s) - { - list($header, $markup) = explode("\n\n", $s, 2); - $lines = explode("\n", $header); - $name = array_shift($lines); - assert(strpos($name, 'Name: ') == 0); - $desc = substr($name, 6); - $parsed = array(); - foreach ($lines as $line) { - $parsed[] = $this->parseLink($line); - } - - return array($desc, $markup, $parsed); - } - - function parseTests($s) - { - $tests = array(); - - $cases = explode("\n\n\n", $s); - $header = array_shift($cases); - list($tests_line, $unused) = explode("\n", $header, 2); - list($k, $v) = explode(": ", $tests_line); - assert($k == 'Num Tests'); - $num_tests = intval($v); - - foreach (array_slice($cases, 0, count($cases) - 1) as $case) { - list($desc, $markup, $links) = $this->parseCase($case); - $tests[] = array($desc, $markup, $links, $case); - } - - return array($num_tests, $tests); - } - - function Tests_Net_OpenID_Parse() - { - $here = realpath(dirname(__FILE__)); - $test_data_file_name = $here . DIRECTORY_SEPARATOR . 'linkparse.txt'; - $test_data = file_get_contents($test_data_file_name); - - list($num_tests, $test_cases) = $this->parseTests($test_data); - - $this->addTest(new NumTestCases($test_cases, $num_tests)); - - foreach ($test_cases as $case) { - $this->addTest(new Tests_Net_OpenID_Link($case)); - } - } -} - -?>
\ No newline at end of file |