summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_url.class12
-rwxr-xr-xtests/it_url.t41
2 files changed, 49 insertions, 4 deletions
diff --git a/it_url.class b/it_url.class
index 09c1292..5c13770 100644
--- a/it_url.class
+++ b/it_url.class
@@ -49,7 +49,7 @@ class it_url
* Constructor: canonicalize an URL
* @param $url URL this object represents
*/
-function it_url($url, $options = array())
+function it_url($url = null, $options = array())
{
$this->rawurl = $url;
@@ -237,10 +237,14 @@ function get($p=null, $timeout=5)
$p += array('totaltimeout' => "999999", 'timeout' => 5, 'retries' => 1);
- if (isset($p['url']))
+ if ($this instanceof it_url)
+ {
+ $url = $this;
+ if ($p['url'])
+ $this->it_url($p['url']);
+ }
+ else # called statically
$url = new it_url($p['url']);
- else
- $url =& $this; # Must be reference for $url->result and $url->data to work
$url->result = $result = false;
unset($url->data);
diff --git a/tests/it_url.t b/tests/it_url.t
index d017610..0178e33 100755
--- a/tests/it_url.t
+++ b/tests/it_url.t
@@ -85,4 +85,45 @@ is(
'it_url::absolute for https'
);
+$url = new it_url('http://www.gna.ch/');
+$page = $url->get();
+is(
+ it::match('(</html>)', $page),
+ '</html>',
+ '$url->get with url in constructor'
+);
+
+$url = new it_url('http://bogus.url');
+$page = $url->get('http://www.gna.ch/');
+is(
+ it::match('(</html>)', $page),
+ '</html>',
+ '$url->get(url) with url as string arg'
+);
+
+$url = new it_url('http://bogus.url');
+$page = $url->get('url' => 'http://www.gna.ch/');
+is(
+ it::match('(</html>)', $page),
+ '</html>',
+ '$url->get(\'url\' => url) with url as named arg'
+);
+is(
+ $url->result,
+ 200,
+ '$url->result = 200'
+);
+is(
+ $url->headers['Connection'],
+ 'close',
+ '$url->headers correctly set'
+);
+
+unset($url, $page);
+$page = it_url::get('http://www.gna.ch/');
+is(
+ it::match('(</html>)', $page),
+ '</html>',
+ 'it_url::get() static call'
+);
?>