r61931 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61930‎ | r61931 | r61932 >
Date:14:58, 3 February 2010
Author:demon
Status:ok
Tags:
Comment:
Starting to phase out /t in favor of /tests, so removing things already covered by the latter (or otherwise unneeded). People prefer PHPUnit, according to cabal-like IRC polling and previous discussions elsewhere
Modified paths:
  • /trunk/phase3/t/00-test.t (deleted) (history)
  • /trunk/phase3/t/inc/Database.t (deleted) (history)
  • /trunk/phase3/t/inc/Global.t (deleted) (history)
  • /trunk/phase3/t/inc/IP.t (deleted) (history)
  • /trunk/phase3/t/inc/ImageFunctions.t (deleted) (history)
  • /trunk/phase3/t/inc/LocalFile.t (deleted) (history)
  • /trunk/phase3/t/inc/Parser.t (deleted) (history)

Diff [purge]

Index: trunk/phase3/t/00-test.t
@@ -1,10 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -require 'Test.php';
5 -
6 -plan(1);
7 -
8 -ok(0 == 0);
9 -
10 -/* vim: set filetype=php: */
11 -?>
Index: trunk/phase3/t/inc/Global.t
@@ -1,154 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -define( 'MEDIAWIKI', true );
6 -require 't/Test.php';
7 -
8 -require 'LocalSettings.php';
9 -require 'includes/Defines.php';
10 -require 'includes/ProfilerStub.php';
11 -require 'includes/AutoLoader.php';
12 -require 'includes/Setup.php';
13 -
14 -plan( 46 );
15 -
16 -$wgReadOnly = null;
17 -$wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
18 -unlink( $wgReadOnlyFile );
19 -
20 -isnt( wfRandom(), wfRandom(), "Two differents random" );
21 -
22 -is( wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ),
23 - "%E7%89%B9%E5%88%A5:Contributions/Foobar", 'Urlencode' );
24 -
25 -is( wfReadOnly(), false, 'Empty read only' );
26 -
27 -is( wfReadOnly(), false, 'Empty read only, second time' );
28 -
29 -$f = fopen( $wgReadOnlyFile, "wt" );
30 -fwrite( $f, 'Message' );
31 -fclose( $f );
32 -$wgReadOnly = null;
33 -
34 -is( wfReadOnly(), true, 'Read only file set' );
35 -
36 -is( wfReadOnly(), true, 'Read only file set, second time' );
37 -
38 -unlink( $wgReadOnlyFile );
39 -$wgReadOnly = null;
40 -
41 -is( wfReadOnly(), false, 'Read only reset' );
42 -
43 -is( wfReadOnly(), false, 'Read only reset, second time' );
44 -
45 -
46 -is( wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ),
47 - "=?UTF-8?Q?=C4=88u=20legebla=3F?=", 'Quoted printable' );
48 -
49 -$start = wfTime();
50 -is( gettype( $start ), 'double', 'Time (type)' );
51 -$end = wfTime();
52 -cmp_ok( $end, '>', $start, 'Time (compare)' );
53 -
54 -$arr = wfArrayToCGI(
55 - array( 'baz' => 'AT&T', 'ignore' => '' ),
56 - array( 'foo' => 'bar', 'baz' => 'overridden value' ) );
57 -is( $arr, "baz=AT%26T&foo=bar", 'Array to CGI' );
58 -
59 -$mime = mimeTypeMatch( 'text/html', array(
60 - 'application/xhtml+xml' => 1.0,
61 - 'text/html' => 0.7,
62 - 'text/plain' => 0.3
63 -) );
64 -is( $mime, 'text/html', 'Mime (1)' );
65 -
66 -$mime = mimeTypeMatch( 'text/html', array(
67 - 'image/*' => 1.0,
68 - 'text/*' => 0.5
69 -) );
70 -is( $mime, 'text/*', 'Mime (2)' );
71 -
72 -$mime = mimeTypeMatch( 'text/html', array( '*/*' => 1.0 ) );
73 -is( $mime, '*/*', 'Mime (3)' );
74 -
75 -$mime = mimeTypeMatch( 'text/html', array(
76 - 'image/png' => 1.0,
77 - 'image/svg+xml' => 0.5
78 -) );
79 -is( $mime, null, 'Mime (4)' );
80 -
81 -$mime = wfNegotiateType(
82 - array( 'application/xhtml+xml' => 1.0,
83 - 'text/html' => 0.7,
84 - 'text/plain' => 0.5,
85 - 'text/*' => 0.2 ),
86 - array( 'text/html' => 1.0 ) );
87 -is( $mime, 'text/html', 'Negotiate Mime (1)' );
88 -
89 -$mime = wfNegotiateType(
90 - array( 'application/xhtml+xml' => 1.0,
91 - 'text/html' => 0.7,
92 - 'text/plain' => 0.5,
93 - 'text/*' => 0.2 ),
94 - array( 'application/xhtml+xml' => 1.0,
95 - 'text/html' => 0.5 ) );
96 -is( $mime, 'application/xhtml+xml', 'Negotiate Mime (2)' );
97 -
98 -$mime = wfNegotiateType(
99 - array( 'text/html' => 1.0,
100 - 'text/plain' => 0.5,
101 - 'text/*' => 0.5,
102 - 'application/xhtml+xml' => 0.2 ),
103 - array( 'application/xhtml+xml' => 1.0,
104 - 'text/html' => 0.5 ) );
105 -is( $mime, 'text/html', 'Negotiate Mime (3)' );
106 -
107 -$mime = wfNegotiateType(
108 - array( 'text/*' => 1.0,
109 - 'image/*' => 0.7,
110 - '*/*' => 0.3 ),
111 - array( 'application/xhtml+xml' => 1.0,
112 - 'text/html' => 0.5 ) );
113 -is( $mime, 'text/html', 'Negotiate Mime (4)' );
114 -
115 -$mime = wfNegotiateType(
116 - array( 'text/*' => 1.0 ),
117 - array( 'application/xhtml+xml' => 1.0 ) );
118 -is( $mime, null, 'Negotiate Mime (5)' );
119 -
120 -$t = gmmktime( 12, 34, 56, 1, 15, 2001 );
121 -is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_UNIX to TS_MW' );
122 -is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_UNIX to TS_UNIX' );
123 -is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_UNIX to TS_DB' );
124 -$t = '20010115123456';
125 -is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_MW to TS_MW' );
126 -is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_MW to TS_UNIX' );
127 -is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_MW to TS_DB' );
128 -$t = '2001-01-15 12:34:56';
129 -is( wfTimestamp( TS_MW, $t ), '20010115123456', 'TS_DB to TS_MW' );
130 -is( wfTimestamp( TS_UNIX, $t ), 979562096, 'TS_DB to TS_UNIX' );
131 -is( wfTimestamp( TS_DB, $t ), '2001-01-15 12:34:56', 'TS_DB to TS_DB' );
132 -
133 -$sets = array(
134 - '' => '',
135 - '/' => '',
136 - '\\' => '',
137 - '//' => '',
138 - '\\\\' => '',
139 - 'a' => 'a',
140 - 'aaaa' => 'aaaa',
141 - '/a' => 'a',
142 - '\\a' => 'a',
143 - '/aaaa' => 'aaaa',
144 - '\\aaaa' => 'aaaa',
145 - '/aaaa/' => 'aaaa',
146 - '\\aaaa\\' => 'aaaa',
147 - '\\aaaa\\' => 'aaaa',
148 - '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
149 - 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
150 - 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
151 -);
152 -foreach( $sets as $from => $to ) {
153 - is( $to, wfBaseName( $from ),
154 - "wfBaseName('$from') => '$to'");
155 -}
\ No newline at end of file
Index: trunk/phase3/t/inc/Database.t
@@ -1,53 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -define( 'MEDIAWIKI', true );
6 -require 't/Test.php';
7 -
8 -require 'includes/Defines.php';
9 -require 'LocalSettings.php';
10 -require 'includes/ProfilerStub.php';
11 -require 'includes/AutoLoader.php';
12 -require 'includes/Setup.php';
13 -
14 -plan( 9 );
15 -
16 -$db = new DatabaseMysql( $wgDBserver, $wgDBuser, $wgDBpassword );
17 -
18 -cmp_ok( $db->addQuotes( null ), '==',
19 - 'NULL', 'Add quotes to NULL' );
20 -
21 -cmp_ok( $db->addQuotes( 1234 ), '==',
22 - "'1234'", 'Add quotes to int' );
23 -
24 -cmp_ok( $db->addQuotes( 1234.5678 ), '==',
25 - "'1234.5678'", 'Add quotes to float' );
26 -
27 -cmp_ok( $db->addQuotes( 'string' ), '==',
28 - "'string'", 'Add quotes to string' );
29 -
30 -cmp_ok( $db->addQuotes( "string's cause trouble" ), '==',
31 - "'string\'s cause trouble'", 'Add quotes to quoted string' );
32 -
33 -$sql = $db->fillPrepared(
34 - 'SELECT * FROM interwiki', array() );
35 -cmp_ok( $sql, '==',
36 - 'SELECT * FROM interwiki', 'FillPrepared empty' );
37 -
38 -$sql = $db->fillPrepared(
39 - 'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
40 - array( 4, "Snicker's_paradox" ) );
41 -cmp_ok( $sql, '==',
42 - "SELECT * FROM cur WHERE cur_namespace='4' AND cur_title='Snicker\'s_paradox'", 'FillPrepared question' );
43 -
44 -$sql = $db->fillPrepared(
45 - 'SELECT user_id FROM ! WHERE user_name=?',
46 - array( '"user"', "Slash's Dot" ) );
47 -cmp_ok( $sql, '==',
48 - "SELECT user_id FROM \"user\" WHERE user_name='Slash\'s Dot'", 'FillPrepared quoted' );
49 -
50 -$sql = $db->fillPrepared(
51 - "SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
52 - array( '"user"', "Slash's Dot" ) );
53 -cmp_ok( $sql, '==',
54 - "SELECT * FROM cur WHERE cur_title='This_&_that,_WTF?!'", 'FillPrepared raw' );
Index: trunk/phase3/t/inc/IP.t
@@ -1,60 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -require 't/Test.php';
6 -
7 -plan( 1120 );
8 -
9 -require_ok( 'includes/IP.php' );
10 -
11 -# some of this test data was taken from Data::Validate::IP
12 -
13 -#
14 -# isValid()
15 -#
16 -
17 -foreach ( range( 0, 255 ) as $i ) {
18 - $a = sprintf( "%03d", $i );
19 - $b = sprintf( "%02d", $i );
20 - $c = sprintf( "%01d", $i );
21 - foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
22 - $ip = "$f.$f.$f.$f";
23 - ok( IP::isValid( $ip ), "$ip is a valid IPv4 address" );
24 - }
25 -}
26 -
27 -# A bit excessive perhaps? meh..
28 -foreach ( range( 256, 999 ) as $i ) {
29 - $a = sprintf( "%03d", $i );
30 - $b = sprintf( "%02d", $i );
31 - $c = sprintf( "%01d", $i );
32 - foreach ( array_unique( array( $a, $b, $c ) ) as $f ) {
33 - $ip = "$f.$f.$f.$f";
34 - ok( ! IP::isValid( $ip ), "$ip is not a valid IPv4 address" );
35 - }
36 -}
37 -
38 -$invalid = array(
39 - 'www.xn--var-xla.net',
40 - '216.17.184.G',
41 - '216.17.184.1.',
42 - '216.17.184',
43 - '216.17.184.',
44 - '256.17.184.1'
45 -);
46 -
47 -foreach ( $invalid as $i ) {
48 - ok( ! IP::isValid( $i ), "$i is an invalid IPv4 address" );
49 -}
50 -
51 -#
52 -# isPublic()
53 -#
54 -
55 -$private = array( '10.0.0.1', '172.16.0.1', '192.168.0.1' );
56 -
57 -foreach ( $private as $p ) {
58 - ok( ! IP::isPublic( $p ), "$p is not a public IP address" );
59 -}
60 -
61 -/* vim: set filetype=php: */
Index: trunk/phase3/t/inc/LocalFile.t
@@ -1,77 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -define( 'MEDIAWIKI', true );
6 -require 't/Test.php';
7 -
8 -require 'includes/Defines.php';
9 -require 'includes/ProfilerStub.php';
10 -require 'LocalSettings.php';
11 -require 'includes/Setup.php';
12 -
13 -/**
14 - * These tests should work regardless of $wgCapitalLinks
15 - */
16 -
17 -$info = array(
18 - 'name' => 'test',
19 - 'directory' => '/testdir',
20 - 'url' => '/testurl',
21 - 'hashLevels' => 2,
22 - 'transformVia404' => false,
23 -);
24 -
25 -plan( 35 );
26 -
27 -$repo_hl0 = new LocalRepo( array( 'hashLevels' => 0 ) + $info );
28 -$repo_hl2 = new LocalRepo( array( 'hashLevels' => 2 ) + $info );
29 -$repo_lc = new LocalRepo( array( 'initialCapital' => false ) + $info );
30 -
31 -$file_hl0 = $repo_hl0->newFile( 'test!' );
32 -$file_hl2 = $repo_hl2->newFile( 'test!' );
33 -$file_lc = $repo_lc->newFile( 'test!' );
34 -
35 -is( $file_hl0->getHashPath(), '', 'Get hash path, hasLev 0' );
36 -is( $file_hl2->getHashPath(), 'a/a2/', 'Get hash path, hasLev 2' );
37 -is( $file_lc->getHashPath(), 'c/c4/', 'Get hash path, lc first' );
38 -
39 -is( $file_hl0->getRel(), 'Test!', 'Get rel path, hasLev 0' );
40 -is( $file_hl2->getRel(), 'a/a2/Test!', 'Get rel path, hasLev 2' );
41 -is( $file_lc->getRel(), 'c/c4/test!', 'Get rel path, lc first' );
42 -
43 -is( $file_hl0->getUrlRel(), 'Test%21', 'Get rel url, hasLev 0' );
44 -is( $file_hl2->getUrlRel(), 'a/a2/Test%21', 'Get rel url, hasLev 2' );
45 -is( $file_lc->getUrlRel(), 'c/c4/test%21', 'Get rel url, lc first' );
46 -
47 -is( $file_hl0->getArchivePath(), '/testdir/archive', 'Get archive path, hasLev 0' );
48 -is( $file_hl2->getArchivePath(), '/testdir/archive/a/a2', 'Get archive path, hasLev 2' );
49 -is( $file_hl0->getArchivePath( '!' ), '/testdir/archive/!', 'Get archive path, hasLev 0' );
50 -is( $file_hl2->getArchivePath( '!' ), '/testdir/archive/a/a2/!', 'Get archive path, hasLev 2' );
51 -
52 -is( $file_hl0->getThumbPath(), '/testdir/thumb/Test!', 'Get thumb path, hasLev 0' );
53 -is( $file_hl2->getThumbPath(), '/testdir/thumb/a/a2/Test!', 'Get thumb path, hasLev 2' );
54 -is( $file_hl0->getThumbPath( 'x' ), '/testdir/thumb/Test!/x', 'Get thumb path, hasLev 0' );
55 -is( $file_hl2->getThumbPath( 'x' ), '/testdir/thumb/a/a2/Test!/x', 'Get thumb path, hasLev 2' );
56 -
57 -is( $file_hl0->getArchiveUrl(), '/testurl/archive', 'Get archive url, hasLev 0' );
58 -is( $file_hl2->getArchiveUrl(), '/testurl/archive/a/a2', 'Get archive url, hasLev 2' );
59 -is( $file_hl0->getArchiveUrl( '!' ), '/testurl/archive/%21', 'Get archive url, hasLev 0' );
60 -is( $file_hl2->getArchiveUrl( '!' ), '/testurl/archive/a/a2/%21', 'Get archive url, hasLev 2' );
61 -
62 -is( $file_hl0->getThumbUrl(), '/testurl/thumb/Test%21', 'Get thumb url, hasLev 0' );
63 -is( $file_hl2->getThumbUrl(), '/testurl/thumb/a/a2/Test%21', 'Get thumb url, hasLev 2' );
64 -is( $file_hl0->getThumbUrl( 'x' ), '/testurl/thumb/Test%21/x', 'Get thumb url, hasLev 0' );
65 -is( $file_hl2->getThumbUrl( 'x' ), '/testurl/thumb/a/a2/Test%21/x', 'Get thumb url, hasLev 2' );
66 -
67 -is( $file_hl0->getArchiveVirtualUrl(), 'mwrepo://test/public/archive', 'Get archive virtual url, hasLev 0' );
68 -is( $file_hl2->getArchiveVirtualUrl(), 'mwrepo://test/public/archive/a/a2', 'Get archive virtual url, hasLev 2' );
69 -is( $file_hl0->getArchiveVirtualUrl( '!' ), 'mwrepo://test/public/archive/%21', 'Get archive virtual url, hasLev 0' );
70 -is( $file_hl2->getArchiveVirtualUrl( '!' ), 'mwrepo://test/public/archive/a/a2/%21', 'Get archive virtual url, hasLev 2' );
71 -
72 -is( $file_hl0->getThumbVirtualUrl(), 'mwrepo://test/thumb/Test%21', 'Get thumb virtual url, hasLev 0' );
73 -is( $file_hl2->getThumbVirtualUrl(), 'mwrepo://test/thumb/a/a2/Test%21', 'Get thumb virtual url, hasLev 2' );
74 -is( $file_hl0->getThumbVirtualUrl( '!' ), 'mwrepo://test/thumb/Test%21/%21', 'Get thumb virtual url, hasLev 0' );
75 -is( $file_hl2->getThumbVirtualUrl( '!' ), 'mwrepo://test/thumb/a/a2/Test%21/%21', 'Get thumb virtual url, hasLev 2' );
76 -
77 -is( $file_hl0->getUrl(), '/testurl/Test%21', 'Get url, hasLev 0' );
78 -is( $file_hl2->getUrl(), '/testurl/a/a2/Test%21', 'Get url, hasLev 2' );
Index: trunk/phase3/t/inc/ImageFunctions.t
@@ -1,56 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -define( 'MEDIAWIKI', true );
6 -require 't/Test.php';
7 -
8 -require 'includes/Defines.php';
9 -
10 -$vals = array(
11 - array(
12 - 'width' => 50,
13 - 'height' => 50,
14 - 'tests' => array(
15 - 50 => 50,
16 - 17 => 17,
17 - 18 => 18 ) ),
18 - array(
19 - 'width' => 366,
20 - 'height' => 300,
21 - 'tests' => array(
22 - 50 => 61,
23 - 17 => 21,
24 - 18 => 22 ) ),
25 - array(
26 - 'width' => 300,
27 - 'height' => 366,
28 - 'tests' => array(
29 - 50 => 41,
30 - 17 => 14,
31 - 18 => 15 ) ),
32 - array(
33 - 'width' => 100,
34 - 'height' => 400,
35 - 'tests' => array(
36 - 50 => 12,
37 - 17 => 4,
38 - 18 => 4 ) )
39 -);
40 -
41 -plan( 3 + 3 * count( $vals ) );
42 -
43 -require_ok( 'includes/ProfilerStub.php' );
44 -require_ok( 'includes/GlobalFunctions.php' );
45 -require_ok( 'includes/ImageFunctions.php' );
46 -
47 -foreach( $vals as $row ) {
48 - extract( $row );
49 - foreach( $tests as $max => $expected ) {
50 - $y = round( $expected * $height / $width );
51 - $result = wfFitBoxWidth( $width, $height, $max );
52 - $y2 = round( $result * $height / $width );
53 - is( $result, $expected,
54 - "($width, $height, $max) wanted: {$expected}x{$y}, got: {$result}x{$y2}" );
55 - }
56 -}
57 -
Index: trunk/phase3/t/inc/Parser.t
@@ -1,39 +0,0 @@
2 -#!/usr/bin/env php
3 -<?php
4 -
5 -require 't/Test.php';
6 -require 'maintenance/parserTests.inc';
7 -
8 -error_reporting( E_ALL ^ E_NOTICE );
9 -
10 -class ProveTestRecorder extends TestRecorder {
11 -
12 - function record( $name, $res ){}
13 - function report(){}
14 - function reportPercentage( $success, $total ){}
15 -}
16 -
17 -class ProveParserTest extends ParserTest {
18 -
19 - function showSuccess( $desc ){
20 - pass( $desc );
21 - }
22 -
23 - function showFailure( $desc, $exp, $got ){
24 - _proclaim( false, $desc, false, $got, $exp );
25 - }
26 -
27 - function showRunFile( $path ){}
28 -}
29 -
30 -$options = array( 'quick', 'quiet', 'compare' );
31 -$tester = new ProveParserTest();
32 -$tester->showProgress = false;
33 -$tester->showFailure = false;
34 -$tester->recorder = new ProveTestRecorder( $tester->term );
35 -
36 -// Do not output the number of tests, if will be done automatically at the end
37 -
38 -$tester->runTestsFromFiles( $wgParserTestFiles );
39 -
40 -/* vim: set filetype=php: */

Status & tagging log