summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2007-05-16 20:58:53 +0000
committerPierre Schmitz <pierre@archlinux.de>2007-05-16 20:58:53 +0000
commitcecb985bee3bdd252e1b8dc0bd500b37cd52be01 (patch)
tree17266aa237742640aabee7856f0202317a45d540 /t
parent0bac06c301f2a83edb0236e4c2434da16848d549 (diff)
Aktualisierung auf MediaWiki 1.10.0
Plugins angepasst und verbessert kleine Korrekturen am Design
Diffstat (limited to 't')
-rw-r--r--t/00-test.t8
-rw-r--r--t/README54
-rw-r--r--t/inc/IP.t60
-rw-r--r--t/inc/Licenses.t29
-rw-r--r--t/inc/Sanitizer.t62
-rw-r--r--t/inc/Title.t33
-rw-r--r--t/inc/Xml.t56
-rw-r--r--t/maint/eol-style.t35
-rw-r--r--t/maint/php-lint.t33
-rw-r--r--t/maint/php-tag.t29
-rw-r--r--t/maint/unix-newlines.t28
11 files changed, 427 insertions, 0 deletions
diff --git a/t/00-test.t b/t/00-test.t
new file mode 100644
index 00000000..c3defa40
--- /dev/null
+++ b/t/00-test.t
@@ -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
index 00000000..2bf42aba
--- /dev/null
+++ b/t/README
@@ -0,0 +1,54 @@
+=head1 NAME
+
+F<t> - MediaWiki test tree
+
+=head1 DESCRIPTION
+
+This is the MediaWiki test tree (well, one of them), tests in this
+directory are self-contained programs that produce TAP output via the
+F<Test.php> module (/trunk/Test/Test.php) (see
+http://search.cpan.org/~petdance/TAP-1.00/TAP.pm#THE_TAP_FORMAT for
+information on the TAP format).
+
+=head1 Running the tests
+
+You'll need F<Test.php> to run the tests, it lives in the
+F<trunk/Test> directory and can be copied or linked to the F<phase3>
+directory.
+
+ ln -s ../Test/Test.php .
+
+Since the tests are self-contained PHP programs you can run them
+(Xml.t here) as:
+
+ php t/inc/Xml.t
+
+That'll give you the raw TAP output, but what you probably want is to
+use a TAP formatter such as L<prove(1)>:
+
+ prove t/inc/Xml.t # add -v for the verbose version
+
+or to run all the tests:
+
+ prove -r t
+
+=head1 TODO
+
+=over
+
+=item *
+
+Rewrite the rest of the F<tests/> stuff to use L<Test.php> and move it
+here
+
+=item *
+
+Make the parsertests use TAP?
+
+=item *
+
+Write unit tests for the entire codebase:)
+
+=back
+
+=cut
diff --git a/t/inc/IP.t b/t/inc/IP.t
new file mode 100644
index 00000000..eb4978b9
--- /dev/null
+++ b/t/inc/IP.t
@@ -0,0 +1,60 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+plan( 1120 );
+
+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" );
+ }
+}
+
+# A bit excessive perhaps? meh..
+foreach ( range( 256, 999 ) 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 not 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" );
+}
+
+?>
diff --git a/t/inc/Licenses.t b/t/inc/Licenses.t
new file mode 100644
index 00000000..86202bd6
--- /dev/null
+++ b/t/inc/Licenses.t
@@ -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
index 00000000..e3b11b6f
--- /dev/null
+++ b/t/inc/Sanitizer.t
@@ -0,0 +1,62 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+plan( 13 );
+
+define( 'MEDIAWIKI', 1 );
+require_ok( 'includes/Defines.php' );
+require_ok( 'includes/GlobalFunctions.php' );
+require_ok( 'includes/Sanitizer.php' );
+require_ok( 'includes/normal/UtfNormal.php' );
+require_ok( 'includes/ProfilerStub.php' ); # For removeHTMLtags
+
+
+#
+# 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' );
+
+$wgUseTidy = false;
+cmp_ok(
+ Sanitizer::removeHTMLtags( '<div>Hello world</div />' ),
+ '==',
+ '<div>Hello world</div>',
+ 'Self-closing closing div'
+);
diff --git a/t/inc/Title.t b/t/inc/Title.t
new file mode 100644
index 00000000..51157197
--- /dev/null
+++ b/t/inc/Title.t
@@ -0,0 +1,33 @@
+#!/usr/bin/env php
+<?php
+
+require 'Test.php';
+
+plan( 2 + 255 );
+
+require_ok( 'includes/Defines.php' );
+
+# require_ok() doesn't work for these, find out why
+define( 'MEDIAWIKI', 1 );
+require 'LocalSettings.php';
+require 'includes/DefaultSettings.php';
+
+require_ok( 'includes/Title.php' );
+
+#
+# legalChars()
+#
+
+$titlechars = Title::legalChars();
+
+foreach ( range( 1, 255 ) as $num ) {
+ $chr = chr( $num );
+ if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
+ unlike( $chr, "/[$titlechars]/", "chr($num) = $chr is not a valid titlechar" );
+ } else {
+ like( $chr, "/[$titlechars]/", "chr($num) = $chr is a valid titlechar" );
+ }
+}
+
+
+?>
diff --git a/t/inc/Xml.t b/t/inc/Xml.t
new file mode 100644
index 00000000..bf95cce2
--- /dev/null
+++ b/t/inc/Xml.t
@@ -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
diff --git a/t/maint/eol-style.t b/t/maint/eol-style.t
new file mode 100644
index 00000000..d877a264
--- /dev/null
+++ b/t/maint/eol-style.t
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+#
+# Based on php-tag.t
+#
+use strict;
+use warnings;
+
+use Test::More;
+use File::Find;
+use IPC::Open3;
+use File::Spec;
+use Symbol qw(gensym);
+
+my $ext = qr/(?: php | inc | txt | sql | t)/x;
+my @files;
+
+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
+
+plan tests => scalar @files ;
+
+for my $file (@files) {
+ open NULL, '+>', File::Spec->devnull and \*NULL or die;
+ my $pid = open3('<&NULL', \*P, '>&NULL', qw'svn propget svn:eol-style', $file);
+ my $res = do { local $/; <P> . "" };
+ chomp $res;
+ waitpid $pid, 0;
+
+ if ( $? != 0 ) {
+ ok 1 => "svn propget failed, $file probably not under version control";
+ } elsif ( $res eq 'native' ) {
+ ok 1 => "$file svn:eol-style is 'native'";
+ } else {
+ ok 0 => "$file svn:eol-style is '$res', should be 'native'";
+ }
+}
diff --git a/t/maint/php-lint.t b/t/maint/php-lint.t
new file mode 100644
index 00000000..e65d6895
--- /dev/null
+++ b/t/maint/php-lint.t
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+#
+# Based on php-tag.t and eol-style
+#
+use strict;
+use warnings;
+
+use Test::More;
+use File::Find;
+use IPC::Open3;
+use File::Spec;
+use Symbol qw(gensym);
+
+my $ext = qr/(?: php | inc )/x;
+my @files;
+
+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
+
+plan tests => scalar @files ;
+
+for my $file (@files) {
+ open NULL, '+>', File::Spec->devnull and \*NULL or die;
+ my $pid = open3('<&NULL', \*P, '>&NULL', qw'php -l', $file);
+ my $res = do { local $/; <P> . "" };
+ chomp $res;
+ waitpid $pid, 0;
+
+ if ( $? == 0 ) {
+ ok 1 => "Looks fine";
+ } else {
+ ok 0 => "$file does not pass php linter. Error was: $res";
+ }
+}
diff --git a/t/maint/php-tag.t b/t/maint/php-tag.t
new file mode 100644
index 00000000..80b870b7
--- /dev/null
+++ b/t/maint/php-tag.t
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More;;
+
+use File::Find;
+use File::Slurp qw< slurp >;
+
+my $ext = qr/(?: php | inc )/x;
+
+my @files;
+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
+
+plan tests => scalar @files;
+
+for my $file (@files) {
+ my $cont = slurp $file;
+ if ( $cont =~ m<<\?php .* \?>>xs ) {
+ ok 1 => "$file has <?php ?>";
+ } elsif ( $cont =~ m<<\? .* \?>>xs ) {
+ ok 0 => "$file does not use <? ?>";
+ } else {
+ ok 1 => "$file has neither <?php ?> nor <? ?>, check it";
+ }
+}
+
+
+
diff --git a/t/maint/unix-newlines.t b/t/maint/unix-newlines.t
new file mode 100644
index 00000000..91a24ad7
--- /dev/null
+++ b/t/maint/unix-newlines.t
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test::More;;
+
+use File::Find;
+use File::Slurp qw< slurp >;
+use Socket qw< $CRLF $LF >;
+
+my $ext = qr/(?: t | pm | sql | js | php | inc | xml )/x;
+
+my @files;
+find( sub { push @files, $File::Find::name if -f && /\. $ext $/x }, '.' );
+
+plan tests => scalar @files;
+
+for my $file (@files) {
+ my $cont = slurp $file;
+ if ( $cont and $cont =~ $CRLF ) {
+ ok 0 => "$file contains windows newlines";
+ } else {
+ ok 1 => "$file is made of unix newlines and win";
+ }
+}
+
+
+