summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/exec.t2
-rwxr-xr-xtests/it.t13
-rwxr-xr-xtests/it_dbi.t8
-rwxr-xr-xtests/it_html.t24
-rwxr-xr-xtests/it_mail.t55
-rwxr-xr-xtests/it_pipe.t19
-rwxr-xr-xtests/it_url.t8
-rwxr-xr-xtests/it_xml.t2
-rwxr-xr-xtests/itjs.t2
9 files changed, 87 insertions, 46 deletions
diff --git a/tests/exec.t b/tests/exec.t
index da5113d..c155c88 100755
--- a/tests/exec.t
+++ b/tests/exec.t
@@ -84,7 +84,7 @@ it::system('touch /tmp/it_system_test');
ok(file_exists('/tmp/it_system_test'), 'shell command gets executed');
@unlink('/tmp/it_system_test');
-it::system('touch {path}', 'path' => '/tmp/it_system_test');
+it::system('touch {path}', array('path' => '/tmp/it_system_test'));
ok(file_exists('/tmp/it_system_test'), 'shell command with argument');
@unlink('/tmp/it_system_test');
diff --git a/tests/it.t b/tests/it.t
index 33a6c13..4fd848b 100755
--- a/tests/it.t
+++ b/tests/it.t
@@ -315,6 +315,19 @@ is(it::grep('match', array('foo' => 'match', 'bar' => 'gna')), array('foo' => 'm
setlocale(LC_CTYPE, $oldlocale);
ini_set('default_charset', $oldcharset); # end of tests that must run with specific charset
+# it::cidr_match tests
+is(it::cidr_match('192.168.2.3', '192.168.2.5'), false, "cidr_match full IP no match no mask");
+is(it::cidr_match('192.168.2.3', '192.168.2.3'), true, "cidr_match full IP match no mask");
+is(it::cidr_match('192.168.2.3', '192.168.2.5/32'), false, "cidr_match full IP no match");
+is(it::cidr_match('192.168.2.5', '192.168.2.5/32'), true, "cidr_match full IP match");
+is(it::cidr_match('192.168.1.1', '192.168.42.0/24'), false, "cidr_match no match");
+is(it::cidr_match('192.168.42.1', '192.168.42.0/24'), true, "cidr_match basic match");
+is(it::cidr_match('192.168.42.42', '192.168.0.0/16'), true, "cidr_match class b");
+is(it::cidr_match('192.168.42.42', '192.168.42.64/26'), false, "cidr_match offset no match");
+is(it::cidr_match('192.168.42.42', '192.168.42.32/27'), true, "cidr_match offset");
+is(it::cidr_match('2001:918:ff83:101:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), true, "cidr_match ipv6");
+is(it::cidr_match('2001:918:ff83:102:798e:77c0:b722:fe56', '2001:918:ff83:101::/64'), false, "cidr_match ipv6 no match" );
+is(it::cidr_match('10.11.12.13', array('10.0.0.0/8', '192.168.0.0./16')), true, "cidr_match array");
# it::filter_keys tests
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
index c9e7d9d..ca39f1f 100755
--- a/tests/it_dbi.t
+++ b/tests/it_dbi.t
@@ -140,13 +140,13 @@ is(
is(
$record->update(array('x' => 18), array('x' => 17)),
1,
- "return affected rows",
+ "return affected rows"
);
is(
$record->update(array('x' => 18), array('x' => 17)),
0,
- "return zero affected rows",
+ "return zero affected rows"
);
$record->update(array('-x' => 'POW(2,2) * 10'));
@@ -166,14 +166,14 @@ is (
$record->update(array('foo' => NULL));
is (
- $record->_set('foo' => ""),
+ $record->_set(array('foo' => "")),
"SET `foo`=''",
'update: _set optimization with NULL => ""'
);
$record->update(array('foo' => "bar"));
$record->update(array('foo' => ""));
is (
- $record->_set('foo' => NULL),
+ $record->_set(array('foo' => NULL)),
"SET `foo`=NULL",
'update: _set optimization with "" => NULL'
);
diff --git a/tests/it_html.t b/tests/it_html.t
index 4c06d9d..4f4da24 100755
--- a/tests/it_html.t
+++ b/tests/it_html.t
@@ -52,40 +52,40 @@ is(
);
is(
- div('arg' => "val: \x03, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \x09, \n", "\x02, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \x09, \n"),
+ div(array('arg' => "val: \x03, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \x09, \n", "\x02, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \x09, \n")),
"<div arg=\"val: , , , , , , \x09, &#10;\">\x02, \x0e, \x0f, \x0c, \xc2\x80, \xc2\x9f, \x09, \n</div>\n",
"blank unprintable characters and illegal utf8 in attributes but not in normal text"
);
is(
- div("arg\x03\x0e\x0f\xc2\x80\xc2\x9fendarg" => "value", "content"),
+ div(array("arg\x03\x0e\x0f\xc2\x80\xc2\x9fendarg" => "value", "content")),
"<div arg\x03\x0e\x0f\xc2\x80\xc2\x9fendarg=\"value\">content</div>\n",
"don't blank unprintable characters and illegal utf8 in attribute names"
);
is(
- div('arg' => "abc äüö éá© œàè îôÇ xyz", "abc äüö éá© œàè îôÇ xyz"),
+ div(array('arg' => "abc äüö éá© œàè îôÇ xyz", "abc äüö éá© œàè îôÇ xyz")),
"<div arg=\"abc äüö éá© œàè îôÇ xyz\">abc äüö éá© œàè îôÇ xyz</div>\n",
- "leave legal utf8 intact",
+ "leave legal utf8 intact"
);
unset($GLOBALS['debug_utf8check']);
is(
- div('arg' => "value \xc2", "content"),
+ div(array('arg' => "value \xc2", "content")),
"<div arg=\"value \xc2\">content</div>\n",
- "handle single \\xc2 at end of attribute value",
+ "handle single \\xc2 at end of attribute value"
);
is(
- div("arg\x00end" => "value \x00 end", "content \x00 content end"),
+ div(array("arg\x00end" => "value \x00 end", "content \x00 content end")),
"<div arg\x00end=\"value end\">content \x00 content end</div>\n",
- "handle 0-bytes",
+ "handle 0-bytes"
);
is(
- div('arg' => "& \" < > \n '", "& \" < > \n '"),
+ div(array('arg' => "& \" < > \n '", "& \" < > \n '")),
"<div arg=\"&amp; &quot; &lt; &gt; &#10; '\">& \" < > \n '</div>\n",
- "use html entities in attributes but not in normal text",
+ "use html entities in attributes but not in normal text"
);
# Test different html types
@@ -93,7 +93,7 @@ foreach (array('html5' => "<br flag>", 'html' => "<br flag>", 'xhtml' => "<br fl
{
unset($GLOBALS['it_html']);
new it_html(array('htmltype' => $type));
- is (trim(br('flag' => true)), $value, "Check empty tag and attribute for $type");
+ is (trim(br(array('flag' => true))), $value, "Check empty tag and attribute for $type");
}
# XML generation
@@ -180,7 +180,7 @@ is(
is(
it_html::sanitize('<div></div>'),
'',
- 'empty tags removal',
+ 'empty tags removal'
);
is(
diff --git a/tests/it_mail.t b/tests/it_mail.t
index 1762788..486dee8 100755
--- a/tests/it_mail.t
+++ b/tests/it_mail.t
@@ -9,19 +9,25 @@ $mail = new it_mail();
is(
$mail->addrlist_escape('éxample@example.com', true),
'éxample@example.com',
- "Don't escape plain email addresses in email headers",
+ "Don't escape plain email addresses in email headers"
);
is(
$mail->header_escape('éxample@example.com'),
'=?utf-8?Q?=C3=A9xample@example.com?=',
- "Escape plain email in non-email headers",
+ "Escape plain email in non-email headers"
+);
+
+is(
+ $mail->header_escape('search.ch e-mail code d\'accès'),
+ '=?utf-8?B?c2VhcmNoLmNoIGUtbWFpbCBjb2RlIGQnYWNjw6hz?=',
+ "Use base64 encoding when php iconv fails with quoted-printable (workaround for php bug #53891)"
);
is(
$mail->addrlist_escape('Èxample User <èxample@example.com>', true),
- '=?utf-8?Q?=C3=88xample_User?= <èxample@example.com>',
- "Escape name but not email in email headers",
+ '=?utf-8?Q?=C3=88xample=20User?= <èxample@example.com>',
+ "Escape name but not email in email headers"
);
is(
@@ -32,51 +38,56 @@ is(
is(
$mail->addrlist_escape('example@example.com, éxample@example.com, Sömeone Ëlse <sömeone@example.com>', true),
- 'example@example.com, éxample@example.com,=?utf-8?Q?_S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>',
- "Don't escape email addresses but escape realnames",
+ 'example@example.com, éxample@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>',
+ "Don't escape email addresses but escape realnames"
);
is(
$mail->addrlist_escape('"Alfred E. Neuman" <neuman@example.com>', true),
'"Alfred E. Neuman" <neuman@example.com>',
- "Don't remove quoting characters from realname",
+ "Don't remove quoting characters from realname"
);
+is(
+ $mail->addrlist_escape('"Schmitt, Sören" <schmitt@example.com>', true),
+ '=?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
+ "Don't remove quoting characters from realname when it contains a quotable character"
+);
-$mail = new it_mail(
+$mail = new it_mail(array(
'From' => 'Someone Ïmportant <ïmportant@search.ch>',
- 'To' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Cc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Bcc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Subject' => "§önÐë®z€ı¢ħèṇ",
-);
+ 'To' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
+ 'Cc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
+ 'Bcc' => 'éxample@example.com, example@example.com, Sömeone Ëlse <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, "Schmitt, Sören" <schmitt@example.com>',
+ 'Subject' => "§önÐë®z€ı¢ħèṇ"
+));
is(
$mail->to[0],
- 'éxample@example.com, example@example.com,=?utf-8?Q?_S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Escape To: field as addrlist',
+ 'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
+ 'Escape To: field as addrlist'
);
is(
$mail->cc[0],
- 'éxample@example.com, example@example.com,=?utf-8?Q?_S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Escape Cc: field as addrlist',
+ 'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
+ 'Escape Cc: field as addrlist'
);
is(
$mail->bcc[0],
- 'éxample@example.com, example@example.com,=?utf-8?Q?_S=C3=B6meone_=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>',
- 'Escape Bcc: field as addrlist',
+ 'éxample@example.com, example@example.com, =?utf-8?Q?S=C3=B6meone=20=C3=8Blse?= <sömeone@example.com>, "Alfred E. Neuman" <neuman@example.com>, =?utf-8?Q?"Schmitt,=20S=C3=B6ren"?= <schmitt@example.com>',
+ 'Escape Bcc: field as addrlist'
);
is(
$mail->header_values[0],
- '=?utf-8?Q?Someone_=C3=8Fmportant?= <ïmportant@search.ch>',
- 'Escape From: field as addrlist',
+ '=?utf-8?Q?Someone=20=C3=8Fmportant?= <ïmportant@search.ch>',
+ 'Escape From: field as addrlist'
);
is(
$mail->subject,
"§önÐë®z€ı¢ħèṇ",
- "Don't escape Subject: field on instanziation",
+ "Don't escape Subject: field on instanziation"
);
diff --git a/tests/it_pipe.t b/tests/it_pipe.t
index ce55469..56ee672 100755
--- a/tests/it_pipe.t
+++ b/tests/it_pipe.t
@@ -2,8 +2,17 @@
<?php
# csv()
-is(json_encode((new it_pipe('data' => array("a\tb", "1\t2")))->csv()), '[{"a":"1","b":"2"}]', "it_pipe::csv()");
-is(json_encode((new it_pipe('data' => array("a;b", "1;2")))->csv()), '[{"a":"1","b":"2"}]', "it_pipe::csv()");
-is(json_encode((new it_pipe('data' => array("a,b", "1,2")))->csv()), '[{"a":"1","b":"2"}]', "it_pipe::csv()");
-is(json_encode((new it_pipe('data' => array("a\tb", "1\t2")))->csv("c,d")), '[{"c":"1","d":"2"}]', "it_pipe::csv()");
-is(json_encode((new it_pipe('data' => array("\t", "1\t2")))->csv()), '[{"field0":"1","field1":"2"}]', "it_pipe::csv()");
+$pipe = new it_pipe(array('data' => array("a\tb", "1\t2")));
+is(json_encode($pipe->csv()), '[{"a":"1","b":"2"}]', "it_pipe::csv()");
+
+$pipe = new it_pipe(array('data' => array("a;b", "1;2")));
+is(json_encode($pipe->csv()), '[{"a":"1","b":"2"}]', "it_pipe::csv()");
+
+$pipe = new it_pipe(array('data' => array("a,b", "1,2")));
+is(json_encode($pipe->csv()), '[{"a":"1","b":"2"}]', "it_pipe::csv()");
+
+$pipe = new it_pipe(array('data' => array("a\tb", "1\t2")));
+is(json_encode($pipe->csv("c,d")), '[{"c":"1","d":"2"}]', "it_pipe::csv()");
+
+$pipe = new it_pipe(array('data' => array("\t", "1\t2")));
+is(json_encode($pipe->csv()), '[{"field0":"1","field1":"2"}]', "it_pipe::csv()");
diff --git a/tests/it_url.t b/tests/it_url.t
index 5cb2b29..b6569b1 100755
--- a/tests/it_url.t
+++ b/tests/it_url.t
@@ -63,6 +63,14 @@ is(
'$url->path'
);
+# punycode test
+$url = new it_url('http://www.sörtsch.ch/?q=ültra#sörtsch');
+is(
+ $url->realhostname,
+ 'www.xn--srtsch-wxa.ch',
+ 'punycode $url->realhostname'
+);
+
$_SERVER['HTTP_HOST'] = "gna.ch";
is(
it_url::absolute("/"),
diff --git a/tests/it_xml.t b/tests/it_xml.t
index d74fadf..f53ceeb 100755
--- a/tests/it_xml.t
+++ b/tests/it_xml.t
@@ -72,7 +72,7 @@ match(
match(
'<foo>&amp;amp; &lt;a&gt; &#38;amp; &#60;b&#62; &#x26;amp; &#x3C;c&#x3E; &uuml;</foo>',
'foo Object ( [val] => &amp; <a> &amp; <b> &amp; <c> ü ) ',
- 'Predecode illegal entities while keeping properly encoded ones',
+ 'Predecode illegal entities while keeping properly encoded ones'
);
match(
diff --git a/tests/itjs.t b/tests/itjs.t
index 4fcc9b4..8dff992 100755
--- a/tests/itjs.t
+++ b/tests/itjs.t
@@ -50,5 +50,5 @@ is(
is(
itjs::serialize(array("foo'foo" => "bar")),
"{'foo\'foo':\"bar\"}",
- "quote ' in keys",
+ "quote ' in keys"
);