* adding tests
authorMichael Wallner <mike@php.net>
Sun, 13 Feb 2005 10:41:15 +0000 (10:41 +0000)
committerMichael Wallner <mike@php.net>
Sun, 13 Feb 2005 10:41:15 +0000 (10:41 +0000)
tests/001_date.phpt [new file with mode: 0644]
tests/002_date.phpt [new file with mode: 0644]
tests/010_abs_uri.phpt [new file with mode: 0644]
tests/011_abs_uri.phpt [new file with mode: 0644]
tests/020_redirect.phpt [new file with mode: 0644]
tests/021_redirect.phpt [new file with mode: 0644]
tests/022_redirect.phpt [new file with mode: 0644]
tests/030_send_data.phpt [new file with mode: 0644]
tests/040_chunked_decode.phpt [new file with mode: 0644]
tests/050_split_response.phpt [new file with mode: 0644]
tests/051_parse_headers.phpt [new file with mode: 0644]

diff --git a/tests/001_date.phpt b/tests/001_date.phpt
new file mode 100644 (file)
index 0000000..7bd8b64
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+http_date() with timestamp
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+echo http_date(1), "\n";
+echo http_date(1234567890), "\n";
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+Thu, 01 Jan 1970 00:00:01 GMT
+Fri, 13 Feb 2009 23:31:30 GMT
diff --git a/tests/002_date.phpt b/tests/002_date.phpt
new file mode 100644 (file)
index 0000000..f518188
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+http_date() without timestamp
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+$d1 = http_date();
+$d2 = http_date();
+var_dump($d1 === $d2);
+echo strtotime($d1), "\n$d1\n$d2\n";
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+bool(true)
+%d
+%s, %d %s %d %d:%d:%d GMT
+%s, %d %s %d %d:%d:%d GMT
diff --git a/tests/010_abs_uri.phpt b/tests/010_abs_uri.phpt
new file mode 100644 (file)
index 0000000..67b1beb
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+http_absolute_uri() with relative paths
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+echo http_absolute_uri('page'), "\n";
+echo http_absolute_uri('with/some/path/'), "\n";
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+http://localhost/page
+http://localhost/with/some/path/
diff --git a/tests/011_abs_uri.phpt b/tests/011_abs_uri.phpt
new file mode 100644 (file)
index 0000000..fa4db1b
--- /dev/null
@@ -0,0 +1,20 @@
+--TEST--
+http_absolute_uri() with proto
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+echo http_absolute_uri('sec', 'https'), "\n";
+echo http_absolute_uri('/pub', 'ftp'), "\n";
+echo http_absolute_uri('/', null), "\n";
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+https://localhost/sec
+ftp://localhost/pub
+http://localhost/
diff --git a/tests/020_redirect.phpt b/tests/020_redirect.phpt
new file mode 100644 (file)
index 0000000..b849ced
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+http_redirect() with params
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+http_redirect('redirect', array('a' => 1, 'b' => 2));
+?>
+--EXPECTF--
+Status: 302
+Content-type: text/html
+X-Powered-By: PHP/%s
+Location: http://localhost/redirect?a=1&b=2
+
+Redirecting to <a href="http://localhost/redirect?a=1&b=2">http://localhost/redirect?a=1&b=2</a>.
+
diff --git a/tests/021_redirect.phpt b/tests/021_redirect.phpt
new file mode 100644 (file)
index 0000000..e8b2cca
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+http_redirect() with session
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+session_start();
+http_redirect('redirect', array('a' => 1), true);
+?>
+--EXPECTF--
+Status: 302
+Content-type: text/html
+X-Powered-By: PHP/%s
+Set-Cookie: PHPSESSID=%s; path=/
+Expires: %s
+Cache-Control: %s
+Pragma: %s
+Location: http://localhost/redirect?a=1&PHPSESSID=%s
diff --git a/tests/022_redirect.phpt b/tests/022_redirect.phpt
new file mode 100644 (file)
index 0000000..bd9a23d
--- /dev/null
@@ -0,0 +1,19 @@
+--TEST--
+http_redirect() permanent
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+http_redirect('redirect', null, false, true);
+?>
+--EXPECTF--
+Status: 301
+Content-type: text/html
+X-Powered-By: PHP/%s
+Location: http://localhost/redirect
+
+Redirecting to <a href="http://localhost/redirect">http://localhost/redirect</a>.
+
diff --git a/tests/030_send_data.phpt b/tests/030_send_data.phpt
new file mode 100644 (file)
index 0000000..301d45f
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+http_send_data()
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+http_content_type('text/plain');
+http_send_data(str_repeat('123abc', 1));
+?>
+--EXPECTREGEX--
+.+\s+.+\s+(abc|[123abc]{,100000})
\ No newline at end of file
diff --git a/tests/040_chunked_decode.phpt b/tests/040_chunked_decode.phpt
new file mode 100644 (file)
index 0000000..9f333f3
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+http_chunked_decode()
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+$data = 
+"02\r\n".
+"ab\r\n".
+"03\r\n".
+"a\nc\r\n".
+"04\r\n".
+"abcd\r\n".
+"0\r\n".
+"abracadabra\n";
+var_dump(http_chunked_decode($data));
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+string(9) "aba
+cabcd"
diff --git a/tests/050_split_response.phpt b/tests/050_split_response.phpt
new file mode 100644 (file)
index 0000000..3a562fd
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+http_split_response()
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+var_export(http_split_response("HTTP/1.1 200 Ok\r\nContent-Type: text/plain\r\nContent-Language: de-AT\r\nDate: Sat, 22 Jan 2005 18:10:02 GMT\r\n\r\nHallo Du!)"));
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+array (
+  0 => 
+  array (
+    'Status' => '200 Ok',
+    'Content-Type' => 'text/plain',
+    'Content-Language' => 'de-AT',
+    'Date' => 'Sat, 22 Jan 2005 18:10:02 GMT',
+  ),
+  1 => 'Hallo Du!',
+)
\ No newline at end of file
diff --git a/tests/051_parse_headers.phpt b/tests/051_parse_headers.phpt
new file mode 100644 (file)
index 0000000..39afa55
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+http_parse_headers()
+--SKIPIF--
+<?php 
+extension_loaded('http') or die('ext/http not available');
+strncasecmp(PHP_SAPI, 'CLI', 3) or die('cannot run tests with CLI');
+?>
+--FILE--
+<?php
+print_r(http_parse_headers(
+"Host: localhost\r\n".
+"Nospace:here\r\n".
+"Muchspace:  there   \r\n".
+"Empty:\r\n".
+"Empty2: \r\n".
+": invalid\r\n".
+" : bogus\r\n".
+"Folded: one\r\n".
+"\ttwo\r\n".
+"  three\r\n".
+"stop\r\n"
+));
+?>
+--EXPECTF--
+Content-type: text/html
+X-Powered-By: PHP/%s
+
+Array
+(
+    [Host] => localhost
+    [Nospace] => here
+    [Muchspace] => there
+    [Empty] => 
+    [Empty2] => 
+    [Folded] => one
+       two
+  three
+)
\ No newline at end of file