fix a test that failed when using a base URL without protocol

This commit is contained in:
Christian Weiske 2011-05-12 19:09:30 +02:00
parent f647c48477
commit aea9c9ddbb
2 changed files with 18 additions and 1 deletions

View file

@ -27,7 +27,7 @@ class Api_OpenSearchTest extends TestBaseApi
1, count($arElements), 1, count($arElements),
'OpenSearch link in HTML is missing' 'OpenSearch link in HTML is missing'
); );
$searchDescUrl = (string)$arElements[0]['href']; $searchDescUrl = $this->completeUrl((string)$arElements[0]['href']);
$this->assertNotNull($searchDescUrl, 'Search description URL is empty'); $this->assertNotNull($searchDescUrl, 'Search description URL is empty');
$req = new HTTP_Request2($searchDescUrl); $req = new HTTP_Request2($searchDescUrl);

View file

@ -92,6 +92,23 @@ class TestBaseApi extends TestBase
} }
/**
* Completes an URL that's missing the protocol.
* Useful when re-using URLs extracted from HTML
*
* @param string $url Potentially partial URL
*
* @return string Full URL
*/
protected function completeUrl($url)
{
if (substr($url, 0, 2) == '//') {
$url = 'http:' . $url;
}
return $url;
}
/** /**
* Creates a user and a HTTP request object and prepares * Creates a user and a HTTP request object and prepares