function Tests_Services_Yadis_ParseHTML() { $test_data = Tests_Services_Yadis_readdata('test1-parsehtml.txt'); $test_cases = $this->parseTests($test_data); foreach ($test_cases as $case) { $this->addTest(new Tests_Services_Yadis_ParseTest($case)); } }
function Tests_Services_Yadis_Yadis() { $test_data = Tests_Services_Yadis_readdata('manifest.txt'); $test_cases = $this->parseTests($test_data); $i = 0; foreach ($test_cases as $case) { $i++; list($input, $redir, $xrds) = $case; $this->addTest(new Tests_Services_Yadis_DiscoveryTest($input, $redir, $xrds, $i)); } }
function readTests($filename) { $data = Tests_Services_Yadis_readdata($filename); if ($data === null) { return null; } $tests = array(); foreach (preg_split("/\f\n/", $data) as $case) { list($name, $content) = explode("\n", $case, 2); $tests[$name] = $content; } return $tests; }
function test_services_filters() { // First, just be sure that service objects do the right // thing. $xml = Tests_Services_Yadis_readdata("brian_priority.xrds"); $xrds = Services_Yadis_XRDS::parseXRDS($xml, array('openid' => 'http://openid.net/xmlns/1.0')); $this->assertTrue($xrds !== null); // Get list of service objects. $services = $xrds->services(); $this->assertEquals(count($services), 2, "first service count"); // Query the two service objecs. $s1 = $services[0]; $this->assertEquals($s1->getPriority(), 1, "first priority check"); $types = $s1->getTypes(); $this->assertEquals(count($types), 1, "first type check"); $s2 = $services[1]; $this->assertEquals($s2->getPriority(), 2, "second priority check"); $types = $s2->getTypes(); $this->assertEquals(count($types), 1, "second type check"); function _DelegateFilter(&$service) { if ($service->getElements('openid:Delegate')) { return true; } return false; } // Make sure that a filter which matches both DOES match both. $this->assertEquals(count($xrds->services(array("_DelegateFilter"))), 2, "_DelegateFilter check"); // This filter should match all services in the document. function _HasTypeAndURI(&$service) { if ($service->getTypes() && $service->getURIs()) { return true; } return false; } // This filter should only match one. function _URIMatchesSchtuff(&$service) { $uris = $service->getURIs(); foreach ($uris as $uri) { if (preg_match("|schtuff|", $uri)) { return true; } } return false; } // This filter should only match one. function _URIMatchesMyOpenID(&$service) { $uris = $service->getURIs(); foreach ($uris as $uri) { if (preg_match("|myopenid|", $uri)) { return true; } } return false; } // Make sure a pair of filters in ALL mode only match one service. $this->assertEquals(count($xrds->services(array("_HasTypeAndURI", "_URIMatchesSchtuff"), SERVICES_YADIS_MATCH_ALL)), 1, "_HasTypeAndURI / _URIMatchesSchtuff check"); // Make sure a pair of filters in ALL mode only match one service. $this->assertEquals(count($xrds->services(array("_HasTypeAndURI", "_URIMatchesMyOpenID"), SERVICES_YADIS_MATCH_ALL)), 1, "_HasTypeAndURI / _URIMatchesMyOpenID check"); // Make sure a pair of filters in ANY mode matches both services. $this->assertEquals(count($xrds->services(array("_URIMatchesMyOpenID", "_URIMatchesSchtuff"))), 2, "_URIMatchesMyOpenID / _URIMatchesSchtuff check"); // Make sure the order of the services returned (when using // filters) is correct. $s = $xrds->services(array("_URIMatchesMyOpenID", "_URIMatchesSchtuff")); $this->assertTrue($s[0]->getPriority() === 1, "s[0] priority check"); $this->assertTrue($s[1]->getPriority() === 2, "s[1] priority check"); // Make sure a bad filter mode gets us a null service list. $this->assertTrue($xrds->services(array("_URIMatchesMyOpenID", "_URIMatchesSchtuff"), "bogus") === null, "bogus filter check"); }