summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weber2010-06-02 15:24:07 +0000
committerChristian Weber2010-06-02 15:24:07 +0000
commit77d04fe9d6b1b784e9f9197ab308e09f184613ab (patch)
treee0dfbdabb486b54f8c5c656fe47bd151ed9b4d05
parentaa3529d9a5d81d83b7bf82a33e4e8988ac81a420 (diff)
downloaditools-77d04fe9d6b1b784e9f9197ab308e09f184613ab.tar.gz
itools-77d04fe9d6b1b784e9f9197ab308e09f184613ab.tar.bz2
itools-77d04fe9d6b1b784e9f9197ab308e09f184613ab.zip
it_url::get() no longer creates new objects if not called statically. Added it_url::get() test cases
-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'
+);
?>