* Test cases for some includes/ stuff
authorÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 31 Dec 2006 09:18:54 +0000 (09:18 +0000)
committerÆvar Arnfjörð Bjarmason <avar@users.mediawiki.org>
Sun, 31 Dec 2006 09:18:54 +0000 (09:18 +0000)
t/00-test.t [new file with mode: 0644]
t/README [new file with mode: 0644]
t/inc/IP.t [new file with mode: 0644]
t/inc/Licenses.t [new file with mode: 0644]
t/inc/Sanitizer.t [new file with mode: 0644]
t/inc/Xml.t [new file with mode: 0644]

diff --git a/t/00-test.t b/t/00-test.t
new file mode 100644 (file)
index 0000000..c3defa4
--- /dev/null
@@ -0,0 +1,8 @@
+#!/usr/bin/env php
+<?php
+require 'Test.php';
+
+plan(1);
+
+ok(0 == 0);
+?>
diff --git a/t/README b/t/README
new file mode 100644 (file)
index 0000000..3141f2c
--- /dev/null
+++ b/t/README
@@ -0,0 +1,10 @@
+=head1 NAME
+
+F<t> - MediaWiki test tree
+
+=head1 DESCRIPTION
+
+This is the MediaWiki test tree (well, one of them), tests here
+produce TAP output, see L<TAP>.
+
+=cut
diff --git a/t/inc/IP.t b/t/inc/IP.t
new file mode 100644 (file)
index 0000000..85fe8cb
--- /dev/null
@@ -0,0 +1,60 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+plan( 'no_plan' );
+
+require_ok( 'includes/IP.php' );
+
+# some of this test data was taken from Data::Validate::IP
+
+#
+# isValid()
+#
+
+foreach ( range( 0, 255 ) as $i ) {
+       $a = sprintf( "%03d", $i );
+       $b = sprintf( "%02d", $i );
+       $c = sprintf( "%01d", $i );
+       foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
+               $ip = "$f.$f.$f.$f";
+               ok( IP::isValid( $ip ), "$ip is a valid IPv4 address" );
+       }
+}
+
+$valid = array( '216.17.184.1', '0.0.0.0', '000.000.000.000' );
+
+foreach ( $valid as $v ) {
+       ok( IP::isValid( $v ), "$v is a valid IPv4 address" );
+}
+
+$invalid = array(
+       'www.xn--var-xla.net',
+       '216.17.184.G',
+       '216.17.184.1.',
+       '216.17.184',
+       '216.17.184.',
+       '256.17.184.1'
+);
+
+foreach ( $invalid as $i ) {
+       ok( ! IP::isValid( $i ), "$i is an invalid IPv4 address" );
+}
+
+#
+# isPublic()
+#
+
+$private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
+
+foreach ( $private as $p ) {
+       ok( ! IP::isPublic( $p ), "$p is not a public IP address" ); 
+}
+
+#is   ('127.0.0.1',    is_loopback_ipv4('127.0.0.1'),          'is_loopback_ipv4 127.0.0.1');
+#is   ('192.0.2.9',    is_testnet_ipv4('192.0.2.9'),           'is_testnet_ipv4 192.0.2.9');
+#is   ('216.17.184.1', is_public_ipv4('216.17.184.1'),         'is_public_ipv4 216.17.184.1');
+#isnt ('192.168.0.1',  is_public_ipv4('192.168.0.1'),          'is_public_ipv4 192.168.0.1');
+#
+?>
\ No newline at end of file
diff --git a/t/inc/Licenses.t b/t/inc/Licenses.t
new file mode 100644 (file)
index 0000000..86202bd
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/env php
+<?php
+require 'Test.php';
+
+plan(3);
+
+error_reporting( E_ALL );
+
+define( 'MEDIAWIKI', 1 ); // Hack
+
+require_ok( 'languages/Language.php' );
+require_ok( 'includes/GlobalFunctions.php' );
+require_ok( 'includes/Licenses.php' );
+
+$str = "
+* Free licenses:
+** GFLD|Debian disagrees
+";
+
+#$lc = new Licenses ( $str );
+
+#isa_ok( $lc, 'Licenses' );
+
+#echo $lc->html;
+
+
+
+
+?>
\ No newline at end of file
diff --git a/t/inc/Sanitizer.t b/t/inc/Sanitizer.t
new file mode 100644 (file)
index 0000000..812cebc
--- /dev/null
@@ -0,0 +1,55 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+plan( 11 );
+
+require_ok( 'includes/Defines.php' );
+require_ok( 'includes/GlobalFunctions.php' );
+require_ok( 'includes/Sanitizer.php' );
+require_ok( 'includes/normal/UtfNormal.php' );
+
+
+#
+# decodeCharReferences
+#
+
+cmp_ok(
+       Sanitizer::decodeCharReferences( '&eacute;cole' ),
+       '==',
+       "\xc3\xa9cole",
+       'decode named entities'
+);
+
+cmp_ok(
+       Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&#233;cole!" ),
+       '==',
+       "\xc4\x88io bonas dans l'\xc3\xa9cole!",
+       'decode numeric entities'
+);
+
+cmp_ok(
+       Sanitizer::decodeCharReferences( "&#x108;io bonas dans l'&eacute;cole!" ),
+       '==',
+       "\xc4\x88io bonas dans l'\xc3\xa9cole!",
+       'decode mixed numeric/named entities'
+);
+
+cmp_ok(
+       Sanitizer::decodeCharReferences(
+               "&#x108;io bonas dans l'&eacute;cole! (mais pas &amp;#x108;io dans l'&#38;eacute;cole)"
+       ),
+       '==',
+       "\xc4\x88io bonas dans l'\xc3\xa9cole! (mais pas &#x108;io dans l'&eacute;cole)",
+       'decode mixed complex entities'
+);
+
+cmp_ok( Sanitizer::decodeCharReferences( 'a & b' ), '==', 'a & b', 'Invalid ampersand' );
+
+cmp_ok( Sanitizer::decodeCharReferences( '&foo;' ), '==', '&foo;', 'Invalid named entity' );
+
+cmp_ok( Sanitizer::decodeCharReferences( "&#88888888888888;" ), '==', UTF8_REPLACEMENT, 'Invalid numbered entity' );
+
+
+
diff --git a/t/inc/Xml.t b/t/inc/Xml.t
new file mode 100644 (file)
index 0000000..bf95cce
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+plan( 8 );
+
+require_ok( 'includes/Sanitizer.php' );
+require_ok( 'includes/Xml.php' );
+
+#
+# element
+#
+
+cmp_ok(
+       Xml::element( 'element', null, null ),
+       '==',
+       '<element>',
+       'Opening element with no attributes'
+);
+
+cmp_ok(
+       Xml::element( 'element', null, '' ),
+       '==',
+       '<element />',
+       'Terminated empty element'
+);
+
+cmp_ok(
+       Xml::element( 'element', null, 'hello <there> you & you' ),
+       '==',
+       '<element>hello &lt;there&gt; you &amp; you</element>',
+       'Element with no attributes and content that needs escaping'
+);
+
+cmp_ok(
+       Xml::element( 'element', array( 'key' => 'value', '<>' => '<>' ), null ),
+       '==',
+       '<element key="value" <>="&lt;&gt;">',
+       'Element attributes, keys are not escaped'
+);
+
+#
+# open/close element
+#
+
+cmp_ok(
+       Xml::openElement( 'element', array( 'k' => 'v' ) ),
+       '==',
+       '<element k="v">',
+       'openElement() shortcut'
+);
+
+cmp_ok( Xml::closeElement( 'element' ), '==', '</element>', 'closeElement() shortcut' );
+
+?>
\ No newline at end of file