summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Gass2012-10-15 16:04:28 +0000
committerNathan Gass2012-10-15 16:04:28 +0000
commit2efc485bc24fd66938d3eb5feb542ed4279a9501 (patch)
treedb0f89db9b28a65a42a8b6fe284d65a82c679bad
parent3d4c923c5f80c85cc44518426b8dc0244ec53842 (diff)
downloaditools-2efc485bc24fd66938d3eb5feb542ed4279a9501.tar.gz
itools-2efc485bc24fd66938d3eb5feb542ed4279a9501.tar.bz2
itools-2efc485bc24fd66938d3eb5feb542ed4279a9501.zip
add harder tests for it_url::get using custom testserver on localhost
-rwxr-xr-xtests/it_url.t56
-rw-r--r--tests/it_url.testserver.php21
2 files changed, 77 insertions, 0 deletions
diff --git a/tests/it_url.t b/tests/it_url.t
index 10fd015..0655bda 100755
--- a/tests/it_url.t
+++ b/tests/it_url.t
@@ -123,9 +123,65 @@ ok(
'it_url::get() static call'
);
+$server = proc_open(
+ 'php -S localhost:8000 ' . dirname($_SERVER['PHP_SELF']) . '/it_url.testserver.php',
+ array(0 => fopen('/dev/null', 'r'), 1 => fopen('/dev/null', 'w'), 2 => array('pipe', 'w')),
+ //array(0 => fopen('/dev/null', 'r'), 1 => fopen('/dev/null', 'w'), 2 => array(fopen('php://stderr', 'w'))),
+ $pipes
+);
+usleep(100000);
+stream_set_blocking($pipes[2], 0);
+function server_output() {
+ $result = array();
+ while (($result[] = trim(fgets($GLOBALS['pipes'][2])))) {};
+ return array_filter($result);
+}
+
+$res = is(
+ it_url::get('http://localhost:8000/'),
+ "Testserver root output",
+ 'it_url::get() static call with port',
+);
+$output = server_output();
+if (!$res)
+ diag($output);
+
+$res = is(
+ it_url::get('http://localhost:8000/temp_redirect'),
+ "Testserver output after temporary redirect",
+ 'it_url::get() follows temproary redirect',
+);
+$output = server_output();
+if (!$res)
+ diag($output);
+
+$res = is(
+ it_url::get('http://localhost:8000/perm_redirect'),
+ "Testserver output after permanent redirect",
+ 'it_url::get() follows permanent redirect',
+);
+$output = server_output();
+if (!$res)
+ diag($output);
+
+$res = ok(
+ !it_url::get(U('http://localhost:8000/redirect_loop', 'num' => 10)),
+ 'it_url::get() handles redirect loop',
+);
+$output = server_output();
+$last_num = it::match('num=(\d+)', end($output));
+$res2 = ok(
+ $last_num == 5,
+ 'it_url::get() aborts redirect loop after 5 redirects',
+);
+if (!$res || !$res2)
+ diag($output);
+
$pages = it_url::get_multi('urls' => array('a' => 'http://www.gna.ch/', 'b' => 'http://search.ch/'));
ok(strpos($pages['a'], '</html>'), 'it_url::get_multi got first url'); # UTF8SAFE
ok(strpos($pages['b'], '</html>'), 'it_url::get_multi got second url'); # UTF8SAFE
is(count($pages), 2, 'it_url::get_multi no additional array elements');
+proc_terminate($server);
+
?>
diff --git a/tests/it_url.testserver.php b/tests/it_url.testserver.php
new file mode 100644
index 0000000..c9c5dff
--- /dev/null
+++ b/tests/it_url.testserver.php
@@ -0,0 +1,21 @@
+<?php
+require '/www/server/phpinclude/auto_prepend.php';
+$stderr = fopen('php://stderr', 'w');
+fwrite($stderr, "Got Request: '" . $_SERVER['REQUEST_URI'] . "'\n");
+
+if ($_SERVER['PHP_SELF'] == "/") {
+ echo 'Testserver root output';
+
+} else if ($_SERVER['PHP_SELF'] == "/temp_redirect") {
+ it_url::redirect(U("redirect_target", array('type' => 'temporary')), 'temporary');
+
+} else if ($_SERVER['PHP_SELF'] == "/perm_redirect") {
+ it_url::redirect(U("redirect_target", array('type' => 'permanent')), 'permanent');
+
+} else if ($_SERVER['PHP_SELF'] == "/redirect_loop") {
+ if ($_REQUEST['num'] > 0)
+ it_url::redirect(U("redirect_loop", array('num' => $_REQUEST['num'] - 1)));
+
+} else if ($_SERVER['PHP_SELF'] == "/redirect_target") {
+ echo 'Testserver output after ' . $_REQUEST['type'] . ' redirect';
+}