Browse Source

Add tests from renji

tags/0.6
Chris Smith 14 years ago
parent
commit
63a5e190bc

+ 46
- 0
test/addarguments.test.php View File

@@ -0,0 +1,46 @@
1
+<?PHP
2
+if (!defined('INCLUDE')) { ?>
3
+<html>
4
+ <head>
5
+  <title>Poidsy unit test - URL Builder</title>
6
+  <style type="text/css">
7
+   table { border-collapse: collapse; width: 100%; }
8
+   td, th { border: 1px solid #000; padding: 10px; }
9
+   td.error { text-align: center; color: #fff; background-color: #c00; }
10
+   td.succ { text-align: center; color: #fff; background-color: #0c0; }
11
+  </style>
12
+ </head>
13
+ <body>
14
+  <table>
15
+   <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
16
+<?PHP
17
+ }
18
+
19
+ require_once('../urlbuilder.inc.php');
20
+
21
+ function doArgTest($data, $key) {
22
+ 
23
+  list($base, $args, $output) = $data;
24
+
25
+  $aoutput = URLBuilder::addArguments($base, $args);
26
+  $result = $aoutput == $output;
27
+
28
+  echo '<tr><td>', htmlentities($base), ', '; print_r($args); echo '</td>';
29
+  echo '<td>', htmlentities($output), '</td>';
30
+  echo '<td>', htmlentities($aoutput), '</td>';
31
+  echo '<td class="', $result ? 'succ' : 'error', '">';
32
+  echo $result ? 'Passed' : 'Failed';
33
+  echo '</td>';
34
+  echo '</tr>';
35
+ }
36
+
37
+ $tests = array(
38
+  array('http://test/?foo=bar', array('baz' => 'qux'), 'http://test/?foo=bar&baz=qux'),
39
+  array('http://test/?', array('baz' => 'qux'), 'http://test/?baz=qux'),
40
+  array('http://test/?foo', array('baz' => 'qux'), 'http://test/?foo&baz=qux'),
41
+  array('http://test/', array('a' => 'b', 'c'=>'d'), 'http://test/?a=b&c=d'),
42
+ );
43
+
44
+ array_walk($tests, 'doArgTest');
45
+
46
+?>

+ 11
- 0
test/httpcodes/500.html View File

@@ -0,0 +1,11 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid.server" href="500.php">
6
+   <link rel="openid.delegate" href="http://delegate.com/">
7
+  </title>
8
+ </head>
9
+ <body>
10
+ </body>
11
+</html>

+ 1
- 0
test/httpcodes/500.php View File

@@ -0,0 +1 @@
1
+<?PHP header('HTTP/1.1 500 Internal Server Error'); ?>

+ 22
- 0
test/index.php View File

@@ -0,0 +1,22 @@
1
+ <head>
2
+  <title>Poidsy unit tests</title>
3
+  <style type="text/css">
4
+   table { border-collapse: collapse; width: 100%; }
5
+   td, th { border: 1px solid #000; padding: 10px; }
6
+   td.error { text-align: center; color: #fff; background-color: #c00; }
7
+   td.succ { text-align: center; color: #fff; background-color: #0c0; }
8
+  </style>
9
+ </head>
10
+ <body>
11
+  <table>
12
+   <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
13
+<?PHP
14
+
15
+ define('INCLUDE', true);
16
+
17
+ foreach (glob('*.test.php') as $test) {
18
+  echo '<tr><th colspan="4">', $test, '</th></tr>';
19
+  include($test); 
20
+ }
21
+
22
+?>

+ 48
- 0
test/parsehtml.test.php View File

@@ -0,0 +1,48 @@
1
+<?PHP if (!defined('INCLUDE')) { ?><html>
2
+ <head>
3
+  <title>Poidsy unit test - HTML parser</title>
4
+  <style type="text/css">
5
+   table { border-collapse: collapse; width: 100%; }
6
+   td, th { border: 1px solid #000; padding: 10px; }
7
+   td.error { text-align: center; color: #fff; background-color: #c00; }
8
+   td.succ { text-align: center; color: #fff; background-color: #0c0; }
9
+  </style>
10
+ </head>
11
+ <body>
12
+  <table>
13
+   <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
14
+<?PHP
15
+
16
+ }
17
+
18
+ require_once('../discoverer.inc.php');
19
+
20
+ function doHtmlTest($output, $input) {
21
+
22
+  $disc = new Discoverer(null);
23
+  $disc->parseHtml(file_get_contents($input));
24
+  $aoutput = $disc->getVersion() . ':' . $disc->getServer() . ',' . $disc->getDelegate();
25
+  $result = $aoutput == $output;
26
+
27
+  echo '<tr><td><a href="', htmlentities($input), '">', htmlentities($input), '</a></td>';
28
+  echo '<td>', htmlentities($output), '</td>';
29
+  echo '<td>', htmlentities($aoutput), '</td>';
30
+  echo '<td class="', $result ? 'succ' : 'error', '">';
31
+  echo $result ? 'Passed' : 'Failed';
32
+  echo '</td>';
33
+  echo '</tr>';
34
+ }
35
+
36
+ $tests = array(
37
+  'samplehtml/test1.html' => '1:http://server.com/path,http://delegate.com/',
38
+  'samplehtml/test2.html' => '1:http://server.com/path,http://delegate.com/',
39
+  'samplehtml/test3.html' => '1:http://server/path?foo&bar,',
40
+  'samplehtml/v2-test1.html' => '2:http://server.com/path,http://delegate.com/',
41
+  'samplehtml/v2-test2.html' => '2:http://server.com/path,',
42
+  'samplehtml/v2-test3.html' => '2:http://server.com/path,',
43
+  'samplehtml/v2-test4.html' => '1:http://server.com/path,http://delegate.com/',
44
+ );
45
+
46
+ array_walk($tests, 'doHtmlTest');
47
+
48
+?>

+ 48
- 0
test/parseredirects.test.php View File

@@ -0,0 +1,48 @@
1
+<?PHP if (!defined('INCLUDE')) { ?><html>
2
+ <head>
3
+  <title>Poidsy unit test - redirect tests</title>
4
+  <style type="text/css">
5
+   table { border-collapse: collapse; width: 100%; }
6
+   td, th { border: 1px solid #000; padding: 10px; }
7
+   td.error { text-align: center; color: #fff; background-color: #c00; }
8
+   td.succ { text-align: center; color: #fff; background-color: #0c0; }
9
+  </style>
10
+ </head>
11
+ <body>
12
+  <table>
13
+   <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
14
+<?PHP
15
+
16
+ }
17
+
18
+ require_once('../discoverer.inc.php');
19
+
20
+ function doRedirTest($output, $input) {
21
+  $url = $url2 = 'http://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/';
22
+  $output = $url . $output;
23
+  $url = $url . $input;
24
+  $disc = new Discoverer($url);
25
+  $aoutput = $disc->getIdentity();
26
+  $result = $aoutput == $output;
27
+
28
+  echo '<tr><td><a href="', htmlentities($url), '">', htmlentities($input), '</a></td>';
29
+  echo '<td>', htmlentities(str_replace($url2, '', $output)), '</td>';
30
+  echo '<td>', htmlentities(str_replace($url2, '', $aoutput)), '</td>';
31
+  echo '<td class="', $result ? 'succ' : 'error', '">';
32
+  echo $result ? 'Passed' : 'Failed';
33
+  echo '</td>';
34
+  echo '</tr>';
35
+ }
36
+
37
+ $tests = array(
38
+ 	'redirtest/one.php' => 'redirtest/three.php',
39
+	'redirtest/two.php' => 'redirtest/three.php',
40
+	'redirtest/three.php' => 'redirtest/three.php',
41
+        'redirtest/four.php' => 'redirtest/three.php',
42
+        'redirtest/five.php' => 'redirtest/three.php',
43
+//        'redirtest/six.php' => 'redirtest/three.php',
44
+ );
45
+
46
+ array_walk($tests, 'doRedirTest');
47
+
48
+?>

+ 5
- 0
test/redirtest/five.php View File

@@ -0,0 +1,5 @@
1
+<?PHP
2
+
3
+header('Location: three.php');
4
+
5
+?>

+ 5
- 0
test/redirtest/four.php View File

@@ -0,0 +1,5 @@
1
+<?PHP
2
+
3
+header('Location: http://' . $_SERVER['HTTP_HOST'] . str_replace('four', 'three', $_SERVER['REQUEST_URI']));
4
+
5
+?>

+ 5
- 0
test/redirtest/one.php View File

@@ -0,0 +1,5 @@
1
+<?PHP
2
+
3
+header('Location: ' . str_replace('one', 'two', $_SERVER['REQUEST_URI']));
4
+
5
+?>

+ 5
- 0
test/redirtest/six.php View File

@@ -0,0 +1,5 @@
1
+<?PHP
2
+
3
+header('Location: ../redirtest/five.php');
4
+
5
+?>

+ 4
- 0
test/redirtest/three.php View File

@@ -0,0 +1,4 @@
1
+<?PHP
2
+
3
+
4
+?>

+ 5
- 0
test/redirtest/two.php View File

@@ -0,0 +1,5 @@
1
+<?PHP
2
+
3
+header('Location: ' . str_replace('two', 'three', $_SERVER['REQUEST_URI']));
4
+
5
+?>

+ 11
- 0
test/samplehtml/test1.html View File

@@ -0,0 +1,11 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid.server" href="http://server.com/path">
6
+   <link rel="openid.delegate" href="http://delegate.com/">
7
+  </title>
8
+ </head>
9
+ <body>
10
+ </body>
11
+</html>

+ 13
- 0
test/samplehtml/test2.html View File

@@ -0,0 +1,13 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="server" href="crap">
6
+   <link rel="openid.server" href="http://server.com/path">
7
+   <link rel="delegate" href="crap">
8
+   <link rel="openid.delegate" href="http://delegate.com/">
9
+  </title>
10
+ </head>
11
+ <body>
12
+ </body>
13
+</html>

+ 10
- 0
test/samplehtml/test3.html View File

@@ -0,0 +1,10 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid.server" href="http://server/path?foo&amp;bar">
6
+  </title>
7
+ </head>
8
+ <body>
9
+ </body>
10
+</html>

+ 11
- 0
test/samplehtml/v2-test1.html View File

@@ -0,0 +1,11 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid2.provider" href="http://server.com/path">
6
+   <link rel="openid2.local_id" href="http://delegate.com/">
7
+  </title>
8
+ </head>
9
+ <body>
10
+ </body>
11
+</html>

+ 10
- 0
test/samplehtml/v2-test2.html View File

@@ -0,0 +1,10 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid2.provider" href="http://server.com/path">
6
+  </title>
7
+ </head>
8
+ <body>
9
+ </body>
10
+</html>

+ 12
- 0
test/samplehtml/v2-test3.html View File

@@ -0,0 +1,12 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid2.provider" href="http://server.com/path">
6
+   <link rel="openid.server" href="http://server.com/path">
7
+   <link rel="openid.delegate" href="http://delegate.com/">
8
+  </title>
9
+ </head>
10
+ <body>
11
+ </body>
12
+</html>

+ 12
- 0
test/samplehtml/v2-test4.html View File

@@ -0,0 +1,12 @@
1
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+<html>
3
+ <head>
4
+  <title>Blah</title>
5
+   <link rel="openid2.local_id" href="http://delegate2.com/">
6
+   <link rel="openid.server" href="http://server.com/path">
7
+   <link rel="openid.delegate" href="http://delegate.com/">
8
+  </title>
9
+ </head>
10
+ <body>
11
+ </body>
12
+</html>

+ 44
- 0
test/trustrootnormaliser.test.php View File

@@ -0,0 +1,44 @@
1
+<?PHP if (!defined('INCLUDE')) { ?><html>
2
+ <head>
3
+  <title>Poidsy unit test - trust root normaliser</title>
4
+  <style type="text/css">
5
+   table { border-collapse: collapse; width: 100%; }
6
+   td, th { border: 1px solid #000; padding: 10px; }
7
+   td.error { text-align: center; color: #fff; background-color: #c00; }
8
+   td.succ { text-align: center; color: #fff; background-color: #0c0; }
9
+  </style>
10
+ </head>
11
+ <body>
12
+  <table>
13
+   <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
14
+<?PHP
15
+
16
+ }
17
+
18
+ require_once('../urlbuilder.inc.php');
19
+
20
+ function doTrustRootTest($input, $output) {
21
+  list($input1, $input2) = $input;
22
+
23
+  $aoutput = URLBuilder::getTrustRoot($input1, $input2);
24
+  $result = $aoutput == $output;
25
+
26
+  echo '<tr><td>', htmlentities($input1 . ',' . $input2), '</td>';
27
+  echo '<td>', htmlentities($output), '</td>';
28
+  echo '<td>', htmlentities($aoutput), '</td>';
29
+  echo '<td class="', $result ? 'succ' : 'error', '">';
30
+  echo $result ? 'Passed' : 'Failed';
31
+  echo '</td>';
32
+  echo '</tr>';
33
+ }
34
+
35
+ $tests = array(
36
+  'http://test.fo1/' => array('http://test.fo1/','http://test.fo1/index.php'),
37
+  'http://test.fo2/' => array('http://test.fo2/bar/baz/','http://test.fo2/index.php'),
38
+  'http://test.fo3/' => array('http://test.fo3/','http://test.fo3/'),
39
+  'http://test.fo4/bar/' => array('http://test.fo4/bar/baz/','http://test.fo4/bar/q/i.php'),
40
+ );
41
+
42
+ array_walk($tests, 'doTrustRootTest');
43
+
44
+?>

+ 56
- 0
test/urlnormaliser.test.php View File

@@ -0,0 +1,56 @@
1
+<?PHP if (!defined('INCLUDE')) { ?><html>
2
+ <head>
3
+  <title>Poidsy unit test - URL normaliser</title>
4
+  <style type="text/css">
5
+   table { border-collapse: collapse; width: 100%; }
6
+   td, th { border: 1px solid #000; padding: 10px; }
7
+   td.error { text-align: center; color: #fff; background-color: #c00; }
8
+   td.succ { text-align: center; color: #fff; background-color: #0c0; }
9
+  </style>
10
+ </head>
11
+ <body>
12
+  <table>
13
+   <tr><th>Input</th><th>Expected</th><th>Actual</th><th>Result</th></tr>
14
+<?PHP
15
+
16
+ }
17
+
18
+ require_once('../discoverer.inc.php');
19
+
20
+ function doNormTest($output, $input) {
21
+
22
+  $aoutput = Discoverer::normalise($input);
23
+  $result = $aoutput == $output;
24
+
25
+  echo '<tr><td>', htmlentities($input), '</td>';
26
+  echo '<td>', htmlentities($output), '</td>';
27
+  echo '<td>', htmlentities($aoutput), '</td>';
28
+  echo '<td class="', $result ? 'succ' : 'error', '">';
29
+  echo $result ? 'Passed' : 'Failed';
30
+  echo '</td>';
31
+  echo '</tr>';
32
+ }
33
+
34
+ $tests = array(
35
+  'test.foo' => 'http://test.foo/',
36
+  'test.foo.' => 'http://test.foo/',
37
+  'http://test.foo:80/' => 'http://test.foo/',
38
+  'user@test.foo' => 'http://test.foo/',
39
+  'test.foo/path#frag' => 'http://test.foo/path',
40
+  'test.foo:81' => 'http://test.foo:81/',
41
+  'user:pass@test.foo.:80/?foo#bar' => 'http://test.foo/',
42
+  'protocol://foo/' => 'protocol://foo/',
43
+  'protocol://foo.:80/' => 'protocol://foo:80/',
44
+  'https://test.foo/' => 'https://test.foo/',
45
+  'https://:@test.foo.:443?#' => 'https://test.foo/',
46
+  'https://test.foo:80' => 'https://test.foo:80/',
47
+  'http://host/path/to/file' => 'http://host/path/to/file',
48
+  'foo/././bar' => 'http://foo/bar',
49
+  'foo/bar/../baz' => 'http://foo/baz',
50
+  'foo/bar/./../baz' => 'http://foo/baz',
51
+  'http://test.foo/abc/../def/.././' => 'http://test.foo/',
52
+ );
53
+
54
+ array_walk($tests, 'doNormTest');
55
+
56
+?>

Loading…
Cancel
Save